1 | #ifndef MAPBOX_UTIL_VARIANT_VISITOR_HPP |
2 | #define MAPBOX_UTIL_VARIANT_VISITOR_HPP |
3 | |
4 | namespace mapbox { |
5 | namespace util { |
6 | |
7 | template <typename... Fns> |
8 | struct visitor; |
9 | |
10 | template <typename Fn> |
11 | struct visitor<Fn> : Fn |
12 | { |
13 | using type = Fn; |
14 | using Fn::operator(); |
15 | |
16 | visitor(Fn fn) : Fn(fn) {} |
17 | }; |
18 | |
19 | template <typename Fn, typename... Fns> |
20 | struct visitor<Fn, Fns...> : Fn, visitor<Fns...> |
21 | { |
22 | using type = visitor; |
23 | using Fn::operator(); |
24 | using visitor<Fns...>::operator(); |
25 | |
26 | visitor(Fn fn, Fns... fns) : Fn(fn), visitor<Fns...>(fns...) {} |
27 | }; |
28 | |
29 | template <typename... Fns> |
30 | visitor<Fns...> make_visitor(Fns... fns) |
31 | { |
32 | return visitor<Fns...>(fns...); |
33 | } |
34 | |
35 | } // namespace util |
36 | } // namespace mapbox |
37 | |
38 | #endif // MAPBOX_UTIL_VARIANT_VISITOR_HPP |
39 | |