Line data Source code
1 : //
2 : // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/beast2
8 : //
9 :
10 : #ifndef BOOST_BEAST2_SERVER_CALL_MF_HPP
11 : #define BOOST_BEAST2_SERVER_CALL_MF_HPP
12 :
13 : #include <boost/beast2/detail/config.hpp>
14 : #include <type_traits>
15 : #include <utility>
16 :
17 : namespace boost {
18 : namespace beast2 {
19 :
20 : namespace detail {
21 : // Primary template
22 : template<class>
23 : struct result_of;
24 :
25 : // Partial specialization for callable types
26 : template<class F, class... Args>
27 : struct result_of<F(Args...)>
28 : {
29 : private:
30 : template<class G, class... A>
31 : static auto test(int) -> decltype(std::declval<G>()(std::declval<A>()...));
32 :
33 : template<class, class...>
34 : static void test(...);
35 :
36 : public:
37 : using type = decltype(test<F, Args...>(0));
38 : };
39 : template<class T>
40 : using result_of_t = typename result_of<T>::type;
41 : } // detail
42 :
43 : template<class T, class MemFn>
44 : class call_mf_impl
45 : {
46 : T* obj_;
47 : MemFn memfn_;
48 :
49 : public:
50 0 : call_mf_impl(T* obj, MemFn memfn)
51 0 : : obj_(obj), memfn_(memfn)
52 : {
53 0 : }
54 :
55 : template<class... Args>
56 0 : auto operator()(Args&&... args) const
57 : -> detail::result_of_t<MemFn(T*, Args&&...)>
58 : {
59 0 : return (obj_->*memfn_)(std::forward<Args>(args)...);
60 : }
61 : };
62 :
63 : template<class MemFn, class T>
64 0 : inline call_mf_impl<T, MemFn> call_mf(MemFn memfn, T* obj)
65 : {
66 0 : return call_mf_impl<T, MemFn>(obj, memfn);
67 : }
68 :
69 : } // beast2
70 : } // boost
71 :
72 : #endif
|