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-2025 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_CONCEPTS_H
14 #define CXXUTILS_CONCEPTS_H
15 
16 
17 #include <type_traits>
18 #include <iterator>
19 #include <concepts>
20 
21 
22 // Some library concepts.
23 
24 namespace CxxUtils {
25 namespace detail {
26 
27 
28 // Standard library Hash requirement.
29 template <class HASHER, class T>
30 concept IsHash =
31  std::destructible<HASHER> &&
32  std::copy_constructible<HASHER> &&
33  requires (const HASHER& h, T x)
34 {
35  { h(x) } -> std::same_as<std::size_t>;
36 };
37 
38 
39 // Standard library BinaryPredicate requirement.
40 template <class PRED, class ARG1, class ARG2=ARG1>
42  std::copy_constructible<PRED> &&
43  std::predicate<PRED, ARG1, ARG2>;
44 
45 
46 template <class CONTAINER>
48  requires (CONTAINER& c)
49  {
50  requires std::contiguous_iterator<decltype(c.begin())>;
51  };
52 
53 
54 template <class ITERATOR, class VAL>
56  std::input_iterator<ITERATOR> &&
57  std::convertible_to<std::iter_value_t<ITERATOR>, VAL>;
58 
59 template <typename SET>
60 concept SimpleAssociativeContainer = requires(SET s, typename SET::key_type k) {
61  typename SET::value_type;
62  typename SET::key_type;
63  typename SET::iterator;
64  typename SET::const_iterator;
65  typename SET::reference;
66  typename SET::const_reference;
67  typename SET::const_pointer;
68 
69  { s.find(k) } -> std::convertible_to<typename SET::const_iterator>;
70  { s.insert(k) } -> std::convertible_to<std::pair<typename SET::iterator, bool>>;
71 };
72 
73 template <typename MAP>
74 concept PairAssociativeContainer = requires(MAP m, typename MAP::key_type k, typename MAP::mapped_type v) {
75  typename MAP::value_type;
76  typename MAP::key_type;
77  typename MAP::mapped_type;
78 
79  { m[k] } -> std::convertible_to<typename MAP::mapped_type>;
80  { m.find(k) } -> std::convertible_to<typename MAP::iterator>;
81  { m.insert(std::make_pair(k, v)) } -> std::same_as<std::pair<typename MAP::iterator, bool>>;
82 };
83 
84 // An allocation function. Can be used like <code>T* p = F()</code> to allocate
85 // a new object.
86 template <typename F, typename T>
88  std::invocable<F> && std::convertible_to<std::invoke_result_t<F>, T*>;
89 
90 
92 template <class T>
93 concept RefCounted =
94  requires (T& x)
95 {
96  { x.addRef() };
97  { x.release() };
98 };
99 
100 
101 } // namespace detail
102 } // namespace CxxUtils
103 
104 
105 
106 #endif // not CXXUTILS_CONCEPTS_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CxxUtils::detail::SimpleAssociativeContainer
concept SimpleAssociativeContainer
Definition: concepts.h:60
detail
Definition: extract_histogram_tag.cxx:14
x
#define x
CxxUtils::detail::IsHash
concept IsHash
Definition: concepts.h:30
CxxUtils::detail::InputValIterator
concept InputValIterator
Definition: concepts.h:55
extractSporadic.h
list h
Definition: extractSporadic.py:96
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::requires
requires(detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentMap
Hash map from integers/pointers allowing concurrent, lockless reads.
Definition: ConcurrentMap.h:94
CxxUtils::detail::RefCounted
concept RefCounted
Has addRef() and release()
Definition: concepts.h:93
CxxUtils::detail::IsContiguousContainer
concept IsContiguousContainer
Definition: concepts.h:47
CxxUtils::detail::IsBinaryPredicate
concept IsBinaryPredicate
Definition: concepts.h:41
CxxUtils::detail::AllocationFunction
concept AllocationFunction
Definition: concepts.h:87
python.PyAthena.v
v
Definition: PyAthena.py:154
h
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:43
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
CxxUtils::detail::PairAssociativeContainer
concept PairAssociativeContainer
Definition: concepts.h:74
python.compressB64.c
def c
Definition: compressB64.py:93
fitman.k
k
Definition: fitman.py:528
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106
SET
#define SET(n)
Definition: MD5.cxx:147