ATLAS Offline Software
concepts.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
4  */
39 #ifndef CXXUTILS_CONCEPTS_H
40 #define CXXUTILS_CONCEPTS_H
41 
42 
43 #include <type_traits>
44 #include <iterator>
45 
46 
47 #ifdef __cpp_concepts
48 
49 #define HAVE_CONCEPTS 1
50 
51 #include <concepts>
52 #define ATH_REQUIRES(...) requires __VA_ARGS__
53 
54 #define ATH_MEMBER_REQUIRES(CONDITION, RETTYPE) \
55  template <bool = true> \
56  requires (CONDITION) \
57  RETTYPE
58 
59 #define ATH_MEMBER_REQUIRES_DEF(CONDITION, RETTYPE) \
60  template <bool> \
61  requires (CONDITION) \
62  RETTYPE
63 
64 
65 // Some library concepts.
66 
67 namespace CxxUtils {
68 namespace detail {
69 
70 
71 // Standard library Hash requirement.
72 template <class HASHER, class T>
73 concept IsHash =
74  std::destructible<HASHER> &&
75  std::copy_constructible<HASHER> &&
76  requires (const HASHER& h, T x)
77 {
78  { h(x) } -> std::same_as<std::size_t>;
79 };
80 
81 
82 // Standard library BinaryPredicate requirement.
83 template <class PRED, class ARG1, class ARG2=ARG1>
84 concept IsBinaryPredicate =
85  std::copy_constructible<PRED> &&
86  std::predicate<PRED, ARG1, ARG2>;
87 
88 
89 template <class CONTAINER>
90 concept IsContiguousContainer =
91  requires (CONTAINER& c)
92  {
93  requires std::contiguous_iterator<decltype(c.begin())>;
94  };
95 
96 
97 template <class ITERATOR, class VAL>
98 concept InputValIterator =
99  std::input_iterator<ITERATOR> &&
100  std::convertible_to<std::iter_value_t<ITERATOR>, VAL>;
101 
102 
103 } // namespace detail
104 } // namespace CxxUtils
105 
106 #else
107 
108 #define HAVE_CONCEPTS 0
109 
110 #define ATH_REQUIRES(...)
111 
112 #define ATH_MEMBER_REQUIRES(CONDITION, RETTYPE) \
113  template <bool Enable = true> \
114  std::enable_if_t<Enable && (CONDITION), RETTYPE>
115 
116 #define ATH_MEMBER_REQUIRES_DEF(CONDITION, RETTYPE) \
117  template <bool Enable> \
118  std::enable_if_t<Enable && (CONDITION), RETTYPE>
119 
120 #endif
121 
122 
123 #endif // not CXXUTILS_CONCEPTS_H
detail
Definition: extract_histogram_tag.cxx:14
x
#define x
extractSporadic.h
list h
Definition: extractSporadic.py:97
CxxUtils
Definition: aligned_vector.h:29
h
python.compressB64.c
def c
Definition: compressB64.py:93