forked from intel/cpp-std-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallable.cpp
More file actions
54 lines (47 loc) · 1.79 KB
/
callable.cpp
File metadata and controls
54 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdx/type_traits.hpp>
#include <catch2/catch_test_macros.hpp>
#include <type_traits>
namespace {
[[maybe_unused]] auto func_no_args() {}
[[maybe_unused]] auto func_one_arg(int) {}
struct S {
auto operator()() {}
};
struct T {
template <typename> auto operator()() {}
};
} // namespace
TEST_CASE("is_function", "[type_traits]") {
auto x = []() {};
STATIC_REQUIRE(not stdx::is_function_v<int>);
STATIC_REQUIRE(not stdx::is_function_v<int &>);
STATIC_REQUIRE(not stdx::is_function_v<decltype(x)>);
STATIC_REQUIRE(stdx::is_function_v<decltype(func_no_args)>);
STATIC_REQUIRE(stdx::is_function_v<decltype(func_one_arg)>);
}
TEST_CASE("is_function_object", "[type_traits]") {
auto x = []() {};
auto y = [](int) {};
auto z = [](auto) {};
STATIC_REQUIRE(not stdx::is_function_object_v<int>);
STATIC_REQUIRE(not stdx::is_function_object_v<decltype(func_no_args)>);
STATIC_REQUIRE(not stdx::is_function_object_v<decltype(func_one_arg)>);
STATIC_REQUIRE(stdx::is_function_object_v<decltype(x)>);
STATIC_REQUIRE(stdx::is_function_object_v<decltype(y)>);
STATIC_REQUIRE(stdx::is_function_object_v<decltype(z)>);
STATIC_REQUIRE(stdx::is_function_object_v<S>);
STATIC_REQUIRE(stdx::is_function_object_v<T>);
}
TEST_CASE("is_callable", "[type_traits]") {
auto x = []() {};
auto y = [](int) {};
auto z = [](auto) {};
STATIC_REQUIRE(not stdx::is_callable_v<int>);
STATIC_REQUIRE(stdx::is_callable_v<decltype(func_no_args)>);
STATIC_REQUIRE(stdx::is_callable_v<decltype(func_one_arg)>);
STATIC_REQUIRE(stdx::is_callable_v<decltype(x)>);
STATIC_REQUIRE(stdx::is_callable_v<decltype(y)>);
STATIC_REQUIRE(stdx::is_callable_v<decltype(z)>);
STATIC_REQUIRE(stdx::is_callable_v<S>);
STATIC_REQUIRE(stdx::is_callable_v<T>);
}