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 (1482B)


0 // #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
2 #include "based/concept/callable.hpp"
4 #include <catch2/catch_test_macros.hpp>
6 #include "based/concept/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::trait::IsSame;
21 TEST_CASE("free function", "[concept/IsCallable]")
22 {
23 using TypeT = decltype(free_func);
25 STATIC_REQUIRE(based::trait::IsCallable<TypeT>);
26 STATIC_REQUIRE(IsSame<based::trait::CallableSigT<TypeT>, int(int, double)>);
27 STATIC_REQUIRE(IsSame<based::trait::CallableRetT<TypeT>, int>);
28 }
30 TEST_CASE("lambda", "[concept/IsCallable]")
31 {
32 const auto func = [](int a, double b)
33 {
34 return static_cast<int>(a + b);
35 };
36 using TypeT = decltype(func);
38 STATIC_REQUIRE(based::trait::IsCallable<TypeT>);
39 STATIC_REQUIRE(IsSame<based::trait::CallableSigT<TypeT>, int(int, double)>);
40 STATIC_REQUIRE(IsSame<based::trait::CallableRetT<TypeT>, int>);
41 }
43 struct Func
44 {
45 auto operator()(auto a, auto b) { return static_cast<int>(a + b); }
46 };
48 /*
49 TEST_CASE("member function", "[concept/IsCallable]")
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::IsCallable<Func>);
56 STATIC_REQUIRE(IsSame<based::CallableSigT<Func>, int(int, double)>);
57 STATIC_REQUIRE(IsSame<based::CallableRetT<Func>, int>);
58 }
59 */