ATLAS Offline Software
Loading...
Searching...
No Matches
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 */
11
12
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
24namespace CxxUtils {
25namespace detail {
26
27
28// Standard library Hash requirement.
29template <class HASHER, class T>
30concept 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.
40template <class PRED, class ARG1, class ARG2=ARG1>
42 std::copy_constructible<PRED> &&
43 std::predicate<PRED, ARG1, ARG2>;
44
45
46template <class CONTAINER>
48 requires (CONTAINER& c)
49 {
50 requires std::contiguous_iterator<decltype(c.begin())>;
51 };
52
53
54template <class ITERATOR, class VAL>
56 std::input_iterator<ITERATOR> &&
57 std::convertible_to<std::iter_value_t<ITERATOR>, VAL>;
58
59template <typename SET>
60concept 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
73template <typename MAP>
74concept 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.
86template <typename F, typename T>
88 std::invocable<F> && std::convertible_to<std::invoke_result_t<F>, T*>;
89
90
92template <class T>
93concept 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
#define SET(n)
Definition MD5.cxx:147
#define x
Header file for AthHistogramAlgorithm.
Has addRef() and release()
Definition concepts.h:93