-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathhandler_type_check.hpp
45 lines (36 loc) · 1.19 KB
/
handler_type_check.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Copyright (C) 2019 Jack.
//
// Author: jack
// Email: jack.wgm at gmail dot com
//
#pragma once
#include <type_traits>
#include <boost/asio/async_result.hpp>
namespace avhttp {
namespace detail {
template<class R, class C, class ...A>
auto is_invocable_test(C&& c, int, A&& ...a)
-> decltype(std::is_convertible<decltype(c(std::forward<A>(a)...)), R>::value
|| std::is_same<R, void>::value, std::true_type());
template<class R, class C, class ...A>
std::false_type
is_invocable_test(C&& c, long, A&& ...a);
template<class C, class F>
struct is_invocable : std::false_type
{};
template<class C, class R, class ...A>
struct is_invocable<C, R(A...)>
: decltype(is_invocable_test<R>(
std::declval<C>(), 1, std::declval<A>()...))
{};
template<class T, class Signature>
using is_completion_handler = std::integral_constant<bool,
std::is_move_constructible<typename std::decay<T>::type>::value &&
detail::is_invocable<T, Signature>::value>;
#define AVHTTP_HANDLER_TYPE_CHECK(type, sig) \
static_assert(avhttp::detail::is_completion_handler< \
BOOST_ASIO_HANDLER_TYPE(type, sig), sig>::value, \
"CompletionHandler signature requirements not met")
}
}