diff --git a/include/nmtools/utl/array.hpp b/include/nmtools/utl/array.hpp index b9bc05b97..225ea2f54 100644 --- a/include/nmtools/utl/array.hpp +++ b/include/nmtools/utl/array.hpp @@ -56,6 +56,18 @@ namespace nmtools::utl return (size_type)N; } + // The following is intended to enable copy assignment of maybe type in constexpr function/lambda + // but then it deprecates the definition of implicit copy constructor + #if 0 + constexpr array& operator=(const array& other) noexcept + { + for (size_t i=0; i(*this); } + constexpr Derived& operator=(const Derived& other) noexcept + { + if (other.self().tag == Derived::LEFT) { + self().left = other.self().left; + self().tag = Derived::LEFT; + return self(); + } else { + self().right = other.self().right; + self().tag = Derived::RIGHT; + return self(); + } + } + template constexpr Derived& operator=(const T& val) noexcept { using left_type = typename Derived::left_type; using right_type = typename Derived::right_type; - static_assert( meta::is_same_v || meta::is_same_v + static_assert( meta::is_same_v || meta::is_same_v || meta::is_same_v , "unsupported type for either assignment" ); if constexpr (meta::is_same_v) { self().left = val; self().tag = Derived::LEFT; return self(); - } else { + } else if constexpr (meta::is_same_v) { self().right = val; - self().tag = Derived::RIGHT; + self().tag = Derived::RIGHT; return self(); + } else { + return operator=(static_cast(val)); } } @@ -156,6 +171,11 @@ namespace nmtools::utl base::operator=(val); return *this; } + + constexpr either& operator=(const either& other) noexcept + { + return base::operator=(other); + } }; // TODO: find out if we can move the constructor to base for better composition & brevity @@ -182,6 +202,8 @@ namespace nmtools::utl friend struct impl::get_if_t; friend base; public: + using left_type = left_t; + using right_type = right_t; constexpr either() noexcept : left{}, tag{LEFT} {} @@ -221,8 +243,12 @@ namespace nmtools::utl template constexpr either& operator=(const U& val) noexcept { - base::operator=(val); - return *this; + return base::operator=(val); + } + + constexpr either& operator=(const either& other) noexcept + { + return base::operator=(other); } }; // either @@ -249,6 +275,8 @@ namespace nmtools::utl friend struct impl::get_if_t; friend base; public: + using left_type = left_t; + using right_type = right_t; constexpr either() noexcept : left{}, tag{LEFT} {} @@ -279,8 +307,12 @@ namespace nmtools::utl template constexpr either& operator=(const U& val) noexcept { - base::operator=(val); - return *this; + return base::operator=(val); + } + + constexpr either& operator=(const either& other) noexcept + { + return base::operator=(other); } }; // either #endif diff --git a/include/nmtools/utl/maybe.hpp b/include/nmtools/utl/maybe.hpp index 6ea7a9629..036981090 100644 --- a/include/nmtools/utl/maybe.hpp +++ b/include/nmtools/utl/maybe.hpp @@ -40,6 +40,8 @@ namespace nmtools::utl // assume copy-constructible constexpr maybe(const T& t) : base(t) {} + constexpr maybe(const maybe& other) : base(other) {} + constexpr bool has_value() const noexcept { return this->tag == base::LEFT; @@ -56,6 +58,18 @@ namespace nmtools::utl return *this; } + /*constexpr*/ maybe& operator=(const maybe& other) + { + if (other.has_value()) { + this->left = other.left; + this->tag = base::LEFT; + } else { + this->right = other.right; + this->tag = base::RIGHT; + } + return *this; + } + constexpr explicit operator bool() const noexcept { return has_value(); @@ -135,6 +149,18 @@ namespace nmtools::utl return *this; } + /*constexpr*/ maybe& operator=(const maybe& other) + { + if (other.has_value()) { + this->left = other.left; + this->tag = base::LEFT; + } else { + this->right = other.right; + this->tag = base::RIGHT; + } + return *this; + } + constexpr explicit operator bool() const noexcept { return has_value(); diff --git a/include/nmtools/utl/vector.hpp b/include/nmtools/utl/vector.hpp index 29b2569f8..95086c51c 100644 --- a/include/nmtools/utl/vector.hpp +++ b/include/nmtools/utl/vector.hpp @@ -133,12 +133,25 @@ namespace nmtools::utl public: - vector() {} + vector() + : buffer_(NULL) + , size_(0) + , buffer_size_(0) + , allocator{} + {} vector(size_type N) + : buffer_(NULL) + , size_(0) + , buffer_size_(0) + , allocator{} { resize(N); } vector(const vector& other) + : buffer_(NULL) + , size_(0) + , buffer_size_(0) + , allocator{} { resize(other.size_); // dumb copy @@ -154,6 +167,10 @@ namespace nmtools::utl // TODO: fix initialization template vector(const A& t, const B& u, const Ts&...ts) + : buffer_(NULL) + , size_(0) + , buffer_size_(0) + , allocator{} { constexpr auto n = sizeof...(Ts) + 2; resize(n); diff --git a/tests/utl/utl/src/array.cpp b/tests/utl/utl/src/array.cpp index 386a85b5a..7d6f62c8e 100644 --- a/tests/utl/utl/src/array.cpp +++ b/tests/utl/utl/src/array.cpp @@ -8,6 +8,22 @@ namespace nm = nmtools; namespace utl = nm::utl; +TEST_CASE("array" * doctest::test_suite("utl")) +{ + { + using array_t = utl::array; + static_assert( meta::is_trivially_constructible_v ); + static_assert( meta::is_trivially_copy_constructible_v ); + static_assert( meta::is_default_constructible_v ); + static_assert( meta::is_copy_constructible_v ); + static_assert( meta::is_trivially_destructible_v ); + static_assert( meta::is_copy_assignable_v ); + static_assert( sizeof(array_t) == sizeof(int)*3 ); + // static_assert( meta::is_constructible_v ); + // static_assert( std::is_constructible_v ); + } +} + TEST_CASE("array" * doctest::test_suite("utl")) { SUBCASE("constructor") @@ -93,4 +109,330 @@ TEST_CASE("array" * doctest::test_suite("utl")) NMTOOLS_ASSERT_EQUAL( nm::len(array), 3 ); } } + + SUBCASE("copy") + { + { + using array_t = utl::array; + auto array = array_t{1,2,3}; + auto copied = array; + NMTOOLS_ASSERT_EQUAL( copied.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( copied[0], 1 ); + NMTOOLS_ASSERT_EQUAL( copied[1], 2 ); + NMTOOLS_ASSERT_EQUAL( copied[2], 3 ); + } + } + + SUBCASE("copy assignment") + { + { + using array_t = utl::array; + auto array = array_t{3,4,5}; + auto copied = array_t(); + copied = array; + NMTOOLS_ASSERT_EQUAL( copied.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( copied[0], 3 ); + NMTOOLS_ASSERT_EQUAL( copied[1], 4 ); + NMTOOLS_ASSERT_EQUAL( copied[2], 5 ); + } + } + + SUBCASE("return") + { + { + auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + return array; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_ASSERT_EQUAL( array[2], 3 ); + } + { + auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + auto copied = array; + return copied; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_ASSERT_EQUAL( array[2], 3 ); + } + { + auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + auto copied = array_t(); + copied = array; + return copied; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_ASSERT_EQUAL( array[2], 3 ); + } + } +} + +TEST_CASE("constexpr_array" * doctest::test_suite("utl")) +{ + SUBCASE("constructor") + { + { + using array_t = utl::array; + constexpr auto array = array_t{1,2,3}; + NMTOOLS_STATIC_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[2], 3 ); + } + { + constexpr auto array = utl::array{3,4,5}; + NMTOOLS_STATIC_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[0], 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[1], 4 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[2], 5 ); + } + } + + SUBCASE("copy") + { + { + using array_t = utl::array; + constexpr auto array = array_t{1,2,3}; + constexpr auto copied = array; + NMTOOLS_STATIC_ASSERT_EQUAL( copied.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( copied[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( copied[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( copied[2], 3 ); + } + } + + SUBCASE("return") + { + { + constexpr auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + return array; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[2], 3 ); + } + { + constexpr auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + auto copied = array; + return copied; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[2], 3 ); + } + { + constexpr auto f = [](){ + using array_t = utl::array; + auto array = array_t(); + array[0] = 1; + array[1] = 2; + array[2] = 3; + auto copied = array_t(); + copied = array; + return copied; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( array[2], 3 ); + } + } +} + +TEST_CASE("maybe_array" * doctest::test_suite("utl")) +{ + SUBCASE("constructor") + { + { + using array_t = nmtools_maybe>; + auto array = array_t{{1,2,3}}; + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*array)[2], 3 ); + } + } + + SUBCASE("copy") + { + { + using array_t = nmtools_maybe>; + auto array = array_t{{1,2,3}}; + auto copied = array; + NMTOOLS_ASSERT_EQUAL( (*copied).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[2], 3 ); + } + } + + SUBCASE("copy assignment") + { + { + using array_t = nmtools_maybe>; + auto array = array_t{{3,4,5}}; + auto copied = array_t(meta::Nothing); + copied = array; + NMTOOLS_ASSERT_EQUAL( (*copied).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[0], 3 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[1], 4 ); + NMTOOLS_ASSERT_EQUAL( (*copied)[2], 5 ); + } + } + + SUBCASE("return") + { + { + auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + return array; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*array)[2], 3 ); + } + { + auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + auto copied = array; + return copied; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*array)[2], 3 ); + } + { + auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + auto copied = array_t(); + copied = array; + return copied; + }; + auto array = f(); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*array)[2], 3 ); + } + } +} + +TEST_CASE("constexpr_maybe_array" * doctest::test_suite("utl")) +{ + SUBCASE("constructor") + { + { + using array_t = nmtools_maybe>; + constexpr auto array = array_t{{1,2,3}}; + NMTOOLS_STATIC_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[2], 3 ); + } + } + + SUBCASE("copy") + { + { + using array_t = nmtools_maybe>; + constexpr auto array = array_t{{1,2,3}}; + constexpr auto copied = array; + NMTOOLS_STATIC_ASSERT_EQUAL( (*copied).size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*copied)[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*copied)[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*copied)[2], 3 ); + } + } + + SUBCASE("return") + { + { + constexpr auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + return array; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[2], 3 ); + } + { + constexpr auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + auto copied = array; + return copied; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[2], 3 ); + } + // error: constexpr variable 'array' must be initialized by a constant expression + // note: non-constexpr function 'operator=' cannot be used in a constant expression + #if 0 + { + constexpr auto f = [](){ + using array_t = nmtools_maybe>; + auto array = array_t({1,2,3}); + auto copied = array_t(); + copied = array; + return copied; + }; + constexpr auto array = f(); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array).size(), 3 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_STATIC_ASSERT_EQUAL( (*array)[2], 3 ); + } + #endif + } } \ No newline at end of file diff --git a/tests/utl/utl/src/clipped_integer.cpp b/tests/utl/utl/src/clipped_integer.cpp index 751750021..98bb33a73 100644 --- a/tests/utl/utl/src/clipped_integer.cpp +++ b/tests/utl/utl/src/clipped_integer.cpp @@ -13,14 +13,14 @@ using namespace nm::literals; TEST_CASE("clipped_integer(case1)" * doctest::test_suite("clipped_integer")) { auto i = "2:[3]"_ct; - // static_assert( meta::is_trivially_destructible_v ); - // static_assert( meta::is_trivially_copyable_v ); - static_assert( meta::is_copy_constructible_v ); - // static_assert( meta::is_trivially_copy_constructible_v ); - // static_assert( std::is_trivially_destructible_v ); - // static_assert( std::is_trivially_copyable_v ); - static_assert( std::is_copy_constructible_v ); - // static_assert( std::is_trivially_copy_constructible_v ); + using T = decltype(i); + static_assert( !meta::is_trivially_constructible_v ); + static_assert( !meta::is_trivially_copy_constructible_v ); + static_assert( meta::is_default_constructible_v ); + static_assert( meta::is_copy_constructible_v ); + static_assert( meta::is_trivially_destructible_v ); + static_assert( meta::is_copy_assignable_v ); + static_assert( sizeof(T) == sizeof(nm_size_t) ); } TEST_CASE("array(case1)" * doctest::test_suite("clipped_integer")) diff --git a/tests/utl/utl/src/vector.cpp b/tests/utl/utl/src/vector.cpp index 74cc1cd50..4aebb830f 100644 --- a/tests/utl/utl/src/vector.cpp +++ b/tests/utl/utl/src/vector.cpp @@ -4,6 +4,20 @@ namespace nm = nmtools; namespace utl = nm::utl; +TEST_CASE("vector" * doctest::test_suite("utl")) +{ + { + using array_t = utl::vector; + static_assert( !meta::is_trivially_constructible_v ); + static_assert( !meta::is_trivially_copy_constructible_v ); + static_assert( meta::is_default_constructible_v ); + static_assert( meta::is_copy_constructible_v ); + static_assert( meta::is_copy_assignable_v ); + static_assert( meta::is_constructible_v ); + static_assert( meta::is_constructible_v ); + } +} + TEST_CASE("vector" * doctest::test_suite("utl")) { SUBCASE("constructor") @@ -51,7 +65,7 @@ TEST_CASE("vector" * doctest::test_suite("utl")) } } - SUBCASE("copyable") + SUBCASE("copy") { { using array_t = utl::vector; @@ -68,7 +82,7 @@ TEST_CASE("vector" * doctest::test_suite("utl")) auto array = array_t(3); auto copied = array_t(); copied = array; - NMTOOLS_ASSERT_EQUAL( array.size(), 3 ); + NMTOOLS_ASSERT_EQUAL( copied.size(), 3 ); } } @@ -92,4 +106,168 @@ TEST_CASE("vector" * doctest::test_suite("utl")) NMTOOLS_ASSERT_EQUAL( array[0], 3 ); } } + + SUBCASE("return") + { + { + auto f = [](auto size){ + using array_t = utl::vector; + auto array = array_t(); + array.resize(size); + return array; + }; + auto array = f(3); + NMTOOLS_ASSERT_EQUAL( array.size(), 3 ); + } + { + auto f = [](auto size){ + using array_t = utl::vector; + auto array = array_t(); + array.resize(size); + auto copied = array; + return copied; + }; + auto array = f(4); + NMTOOLS_ASSERT_EQUAL( array.size(), 4 ); + } + { + auto f = [](auto size){ + using array_t = utl::vector; + auto array = array_t(); + array.resize(size); + auto copied = array_t(3); + copied = array; + return copied; + }; + auto array = f(6); + NMTOOLS_ASSERT_EQUAL( array.size(), 6 ); + } + { + auto f = [](auto value1, auto value2){ + using array_t = utl::vector; + auto array = array_t(); + array.push_back(value1); + array.push_back(value2); + return array; + }; + auto array = f(4,5); + NMTOOLS_ASSERT_EQUAL( array.size(), 2 ); + NMTOOLS_ASSERT_EQUAL( array.at(0), 4 ); + NMTOOLS_ASSERT_EQUAL( array.at(1), 5 ); + } + } +} + +TEST_CASE("maybe_vector" * doctest::test_suite("utl")) +{ + SUBCASE("constructor") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(3); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + } + { + using array_t = nmtools_maybe>; + auto array = array_t(); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 0 ); + } + } + SUBCASE("resize") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(); + (*array).resize(3); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + } + { + using array_t = nmtools_maybe>; + auto array = array_t(); + (*array).resize(12); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 12 ); + } + } + SUBCASE("assignment") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(3); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + (*array)[0] = 1; + (*array)[1] = 2; + (*array)[2] = 3; + NMTOOLS_ASSERT_EQUAL( (*array)[0], 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[1], 2 ); + NMTOOLS_ASSERT_EQUAL( (*array)[2], 3 ); + } + } + SUBCASE("copy") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(3); + auto copied = array_t(array); + NMTOOLS_ASSERT_EQUAL( (*copied).size(), 3 ); + } + } + SUBCASE("copy assignment") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(3); + auto copied = array_t(); + copied = *array; + NMTOOLS_ASSERT_EQUAL( (*copied).size(), 3 ); + } + { + using array_t = nmtools_maybe>; + auto array = array_t(3); + auto copied = array_t(); + copied = array; + NMTOOLS_ASSERT_EQUAL( (*copied).size(), 3 ); + } + } + SUBCASE("push_back") + { + { + using array_t = nmtools_maybe>; + auto array = array_t(); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 0 ); + (*array).push_back(3); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 1 ); + NMTOOLS_ASSERT_EQUAL( (*array)[0], 3 ); + } + } + SUBCASE("return") + { + { + auto f = [](auto size){ + using array_t = nmtools_maybe>; + auto array = array_t(); + (*array).resize(size); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + return array; + }; + auto array = f(3); + NMTOOLS_ASSERT_EQUAL( array.has_value(), true ); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 3 ); + } + { + auto f = [](auto value1, auto value2){ + using array_t = nmtools_maybe>; + auto array = array_t(); + (*array).push_back(value1); + (*array).push_back(value2); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 2 ); + NMTOOLS_ASSERT_EQUAL( (*array).at(0), 4 ); + NMTOOLS_ASSERT_EQUAL( (*array).at(1), 5 ); + return array; + }; + auto array = f(4,5); + NMTOOLS_ASSERT_EQUAL( (*array).size(), 2 ); + NMTOOLS_ASSERT_EQUAL( (*array).at(0), 4 ); + NMTOOLS_ASSERT_EQUAL( (*array).at(1), 5 ); + } + } } \ No newline at end of file