Sequoia
Loading...
Searching...
No Matches
Concepts.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2020. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
15
16#include <utility>
17#include <functional>
18#include <concepts>
19
20namespace sequoia
21{
23 template <class F, class R, class... Args>
24 concept invocable_r =
25 requires(F&& f, Args&&... args) {
26 { std::invoke(std::forward<F>(f), std::forward<Args>(args)...) } -> std::same_as<R>;
27 };
28
30 template <class F, class R, class... Args>
31 concept regular_invocable_r = invocable_r<F, R, Args...>;
32
34 template <class T>
35 concept movable_comparable = std::movable<T> && std::equality_comparable<T>;
36
38 template <class T>
39 concept pseudoregular = movable_comparable<T> && std::copyable<T>;
40
42 template <class T>
43 concept moveonly = movable_comparable<T> && !std::copyable<T>;
44
45
47 template <class A>
48 concept alloc = requires(A& a) {
49 a.allocate(0);
50 };
51
53 template <class A>
54 concept scoped_alloc = alloc<A> && requires() {
55 typename A::outer_allocator_type;
56 typename A::inner_allocator_type;
57 };
58
60 template<class T, class Stream>
61 concept serializable_to = requires(std::remove_reference_t<Stream>& stream, const std::remove_reference_t<T>& t) {
62 typename Stream::char_type;
63 stream << t;
64 };
65
67 template<class T, class Stream>
68 concept deserializable_from = requires(std::remove_reference_t<Stream>& stream, std::remove_reference_t<T>& t) {
69 typename Stream::char_type;
70 stream >> t;
71 };
72
74 template<class T, class... Args>
75 concept initializable_from = requires{
76 T{std::declval<Args>()...};
77 };
78
80 template<class T>
81 concept arithmetic = std::is_arithmetic_v<T>;
82
90 template<class T>
91 concept faithful_range = requires(T& t) {
92 std::ranges::begin(t);
93 std::ranges::end(t);
94
95 requires (!std::same_as<std::remove_cvref_t<decltype(*std::ranges::begin(t))>, std::remove_cvref_t<T>>);
96 };
97
104 template<class T>
105 concept deep_equality_comparable = is_deep_equality_comparable_v<T>;
106
108}
Traits which are sufficiently general to appear in the sequoia namespace.
A concept for allocators.
Definition: Concepts.hpp:48
\brieft A concept for arithmetic types
Definition: Concepts.hpp:81
Concept to work around the fact that currently the stl typically underconstrains operator==.
Definition: Concepts.hpp:105
A concept which is realized by a Stream& which may be deserialized to a T&.
Definition: Concepts.hpp:68
Similar to std::range but excludes the case where dereferencing yields the same type as the range.
Definition: Concepts.hpp:91
A concept similar to std::constructible_from, but which considers braced-init.
Definition: Concepts.hpp:75
Supplements std::invocable.
Definition: Concepts.hpp:24
Building block for concepts related to std::regular but without the requirement of default constructi...
Definition: Concepts.hpp:35
The move-only version of sequoia::pseudoregular.
Definition: Concepts.hpp:43
Similar to std::regular but relaxes the requirement of default initializability.
Definition: Concepts.hpp:39
Supplements std::regular_invocable.
Definition: Concepts.hpp:31
A concept for scoped allocators.
Definition: Concepts.hpp:54
A concept which is realized by a T const& which may be serialized to a Stream&.
Definition: Concepts.hpp:61