-
Notifications
You must be signed in to change notification settings - Fork 5
/
lambda_utils.h
60 lines (47 loc) · 1002 Bytes
/
lambda_utils.h
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
58
59
#ifndef LAMBDA_UTILS_20_10_2015
#define LAMBDA_UTILS_20_10_2015
#include <type_traits>
namespace lut
{
template<class... Fs>
struct overload_set
{
};
template<class F0, class...Fs>
struct overload_set<F0, Fs...>
: F0, overload_set<Fs...>
{
overload_set(F0 f0, Fs... fs) :
F0(std::move(f0)),
overload_set<Fs...>(std::move(fs)...)
{
}
using F0::operator();
using overload_set<Fs...>::operator();
};
template<class F>
struct overload_set<F> : F
{
overload_set(F f) :F(std::move(f)){};
using F::operator();
};
template<class...Fs>
overload_set<typename std::decay<Fs>::type...> overload(Fs&&...fs)
{
return{ std::forward<Fs>(fs)... };
}
namespace detail
{
struct NC
{
NC() = default;
NC(NC const&) = delete;
NC& operator=(NC const&) = delete;
NC(NC&&) = default;
};
}
} // ~ namespace lut
/// x___x will belong to the closure's scope
/// so it'll be a unique expression across lambdas
#define nocopy x___x = lut::detail::NC()
#endif