1 | #pragma once |
2 | |
3 | namespace c10 { |
4 | namespace detail { |
5 | |
6 | template <class... Ts> |
7 | struct overloaded_t {}; |
8 | |
9 | template <class T0> |
10 | struct overloaded_t<T0> : T0 { |
11 | using T0::operator(); |
12 | overloaded_t(T0 t0) : T0(std::move(t0)) {} |
13 | }; |
14 | template <class T0, class... Ts> |
15 | struct overloaded_t<T0, Ts...> : T0, overloaded_t<Ts...> { |
16 | using T0::operator(); |
17 | using overloaded_t<Ts...>::operator(); |
18 | overloaded_t(T0 t0, Ts... ts) |
19 | : T0(std::move(t0)), overloaded_t<Ts...>(std::move(ts)...) {} |
20 | }; |
21 | |
22 | } // namespace detail |
23 | |
24 | // Construct an overloaded callable combining multiple callables, e.g. lambdas |
25 | template <class... Ts> |
26 | detail::overloaded_t<Ts...> overloaded(Ts... ts) { |
27 | return {std::move(ts)...}; |
28 | } |
29 | |
30 | } // namespace c10 |
31 | |