Circus 0.0.1-alpha
C++ Serialization Framework
Loading...
Searching...
No Matches
circus_traits.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3#include <iostream>
4#include <vector>
13namespace circus::traits {
17template <typename Ts, typename... Us>
18struct exists {
19 constexpr static bool value = (std::is_same_v<Ts, Us> || ...);
20};
21
24template <typename TypeComparablePolicy, typename... Ts>
25concept ComparableTypes = (std::is_same_v<TypeComparablePolicy, Ts> && ...);
26
30template <typename Curr, typename... Others>
31 requires(ComparableTypes<Curr, Others...>)
32[[nodiscard]] constexpr static bool any_of(const Curr &c, const Others &&...o) noexcept {
33 return ((c == o) || ...);
34}
38template <typename Curr, typename... Others>
39 requires(ComparableTypes<Curr, Others...>)
40[[nodiscard]] constexpr static bool none_of(const Curr &c, Others &&...o) noexcept {
41 return !(any_of(c, std::forward<Others>(o)...));
42};
46template <typename T>
47concept IsSerializable = requires(T t) {
48 {
49 t.serialize(std::declval<std::ostream &>())
50 };
51};
52
55template <typename T>
56concept OutStream = std::is_convertible_v<T, std::ostream &>;
60template <typename T>
62 requires(std::ostream &os, T value) {
63 {
64 os << value
65 }
66 -> OutStream;
67 };
68
71template <typename T>
72concept InStream = std::is_convertible_v<T, std::istream &>;
76template <typename T>
77concept InStreamable = requires(std::istream &is, T value) {
78 {
79 value >> is
80 } -> InStream;
81};
82
85template <typename T, typename = void>
86struct pair_inspect : std::false_type {
87};
88
89template <typename T>
90struct pair_inspect<T, std::void_t<
91 decltype(std::declval<T>().first),
92 decltype(std::declval<T>().second)>> : std::true_type {
93 using first_type = decltype(std::declval<T>().first);
94 using second_type = decltype(std::declval<T>().second);
95};
96
99template <typename T>
104template <class T>
105concept StringLike = std::is_convertible_v<T, std::string_view>;
109template <typename T>
114template <typename T>
115struct is_vector : std::false_type {
116 using value_type = T;
117};
118
119template <typename T, typename A>
120struct is_vector<std::vector<T, A>> : std::true_type {
121 using value_type = T;
122};
123
126template <typename T>
127concept Flaggable = std::is_enum_v<T> && (std::is_same_v<std::underlying_type_t<T>, std::uint64_t> || std::is_same_v<std::underlying_type_t<T>, std::uint32_t>);
131template <typename V>
139template <class T>
140concept Container = requires(T a, const T b) {
141 requires std::regular<T>;
142 requires std::swappable<T>;
143 requires std::same_as<typename T::reference, typename T::value_type &>;
144 requires std::same_as<typename T::const_reference, const typename T::value_type &>;
145 requires std::forward_iterator<typename T::iterator>;
146 requires std::forward_iterator<typename T::const_iterator>;
147 requires std::signed_integral<typename T::difference_type>;
148 requires std::same_as<typename T::difference_type, typename std::iterator_traits<typename T::iterator>::difference_type>;
149 requires std::same_as<typename T::difference_type, typename std::iterator_traits<typename T::const_iterator>::difference_type>;
150 { a.begin() } -> std::same_as<typename T::iterator>;
151 { a.end() } -> std::same_as<typename T::iterator>;
152 { b.begin() } -> std::same_as<typename T::const_iterator>;
153 { b.end() } -> std::same_as<typename T::const_iterator>;
154 { a.cbegin() } -> std::same_as<typename T::const_iterator>;
155 { a.cend() } -> std::same_as<typename T::const_iterator>;
156 { a.size() } -> std::same_as<typename T::size_type>;
157 { a.max_size() } -> std::same_as<typename T::size_type>;
158 { a.empty() } -> std::convertible_to<bool>;
159};
160
161}; // namespace circus::traits
162 // end of Traits group
Concept that checks if all types match a given type.
Definition circus_traits.hpp:25
Concept for containers that satisfy a wide set of STL-like requirements. Includes regularity,...
Definition circus_traits.hpp:140
Concept for enum types that are eligible for flagging (i.e., bitmask ops).
Definition circus_traits.hpp:127
Concept that checks if a type can be used as an input stream.
Definition circus_traits.hpp:72
Concept for values that can be extracted from an std::istream using >>.
Definition circus_traits.hpp:77
Concept that checks whether a type has a .serialize(std::ostream&) method.
Definition circus_traits.hpp:47
Concept that checks if a type can be used as an output stream.
Definition circus_traits.hpp:56
Concept for values that can be streamed using << to an std::ostream.
Definition circus_traits.hpp:61
Concept for types that behave like key-value pairs.
Definition circus_traits.hpp:100
Concept for types that are serializable via either literal streaming or custom serialize.
Definition circus_traits.hpp:110
Concept for std::vector-like containers whose elements can be streamed.
Definition circus_traits.hpp:132
Concept for types that can be converted to a string-like view.
Definition circus_traits.hpp:105
Checks if a type Ts exists among a variadic list of types Us.
Definition circus_traits.hpp:18
Trait to determine if a type is a std::vector.
Definition circus_traits.hpp:115
Trait to determine if a type is a pair-like structure (has .first and .second).
Definition circus_traits.hpp:86