1 /*
2 Copyright 2020-2022 René Ferdinand Rivera Morell
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include <lyra/detail/trait_utils.hpp>
9 #include "mini_test.hpp"
10 #include <string>
11
12 template <typename L>
is_invocable_v(L,typename std::enable_if<lyra::detail::is_invocable<L>::value,int>::type=0)13 constexpr bool is_invocable_v(
14 L,
15 typename std::enable_if<lyra::detail::is_invocable<L>::value, int>::type = 0)
16 {
17 return true;
18 }
19
20 template <typename T>
is_invocable_v(T,typename std::enable_if<!lyra::detail::is_invocable<T>::value,char>::type=0)21 constexpr bool is_invocable_v(
22 T,
23 typename std::enable_if<!lyra::detail::is_invocable<T>::value, char>::type = 0)
24 {
25 return false;
26 }
27
main()28 int main()
29 {
30 using namespace lyra;
31 bfg::mini_test::scope test;
32
33 {
34 test
35 (REQUIRE(
36 (!lyra::detail::is_callable<int, int>::value)
37 ))
38 (REQUIRE(
39 (!lyra::detail::is_callable<float, int, int>::value)
40 ))
41 (REQUIRE(
42 (!lyra::detail::is_callable<std::string, int>::value)
43 ))
44 ;
45 }
46 {
47 auto f0 = []() -> bool { return false; };
48 auto f1 = [](int x) -> bool { return x > 1; };
49 auto f2 = [](int x, float y) -> bool { return x > y; };
50 test
51 (REQUIRE(
52 (lyra::detail::is_callable<decltype(f0)>::value)
53 ))
54 (REQUIRE(
55 (lyra::detail::is_callable<decltype(f1), int>::value)
56 ))
57 (REQUIRE(
58 (lyra::detail::is_callable<decltype(f2), int, int>::value)
59 ))
60 ;
61 }
62
63 {
64 test
65 (REQUIRE(
66 (!lyra::detail::is_invocable<int>::value)
67 ))
68 (REQUIRE(
69 (!lyra::detail::is_invocable<float>::value)
70 ))
71 (REQUIRE(
72 (!lyra::detail::is_invocable<std::string>::value)
73 ))
74 ;
75 }
76 {
77 auto f0 = []() -> bool { return false; };
78 auto f1 = [](int x) -> bool { return x > 1; };
79 auto f2 = [](int x, float y) -> bool { return x > y; };
80 test
81 (REQUIRE(
82 (lyra::detail::is_invocable<decltype(f0)>::value)
83 ))
84 (REQUIRE(
85 (lyra::detail::is_invocable<decltype(f1)>::value)
86 ))
87 (REQUIRE(
88 (lyra::detail::is_invocable<decltype(f2)>::value)
89 ))
90 ;
91 }
92 {
93 test
94 (REQUIRE(
95 is_invocable_v([]() -> bool { return false; })
96 ))
97 (REQUIRE(
98 is_invocable_v([](int x) -> bool { return x > 1; })
99 ))
100 (REQUIRE(
101 is_invocable_v([](int x, float y) -> bool { return x > y; })
102 ))
103 ;
104 }
105
106 return test;
107 }
108