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-2023 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 } // namespace detail
98 } // namespace CxxUtils
99 
100 #else
101 
102 #define HAVE_CONCEPTS 0
103 
104 #define ATH_REQUIRES(...)
105 
106 #define ATH_MEMBER_REQUIRES(CONDITION, RETTYPE) \
107  template <bool Enable = true> \
108  std::enable_if_t<Enable && (CONDITION), RETTYPE>
109 
110 #define ATH_MEMBER_REQUIRES_DEF(CONDITION, RETTYPE) \
111  template <bool Enable> \
112  std::enable_if_t<Enable && (CONDITION), RETTYPE>
113 
114 #endif
115 
116 
117 #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