Debian Codegraph @

3rd_party/range-v3/range/v3/functional/concepts.hpp

raw
1
2 /// \file
3 // Range v3 library
4 //
5 // Copyright Eric Niebler 2013-present
6 //
7 // Use, modification and distribution is subject to the
8 // Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 //
12 // Project home: https://github.com/ericniebler/range-v3
13 //
14 #ifndef RANGES_V3_FUNCTIONAL_CONCEPTS_HPP
15 #define RANGES_V3_FUNCTIONAL_CONCEPTS_HPP
16
17 #include <concepts/concepts.hpp>
18
19 #include <range/v3/functional/invoke.hpp>
20
21 #include <range/v3/detail/prologue.hpp>
22
23 namespace ranges
24 {
25 /// \addtogroup group-functional
26 /// @{
27
28 // clang-format off
29 // WORKAROUND mysterious msvc bug
30 #if defined(_MSC_VER) && !defined(__clang__)
31 /// \concept invocable
32 /// \brief The \c invocable concept
33 template<typename Fun, typename... Args>
34 CPP_concept invocable =
35 std::is_invocable_v<Fun, Args...>;
36 #else
37 /// \concept invocable_
38 /// \brief The \c invocable_ concept
39 template<typename Fun, typename... Args>
40 CPP_requires(invocable_,
41 requires(Fun && fn) //
42 (
43 invoke((Fun &&) fn, std::declval<Args>()...)
44 ));
45 /// \concept invocable
46 /// \brief The \c invocable concept
47 template<typename Fun, typename... Args>
48 CPP_concept invocable =
49 CPP_requires_ref(ranges::invocable_, Fun, Args...);
50 #endif
51
52 /// \concept regular_invocable
53 /// \brief The \c regular_invocable concept
54 template<typename Fun, typename... Args>
55 CPP_concept regular_invocable =
56 invocable<Fun, Args...>;
57 // Axiom: equality_preserving(invoke(f, args...))
58
59 /// \concept predicate_
60 /// \brief The \c predicate_ concept
61 template<typename Fun, typename... Args>
62 CPP_requires(predicate_,
63 requires(Fun && fn) //
64 (
65 concepts::requires_<
66 convertible_to<
67 decltype(invoke((Fun &&) fn, std::declval<Args>()...)),
68 bool>>
69 ));
70 /// \concept predicate
71 /// \brief The \c predicate concept
72 template<typename Fun, typename... Args>
73 CPP_concept predicate =
74 regular_invocable<Fun, Args...> &&
75 CPP_requires_ref(ranges::predicate_, Fun, Args...);
76
77 /// \concept relation
78 /// \brief The \c relation concept
79 template<typename R, typename T, typename U>
80 CPP_concept relation =
81 predicate<R, T, T> &&
82 predicate<R, U, U> &&
83 predicate<R, T, U> &&
84 predicate<R, U, T>;
85
86 /// \concept strict_weak_order
87 /// \brief The \c strict_weak_order concept
88 template<typename R, typename T, typename U>
89 CPP_concept strict_weak_order =
90 relation<R, T, U>;
91 // clang-format on
92
93 namespace cpp20
94 {
95 using ranges::invocable;
96 using ranges::predicate;
97 using ranges::regular_invocable;
98 using ranges::relation;
99 using ranges::strict_weak_order;
100 } // namespace cpp20
101 /// @}
102 } // namespace ranges
103
104 #include <range/v3/detail/epilogue.hpp>
105
106 #endif