File tree 2 files changed +11
-7
lines changed
src/__support/CPP/type_traits 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 10
10
#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
11
11
12
12
#include " src/__support/CPP/type_traits/decay.h"
13
+ #include " src/__support/CPP/type_traits/enable_if.h"
13
14
#include " src/__support/CPP/type_traits/is_base_of.h"
15
+ #include " src/__support/CPP/type_traits/is_same.h"
14
16
#include " src/__support/CPP/utility/forward.h"
15
17
16
- // BEWARE : this implementation is not fully conformant as it doesn't take
17
- // `cpp::reference_wrapper` into account.
18
-
19
18
namespace __llvm_libc ::cpp {
20
19
21
20
namespace detail {
22
21
23
- // Catch all function types.
22
+ // Catch all function and functor types.
24
23
template <class FunctionPtrType > struct invoke_dispatcher {
25
- template <class ... Args>
26
- static auto call (FunctionPtrType &&fun, Args &&...args) {
27
- return cpp::forward<FunctionPtrType>(fun)(cpp::forward<Args>(args)...);
24
+ template <class T , class ... Args,
25
+ typename = cpp::enable_if_t <
26
+ cpp::is_same_v<cpp::decay_t <T>, FunctionPtrType>>>
27
+ static auto call (T &&fun, Args &&...args) {
28
+ return cpp::forward<T>(fun)(cpp::forward<Args>(args)...);
28
29
}
29
30
};
30
31
Original file line number Diff line number Diff line change @@ -196,6 +196,9 @@ TEST(LlvmLibcTypeTraitsTest, invoke) {
196
196
{ // lambda
197
197
EXPECT_EQ (cpp::invoke ([]() -> int { return 2 ; }), 2 );
198
198
EXPECT_EQ (cpp::invoke ([](int value) -> int { return value; }, 1 ), 1 );
199
+
200
+ const auto lambda = [](int ) { return 0 ; };
201
+ EXPECT_EQ (cpp::invoke (lambda, 1 ), 0 );
199
202
}
200
203
}
201
204
You can’t perform that action at this time.
0 commit comments