repr
0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
concepts.h
Go to the documentation of this file.
1
#pragma once
2
#include <
concepts
>
3
#include <
type_traits
>
4
#include <
string
>
5
6
namespace
librepr::detail
{
7
template
<
typename
T>
8
concept
pair_like
=
requires
(T t) {
9
t.first;
10
t.second;
11
requires
std::is_same_v
<
typename
T::first_type,
decltype
(t.first)>;
12
requires
std::is_same_v
<
typename
T::second_type,
decltype
(t.second)>;
13
};
14
15
template
<
typename
T>
16
concept
has_repr_member
=
requires
(T
const
&
obj
) {
17
{
obj
.repr() } -> std::same_as<std::string>;
18
};
19
20
template
<
typename
T>
21
concept
is_scoped_enum
= !std::is_convertible_v<T, std::underlying_type_t<T>>;
22
23
template
<
typename
T, std::
size_t
N>
24
concept
is_tuple_element
=
requires
(T t) {
25
typename
std::tuple_element_t<N, std::remove_const_t<T>>;
26
{
get<N>
(t) } -> std::convertible_to<std::tuple_element_t<N, T>
const
&>;
27
};
28
template
<
typename
T>
29
concept
tuple_like
= !std::is_reference_v<T> &&
requires
{
30
typename
std::tuple_size<T>::type;
31
requires
std::same_as<
decltype
(std::tuple_size_v<T>),
size_t
>;
32
} && []<
std::size_t
...
I
>(
std::index_sequence
<
I
...>) {
33
return
(
is_tuple_element<T, I>
&& ...);
34
}(
std::make_index_sequence<std::tuple_size_v<T>
>{});
35
36
}
// namespace librepr::detail
librepr::detail::has_repr_member
Definition
concepts.h:16
librepr::detail::is_scoped_enum
Definition
concepts.h:21
librepr::detail::is_tuple_element
Definition
concepts.h:24
librepr::detail::pair_like
Definition
concepts.h:8
librepr::detail::tuple_like
Definition
concepts.h:29
concepts
std::index_sequence
std::is_same_v
T is_same_v
librepr::detail
Definition
assert.h:89
librepr::code_for
std::string code_for()
Definition
repr:39
std::size_t
string
type_traits
include
librepr
util
concepts.h
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme