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 (706B)
0 #include "based/functional/function.hpp"
2 #include <catch2/catch_test_macros.hpp>
4 namespace
5 {
7 int identity(int a)
8 {
9 return a;
10 }
12 } // namespace
14 template class based::function<decltype(identity)>;
16 TEST_CASE("empty", "[template/function]")
17 {
18 const based::function<void()> func;
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 }
30 TEST_CASE("free function", "[template/function]")
31 {
32 const based::function func = identity;
34 REQUIRE(func(3) == 3);
35 }
37 TEST_CASE("lambda function", "[template/function]")
38 {
39 const based::function func = [](int a)
40 {
41 return a;
42 };
44 REQUIRE(func(3) == 3);
45 }