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
13namespace malloy::mp
14{
15
16 namespace detail
17 {
19 template<
20 template<typename...> typename V,
21 typename... Vargs
22 >
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>
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>
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>
66
67}
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:43
unwrap_variant< V > body_type
Converts from a variant of possible bodies to the actual body type taken by callbacks.
Definition: mp.hpp:50
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
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
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
Helper to map variant<T...> to variant<response<T>...>
Definition: mp.hpp:24