The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
Loading...
Searching...
No Matches
zip.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
#include <
GaudiKernel/System.h
>
13
#ifndef NDEBUG
14
# include <
GaudiKernel/GaudiException.h
>
15
# include <sstream>
16
#endif
17
#include <utility>
18
19
#if defined( __cpp_lib_ranges_zip ) && defined( __cpp_lib_ranges_as_const )
20
# define GAUDI_FUNCTIONAL_USES_STD_RANGES 1
21
# include <ranges>
22
#else
23
# include <range/v3/view/const.hpp>
24
# include <range/v3/view/zip.hpp>
25
#endif
26
27
namespace
Gaudi::Functional::details
{
28
// CRJ : Stuff for zipping
29
namespace
zip
{
30
32
template
<
typename
OS,
typename
Arg>
33
OS&
printSizes
( OS& out, Arg&& arg ) {
34
out <<
"SizeOf'"
<<
System::typeinfoName
(
typeid
( Arg ) ) <<
"'="
<< arg.size();
35
return
out;
36
}
37
39
template
<
typename
OS,
typename
Arg,
typename
... Args>
40
requires
(
sizeof
...( Args ) > 0 )
41
OS&
printSizes
( OS& out, Arg&& arg, Args&&... args ) {
42
printSizes
( out, arg ) <<
", "
;
43
return
printSizes
( out, args... );
44
}
45
47
template
<
typename
A,
typename
... Rest>
48
bool
check_sizes
(
const
A& first,
const
Rest&... rest )
noexcept
{
49
return
( ( first.size() == rest.size() ) && ... );
50
}
51
52
#ifndef NDEBUG
54
template
<
typename
... Args>
55
inline
decltype
( auto )
verifySizes
( Args&... args ) {
56
if
( !
check_sizes
( args... ) ) {
57
std::ostringstream mess;
58
mess <<
"Zipped containers have different sizes : "
;
59
printSizes
( mess, args... );
60
throw
GaudiException
( mess.str(),
"Gaudi::Functional::details::zip::verifySizes"
,
StatusCode::FAILURE
);
61
}
62
}
63
#endif
64
66
template
<
typename
... Args>
67
inline
decltype
( auto )
range
( Args&&... args ) {
68
#ifndef NDEBUG
69
verifySizes
( args... );
70
#endif
71
#if defined( GAUDI_FUNCTIONAL_USES_STD_RANGES )
72
return
std::ranges::zip_view( std::forward<Args>( args )... );
73
#else
74
return
ranges::views::zip( std::forward<Args>( args )... );
75
#endif
76
}
77
79
template
<
typename
... Args>
80
inline
decltype
( auto )
const_range
( Args&&... args ) {
81
#ifndef NDEBUG
82
verifySizes
( args... );
83
#endif
84
#if defined( GAUDI_FUNCTIONAL_USES_STD_RANGES )
85
return
std::ranges::as_const_view( std::ranges::zip_view( std::forward<Args>( args )... ) );
86
#else
87
return
ranges::views::const_( ranges::views::zip( std::forward<Args>( args )... ) );
88
#endif
89
}
90
}
// namespace zip
91
}
// namespace Gaudi::Functional::details
GaudiException.h
System.h
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::Functional::details::zip
Definition
zip.h:29
Gaudi::Functional::details::zip::printSizes
OS & printSizes(OS &out, Arg &&arg)
Print the parameter.
Definition
zip.h:33
Gaudi::Functional::details::zip::verifySizes
decltype(auto) verifySizes(Args &... args)
Verify the data container sizes have the same sizes.
Definition
zip.h:55
Gaudi::Functional::details::zip::const_range
decltype(auto) const_range(Args &&... args)
Zips multiple containers together to form a single const range.
Definition
zip.h:80
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition
zip.h:67
Gaudi::Functional::details::zip::check_sizes
bool check_sizes(const A &first, const Rest &... rest) noexcept
Compare sizes of 1 or more containers.
Definition
zip.h:48
Gaudi::Functional::details
Definition
Consumer.h:17
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition
System.cpp:254
GaudiFunctional
include
Gaudi
Functional
zip.h
Generated on
for The Gaudi Framework by
1.17.0