based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

callable_test.cpp (1437B)


0 // #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/concepts/callable.hpp"
4 #include <catch2/catch_test_macros.hpp>
6 #include "based/concepts/is/same.hpp"
8 namespace
9 {
11 // NOLINTNEXTLINE(*need*)
12 int free_func(int a, double b)
13 {
14 return static_cast<int>(a + b);
15 }
17 } // namespace
19 using based::SameAs;
21 TEST_CASE("free function", "[trait/callable]")
22 {
23 using type_t = decltype(free_func);
25 STATIC_REQUIRE(based::Callable<type_t>);
26 STATIC_REQUIRE(SameAs<based::callable_sig_t<type_t>, int(int, double)>);
27 STATIC_REQUIRE(SameAs<based::callable_ret_t<type_t>, int>);
28 }
30 TEST_CASE("lambda", "[trait/callable]")
31 {
32 const auto func = [](int a, double b)
33 {
34 return static_cast<int>(a + b);
35 };
36 using type_t = decltype(func);
38 STATIC_REQUIRE(based::Callable<type_t>);
39 STATIC_REQUIRE(SameAs<based::callable_sig_t<type_t>, int(int, double)>);
40 STATIC_REQUIRE(SameAs<based::callable_ret_t<type_t>, int>);
41 }
43 /*
44 struct func
45 {
46 auto operator()(auto a, auto b) { return static_cast<int>(a + b); }
47 };
49 TEST_CASE("member function", "[trait/callable]")
50 {
51 // [&](auto&&... args) -> decltype(auto) { return
52 // f(based::forward<decltype(args)>(args)...); }
54 // based::error_template<decltype(&func::template operator()<int, double>)>();
55 STATIC_REQUIRE(based::Callable<func>);
56 STATIC_REQUIRE(SameAs<based::callable_sig_t<func>, int(int, double)>);
57 STATIC_REQUIRE(SameAs<based::callable_ret_t<func>, int>);
58 }
59 */