basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
callable_test.cpp (1409B)
0 // #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE 1 2 #include <catch2/catch_test_macros.hpp> 3 4 #include "based/type_traits.hpp" 5 6 7 namespace 8 { 9 10 // NOLINTNEXTLINE(*need*) 11 int free_func(int a, double b) 12 { 13 return static_cast<int>(a + b); 14 } 15 16 } // namespace 17 18 using based::SameAs; 19 20 TEST_CASE("free function", "[type_traits/callable]") 21 { 22 using type_t = decltype(free_func); 23 24 STATIC_REQUIRE(based::Callable<type_t>); 25 STATIC_REQUIRE(SameAs<based::callable_sig_t<type_t>, int(int, double)>); 26 STATIC_REQUIRE(SameAs<based::callable_ret_t<type_t>, int>); 27 } 28 29 TEST_CASE("lambda", "[type_traits/callable]") 30 { 31 const auto func = [](int a, double b) 32 { 33 return static_cast<int>(a + b); 34 }; 35 using type_t = decltype(func); 36 37 STATIC_REQUIRE(based::Callable<type_t>); 38 STATIC_REQUIRE(SameAs<based::callable_sig_t<type_t>, int(int, double)>); 39 STATIC_REQUIRE(SameAs<based::callable_ret_t<type_t>, int>); 40 } 41 42 /* 43 struct func 44 { 45 auto operator()(auto a, auto b) { return static_cast<int>(a + b); } 46 }; 47 48 TEST_CASE("member function", "[type_traits/callable]") 49 { 50 // [&](auto&&... args) -> decltype(auto) { return 51 // f(std::forward<decltype(args)>(args)...); } 52 53 // based::error_template<decltype(&func::template operator()<int, double>)>(); 54 STATIC_REQUIRE(based::Callable<func>); 55 STATIC_REQUIRE(SameAs<based::callable_sig_t<func>, int(int, double)>); 56 STATIC_REQUIRE(SameAs<based::callable_ret_t<func>, int>); 57 } 58 */