-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_bind.hpp
57 lines (47 loc) · 1.23 KB
/
ex_bind.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
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include <type_traits>
#include <utility>
namespace ex
{
namespace internal
{
template <typename T, typename ...Args>
struct all_same_as;
template <typename T, typename First>
struct all_same_as<T, First>
{
static constexpr bool value = std::is_same<T, First>::value;
};
template <typename T, typename First, typename ...Rest>
struct all_same_as<T, First, Rest...>
{
static constexpr bool value = std::is_same<T, First>::value && all_same_as<T, Rest...>::value;
};
struct ph_t
{
constexpr ph_t() = default;
template <typename T>
constexpr ph_t(T&&)
{
}
};
}
constexpr auto ph = internal::ph_t{};
template <typename ReturnType,
typename ...Args,
typename ...PHs
#ifdef EX_BIND_DIAGNOSTIC_ENABLE_IF
,typename = typename std::enable_if<internal::all_same_as<const internal::ph_t&, PHs...>::value>::type
#endif
>
auto bind(ReturnType(*func)(Args...), PHs&&... placeHolders)
{
#ifdef EX_BIND_DIAGNOSTIC_STATIC_ASSERT
static_assert(internal::all_same_as<const internal::ph_t&, PHs...>::value, R"("ex::ph" is the only valid placeholder !)");
#endif
return [func](Args&&... originalArgs, PHs&&... innerPlaceHolders)
{
return func(std::forward<Args>(originalArgs)...);
};
}
}