diff --git a/bin/main.cpp b/bin/main.cpp index 9750852..0148e7f 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -23,6 +23,16 @@ int f(int a) return ++a; } +int plus(int a) +{ + return a++; +} + +int minus(int a) +{ + return a--; +} + int main(int argc, char *argv[]) { {// ex: string::split_str @@ -155,4 +165,9 @@ int main(int argc, char *argv[]) hack::log()(full_name); hack::log()(hack::string::str_concat + "super", + "string"); } + + {// ex: utils::func_concat + auto combine ( hack::utils::func_concat(plus, minus) ); + hack::log("")("func_concat result: ", combine(3)); + } } diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 86afe66..6b1cfc9 100644 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -24,4 +24,23 @@ namespace hack::utils return cached->second; }; } + + template + auto func_concat(T t, Args... args) + { + if constexpr (sizeof...(args) > 0) + { + return [=](auto... params) + { + return t(func_concat(args...)(params...)); + }; + } + else + { + return [=](auto... params) + { + return t(params...); + }; + } + } } diff --git a/tests/math.cpp b/tests/math.cpp new file mode 100644 index 0000000..9019c01 --- /dev/null +++ b/tests/math.cpp @@ -0,0 +1,11 @@ +#include + +#include "math/matrix.hpp" + +TEST(matrix, check) +{ + hack::matrix m { { 0, 0, 1 }, { 0, 1, 1 } }; + m[1][1] = 123; + + ASSERT_EQ(m.size(), 3); +} diff --git a/tests/meson.build b/tests/meson.build index 250798e..1449657 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -27,3 +27,12 @@ test( dependencies: [ deps, gtest_dep ] ) ) + +test( + 'math', + executable( + 'math', + 'math.cpp', + dependencies: [ deps, gtest_dep ] + ) +)