basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
function_test.cpp (695B)
0 #include <catch2/catch_test_macros.hpp> 1 2 #include "based/template.hpp" 3 4 namespace 5 { 6 7 int identity(int a) 8 { 9 return a; 10 } 11 12 } // namespace 13 14 template class based::function<decltype(identity)>; 15 16 TEST_CASE("empty", "[template/function]") 17 { 18 const based::function<void()> func; 19 20 try { 21 func(); 22 REQUIRE(false); 23 } catch (const std::bad_function_call& err) { 24 REQUIRE(true); 25 } catch (...) { 26 REQUIRE(false); 27 } 28 } 29 30 TEST_CASE("free function", "[template/function]") 31 { 32 const based::function func = identity; 33 34 REQUIRE(func(3) == 3); 35 } 36 37 TEST_CASE("lambda function", "[template/function]") 38 { 39 const based::function func = [](int a) 40 { 41 return a; 42 }; 43 44 REQUIRE(func(3) == 3); 45 }