1 // This file is part of Desktop App Toolkit,
2 // a set of libraries for developing nice desktop applications.
3 //
4 // For license and copyright information please follow this link:
5 // https://github.com/desktop-app/legal/blob/master/LEGAL
6 //
7 #pragma once
8 
9 #include <rpl/details/callable.h>
10 
11 namespace base {
12 
13 template <typename Data, typename Method, typename ...Methods>
decltype(auto)14 inline decltype(auto) match_method(
15 		Data &&data,
16 		Method &&method,
17 		Methods &&...methods) {
18 	using namespace rpl::details;
19 	if constexpr (is_callable_plain_v<Method, Data&&>) {
20 		return std::forward<Method>(method)(std::forward<Data>(data));
21 	} else {
22 		return match_method(
23 			std::forward<Data>(data),
24 			std::forward<Methods>(methods)...);
25 	}
26 }
27 
28 template <
29 	typename Data1,
30 	typename Data2,
31 	typename Method,
32 	typename ...Methods>
decltype(auto)33 inline decltype(auto) match_method2(
34 		Data1 &&data1,
35 		Data2 &&data2,
36 		Method &&method,
37 		Methods &&...methods) {
38 	using namespace rpl::details;
39 	if constexpr (is_callable_plain_v<Method, Data1&&, Data2&&>) {
40 		return std::forward<Method>(method)(
41 			std::forward<Data1>(data1),
42 			std::forward<Data2>(data2));
43 	} else {
44 		return match_method2(
45 			std::forward<Data1>(data1),
46 			std::forward<Data2>(data2),
47 			std::forward<Methods>(methods)...);
48 	}
49 }
50 
51 } // namespace base
52