Malloy
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
malloy
client
type_traits.hpp
1
#pragma once
2
3
#include "../core/http/response.hpp"
4
#include "../core/http/type_traits.hpp"
5
#include "../core/type_traits.hpp"
6
7
#include <concepts>
8
#include <variant>
9
10
namespace
malloy::client::concepts
11
{
12
13
namespace
detail
14
{
15
16
template
<
typename
F>
17
struct
response_filter_body_helper
18
{
19
template
<malloy::http::concepts::body T>
20
void
operator()(T&&)
21
{
22
F f2;
23
typename
F::header_type h2;
24
typename
std::decay_t<T>::value_type r;
25
f2.setup_body(h2, r);
26
}
27
};
28
37
template
<
typename
Callback>
38
struct
http_cb_helper
39
{
40
Callback cb;
41
42
template
<
typename
V>
43
void
operator()(V&&)
44
{
45
using
body_t = std::decay_t<V>;
46
malloy::http::response<body_t>
res;
47
48
cb(std::move(res));
49
}
50
51
};
52
53
}
// namespace detail
54
55
template
<
typename
F>
56
concept
response_filter
= std::move_constructible<F> &&
requires
(
const
F& f,
const
typename
F::header_type& h)
57
{
58
{
59
f.body_for(h)
60
} ->
malloy::concepts::is_variant_of_bodies
;
61
62
{
63
std::visit(
detail::response_filter_body_helper<F>
{}, f.body_for(h))
64
};
65
};
66
67
template
<
typename
F,
typename
Filter>
68
concept
http_callback
=
response_filter<Filter>
&& std::move_constructible<F>&&
requires
(F cb,
const
Filter& f,
const
typename
Filter::header_type& h)
69
{
70
std::visit(
detail::http_cb_helper<F>
{std::move(cb)}, f.body_for(h));
71
};
72
73
}
74
malloy::http::response
Definition
response.hpp:22
malloy::client::concepts::http_callback
Definition
type_traits.hpp:68
malloy::client::concepts::response_filter
Definition
type_traits.hpp:56
malloy::concepts::is_variant_of_bodies
Definition
type_traits.hpp:123
malloy::client::concepts::detail::http_cb_helper
Helper for http_callback concept.
Definition
type_traits.hpp:39
malloy::client::concepts::detail::response_filter_body_helper
Definition
type_traits.hpp:18
Generated by
1.18.0