Malloy
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
malloy
core
type_traits.hpp
1
#pragma once
2
3
#include "error.hpp"
4
5
#include <boost/asio/buffer.hpp>
6
#include <boost/beast/core/buffer_traits.hpp>
7
#include <boost/beast/http/type_traits.hpp>
8
9
#include <concepts>
10
#include <variant>
11
17
namespace
malloy::concepts
18
{
19
20
namespace
detail
21
{
22
23
template
<
template
<
typename
...>
typename
T>
24
struct
is_helper
25
{
26
template
<
typename
... Ts>
27
void
operator()(
const
T<Ts...>&)
const
28
{
29
}
30
};
31
32
}
// namespace detail
33
34
template
<
typename
B>
35
concept
const_buffer_sequence
= boost::asio::is_const_buffer_sequence<B>::value;
36
37
template
<
typename
Func>
38
concept
accept_handler
= std::invocable<Func, malloy::error_code>;
39
40
template
<
typename
B>
41
concept
dynamic_buffer
= boost::asio::is_dynamic_buffer<B>::value;
42
43
template
<
typename
Func>
44
concept
async_read_handler
= std::invocable<Func, boost::beast::error_code, std::size_t>;
45
52
template
<
typename
T>
53
concept
callable_string
=
requires
(T t)
54
{
55
{ t() } -> std::same_as<std::string>;
56
// { t() } -> std::same_as<std::string_view>; // ToDo: Want to extend this to also accept std::string_view as return type.
57
};
58
59
namespace
detail
60
{
66
template
<
typename
T,
template
<
typename
>
typename
Pred>
67
concept
sats_pred
=
static_cast<
bool
>
(Pred<T>::value);
68
75
template
<
template
<
typename
...>
typename
A,
template
<
typename
>
typename
Cond>
76
struct
is_container_of_helper
77
{
78
template
<sats_pred<Cond>... Ts>
79
void
operator()(
const
A<Ts...>&)
const
80
{
81
}
82
};
83
87
template
<
typename
T>
88
struct
always_true
89
{
90
static
constexpr
bool
value =
true
;
91
};
92
93
}
94
template
<
typename
T,
template
<
typename
...>
typename
Container,
template
<
typename
>
typename
Cond>
95
concept
is_container_of_if
=
requires
(
const
T& v,
const
detail::is_container_of_helper<Container, Cond>
& h)
96
{
97
h(v);
98
};
99
100
template
<
typename
T,
template
<
typename
...>
typename
A>
101
concept
is
=
is_container_of_if<T, A, detail::always_true>
;
102
103
template
<
typename
V>
104
concept
is_variant
=
is<V, std::variant>
;
105
106
namespace
detail
107
{
108
template
<
template
<
typename
...>
typename
A>
109
struct
is_a
110
{
111
template
<
typename
T>
112
struct
type
113
{
114
static
constexpr
bool
value =
is<T, A>
;
115
};
116
};
117
}
118
119
template
<
typename
T,
template
<
typename
...>
typename
Contained,
template
<
typename
...>
typename
Container>
120
concept
is_container_of
=
is_container_of_if<T, Container, detail::is_a<Contained>::template
type>;
121
122
template
<
typename
T>
123
concept
is_variant_of_bodies
=
is_container_of_if<T, std::variant, boost::beast::http::is_body>
;
124
125
static_assert
(
is_container_of<std::variant<std::tuple<std::string>
, std::tuple<int>>, std::tuple, std::variant>,
"is_container_of is defective"
);
126
127
}
// namespace malloy::concepts
128
malloy::concepts::accept_handler
Definition
type_traits.hpp:38
malloy::concepts::async_read_handler
Definition
type_traits.hpp:44
malloy::concepts::callable_string
Definition
type_traits.hpp:53
malloy::concepts::const_buffer_sequence
Definition
type_traits.hpp:35
malloy::concepts::detail::sats_pred
Helper concept to transform a predicate into a concept.
Definition
type_traits.hpp:67
malloy::concepts::dynamic_buffer
Definition
type_traits.hpp:41
malloy::concepts::is_container_of_if
Definition
type_traits.hpp:95
malloy::concepts::is_container_of
Definition
type_traits.hpp:120
malloy::concepts::is_variant_of_bodies
Definition
type_traits.hpp:123
malloy::concepts::is_variant
Definition
type_traits.hpp:104
malloy::concepts::is
Definition
type_traits.hpp:101
malloy::concepts
malloy::concepts::detail::always_true
Predicate which is always true no matter the type passed to it.
Definition
type_traits.hpp:89
malloy::concepts::detail::is_a::type
Definition
type_traits.hpp:113
malloy::concepts::detail::is_a
Definition
type_traits.hpp:110
malloy::concepts::detail::is_container_of_helper
Helper for the is_container_of_if<...> concept.
Definition
type_traits.hpp:77
malloy::concepts::detail::is_helper
Definition
type_traits.hpp:25
Generated by
1.18.0