Malloy
Loading...
Searching...
No Matches
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
9// ToDo: Should we move this to a different namespace? There are type_traits/concepts all over the place.
10
15namespace malloy::mp
16{
17
18 namespace detail
19 {
21 template<
22 template<typename...> typename V,
23 typename... Vargs
24 >
26 {
27 using type = V<http::response<Vargs>...>;
28
29 explicit
30 constexpr
31 conv_to_resp_helper(V<Vargs...>)
32 {
33 }
34 };
35 }
36
44 template<typename V>
45 using unwrap_variant = std::conditional_t<std::variant_size_v<V> == 1, std::variant_alternative_t<0, V>, V>;
46
50 template<typename V>
53
55 // ToDo: Concept for F
56 template<typename F>
57 using bodies_for_t = std::invoke_result_t<decltype(&F::body_for), const F*, const typename F::header_type&>;
58
60 template<typename Bodies>
62 using to_responses = typename decltype(detail::conv_to_resp_helper{std::declval<Bodies>()})::type;
63
65 // ToDo: Concept for Filter
66 template<typename Filter>
68
69}
Definition: type_traits.hpp:123
Namespace for metaprogramming utils.
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:45
unwrap_variant< V > body_type
Converts from a variant of possible bodies to the actual body type taken by callbacks.
Definition: mp.hpp:52
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:57
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:62
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:67
Helper to map variant<T...> to variant<response<T>...>
Definition: mp.hpp:26