Malloy
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
malloy
core
mp.hpp
1
#pragma once
2
3
#include "type_traits.hpp"
4
#include "http/response.hpp"
5
6
#include <variant>
7
#include <type_traits>
8
13
namespace
malloy::mp
14
{
15
16
namespace
detail
17
{
19
template
<
20
template
<
typename
...>
typename
V,
21
typename
... Vargs
22
>
23
struct
conv_to_resp_helper
24
{
25
using
type = V<http::response<Vargs>...>;
26
27
explicit
28
constexpr
29
conv_to_resp_helper(V<Vargs...>)
30
{
31
}
32
};
33
}
34
42
template
<
typename
V>
43
using
unwrap_variant
= std::conditional_t<std::variant_size_v<V> == 1, std::variant_alternative_t<0, V>, V>;
44
48
template
<
typename
V>
49
requires
(
malloy::concepts::is_variant_of_bodies<V>
)
50
using
body_type
=
unwrap_variant<V>
;
51
53
// ToDo: Concept for F
54
template
<
typename
F>
55
using
bodies_for_t
= std::invoke_result_t<
decltype
(&F::body_for),
const
F*,
const
typename
F::header_type&>;
56
58
template
<
typename
Bodies>
59
requires
(
malloy::concepts::is_variant_of_bodies<Bodies>
)
60
using
to_responses
=
typename
decltype
(
detail::conv_to_resp_helper
{std::declval<Bodies>()})::type;
61
63
// ToDo: Concept for Filter
64
template
<
typename
Filter>
65
using
filter_resp_t
=
unwrap_variant<to_responses<bodies_for_t<Filter>
>>;
66
67
}
malloy::concepts::is_variant_of_bodies
Definition
type_traits.hpp:123
malloy::mp
Namespace for metaprogramming utils.
malloy::mp::unwrap_variant
std::conditional_t< std::variant_size_v< V >==1, std::variant_alternative_t< 0, V >, V > unwrap_variant
Pattern: unwrap_variant<variant<T>> -> T unwrap_variant<variant<T, ...> -> std::variant<T,...
Definition
mp.hpp:43
malloy::mp::bodies_for_t
std::invoke_result_t< decltype(&F::body_for), const F *, const typename F::header_type & > bodies_for_t
Resolves the body type used by a filter F.
Definition
mp.hpp:55
malloy::mp::body_type
unwrap_variant< V > body_type
Converts from a variant of possible bodies to the actual body type taken by callbacks.
Definition
mp.hpp:50
malloy::mp::filter_resp_t
unwrap_variant< to_responses< bodies_for_t< Filter > > > filter_resp_t
Resolves to the type that must be taken in callbacks handling responses for Filter.
Definition
mp.hpp:65
malloy::mp::to_responses
typename decltype(detail::conv_to_resp_helper{std::declval< Bodies >()})::type to_responses
Converts a variant<T...> where T is body to a variant<response<T>...>.
Definition
mp.hpp:60
malloy::mp::detail::conv_to_resp_helper
Helper to map variant<T...> to variant<response<T>...>.
Definition
mp.hpp:24
Generated by
1.18.0