5 #ifndef PACKIO_TRAITS_H
6 #define PACKIO_TRAITS_H
11 #include <type_traits>
14 #include "internal/config.h"
15 #include "internal/rpc.h"
16 #include "internal/utils.h"
18 #if defined(PACKIO_TRAITS_CHECK_DISABLE)
19 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) (void)0
20 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) (void)0
22 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) \
24 ::packio::traits::Trait<Trait>::value, "Trait " #Trait " not satisfied")
25 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) \
27 ::packio::traits::Trait<Trait, __VA_ARGS__>::value, \
28 "Trait " #Trait " not satisfied")
33 template <
typename Rpc>
39 template <
typename,
typename,
typename =
void>
40 struct AsyncProcedureImpl : std::false_type {
43 template <
typename T,
typename Rpc>
44 struct AsyncProcedureImpl<T, Rpc, std::enable_if_t<internal::func_traits_v<T>>> {
45 using TArgs =
typename internal::func_traits<T>::args_type;
46 static constexpr
bool value = [] {
47 if constexpr (std::tuple_size_v<TArgs> == 0) {
51 return std::is_same_v<
52 std::decay_t<std::tuple_element_t<0, TArgs>>,
53 completion_handler<Rpc>>;
58 template <
typename T,
typename Rpc>
59 constexpr
bool is_async_procedure_v = AsyncProcedureImpl<T, Rpc>::value;
63 template <
bool condition>
64 struct Trait : std::integral_constant<bool, condition> {
79 template <
typename T,
typename Rpc>
81 : Trait<std::is_invocable_v<T, error_code, typename Rpc::response_type>> {
89 template <
typename T,
typename Session>
91 : Trait<std::is_invocable_v<T, error_code, std::shared_ptr<Session>>> {
100 template <
typename T,
typename Rpc>
110 template <
typename T>
114 #if defined(PACKIO_HAS_CO_AWAIT)
121 template <
typename T>
123 : Trait<internal::is_coroutine_v<T> && internal::func_traits_v<T>> {
completion_handler< rpc > completion_handler
The completion_handler for JSON-RPC.
Definition: json_rpc.h:23
The packio namespace.
Definition: arg.h:14
AsyncProcedure trait.
Definition: traits.h:101
CallHandler trait.
Definition: traits.h:81
CoroProcedure trait.
Definition: traits.h:123
NotifyHandler trait.
Definition: traits.h:72
ServeHandler trait.
Definition: traits.h:91
SyncProcedure trait.
Definition: traits.h:111