source: mainline/uspace/lib/cpp/include/__bits/functional/invoke.hpp@ c6f23a7

Last change on this file since c6f23a7 was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef LIBCPP_BITS_FUNCTIONAL_INVOKE
8#define LIBCPP_BITS_FUNCTIONAL_INVOKE
9
10#include <__bits/utility/declval.hpp>
11#include <__bits/utility/forward_move.hpp>
12
13namespace std
14{
15 template<class>
16 struct is_member_function_pointer;
17
18 template<class, class>
19 struct is_base_of;
20
21 template<class>
22 struct is_member_object_pointer;
23}
24
25namespace std::aux
26{
27 /**
28 * 20.9.2, requirements:
29 */
30
31 template<class R, class T, class T1, class... Ts>
32 decltype(auto) INVOKE(R T::* f, T1&& t1, Ts&&... args)
33 {
34 if constexpr (is_member_function_pointer<decltype(f)>::value)
35 {
36 if constexpr (is_base_of<T, remove_reference_t<T1>>::value)
37 // (1.1)
38 return (t1.*f)(forward<Ts>(args)...);
39 else
40 // (1.2)
41 return ((*t1).*f)(forward<Ts>(args)...);
42 }
43 else if constexpr (is_member_object_pointer<decltype(f)>::value && sizeof...(args) == 0)
44 {
45 /**
46 * Note: Standard requires to N be equal to 1, but we take t1 directly
47 * so we need sizeof...(args) to be 0.
48 */
49 if constexpr (is_base_of<T, remove_reference_t<T1>>::value)
50 // (1.3)
51 return t1.*f;
52 else
53 // (1.4)
54 return (*t1).*f;
55 }
56 else
57
58 /**
59 * Note: If this condition holds this will not be reachable,
60 * but a new addition to the standard (17.7 point (8.1))
61 * prohibits us from simply using false as the condition here,
62 * so we use this because we know it is false here.
63 */
64 static_assert(is_member_function_pointer<decltype(f)>::value, "invalid invoke");
65 }
66
67 template<class F, class... Args>
68 decltype(auto) INVOKE(F&& f, Args&&... args)
69 {
70 // (1.5)
71 return f(forward<Args>(args)...);
72 }
73}
74
75#endif
Note: See TracBrowser for help on using the repository browser.