From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/hof/test/construct.cpp | 222 ++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 src/boost/libs/hof/test/construct.cpp (limited to 'src/boost/libs/hof/test/construct.cpp') diff --git a/src/boost/libs/hof/test/construct.cpp b/src/boost/libs/hof/test/construct.cpp new file mode 100644 index 000000000..953f0f6c3 --- /dev/null +++ b/src/boost/libs/hof/test/construct.cpp @@ -0,0 +1,222 @@ +/*============================================================================= + Copyright (c) 2017 Paul Fultz II + construct.cpp + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#include +#include "test.hpp" + +#include +#include +#include + +#include +#include +#include + +template +struct ac +{ + T value; + constexpr ac(T i) : value(i) + {} +}; + +template +struct tuple_meta +{ + typedef std::tuple type; +}; + +struct tuple_meta_class +{ + template + struct apply + { + typedef std::tuple type; + }; +}; + +struct implicit_default +{ + int mem1; + std::string mem2; +}; + +struct user_default +{ + int mem1; + std::string mem2; + user_default() { } +}; + +struct user_construct +{ + int mem1; + std::string mem2; + user_construct(int) { } +}; + +template +struct template_user_construct +{ + int mem1; + std::string mem2; + template_user_construct(T) { } +}; + + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct_basic>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct_forward>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct()(); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct()(); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct_forward()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct_basic()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct>()({5, 5, 5, 5, 5}); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct()(1, 2, 3); + static_assert(std::is_same, decltype(t)>::value, ""); + BOOST_HOF_TEST_CHECK(t == std::make_tuple(1, 2, 3)); +// GCC 4.7 doesn't have fully constexpr tuple +#if BOOST_HOF_HAS_CONSTEXPR_TUPLE + BOOST_HOF_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == boost::hof::construct()(1, 2, 3)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct()(1, 2); + static_assert(std::is_same, decltype(t)>::value, ""); + BOOST_HOF_TEST_CHECK(t == std::make_pair(1, 2)); +// GCC 4.7 doesn't have fully constexpr pair +#if BOOST_HOF_HAS_CONSTEXPR_TUPLE + BOOST_HOF_STATIC_TEST_CHECK(std::make_pair(1, 2) == boost::hof::construct()(1, 2)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto f = boost::hof::first_of(boost::hof::construct(), boost::hof::identity); + BOOST_HOF_TEST_CHECK(f(1, 2) == std::make_pair(1, 2)); + BOOST_HOF_TEST_CHECK(f(1) == 1); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct()(1); + static_assert(std::is_same, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(x.value == ac(1).value); + BOOST_HOF_STATIC_TEST_CHECK(ac(1).value == boost::hof::construct()(1).value); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct_basic()(1); + static_assert(std::is_same, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(x.value == ac(1).value); + BOOST_HOF_STATIC_TEST_CHECK(ac(1).value == boost::hof::construct()(1).value); +} + +BOOST_HOF_TEST_CASE() +{ + int i = 1; + auto x = boost::hof::construct_forward()(i); + static_assert(std::is_same, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(&x.value == &i); +} + +BOOST_HOF_TEST_CASE() +{ + int i = 1; + auto x = boost::hof::construct_basic()(i); + static_assert(std::is_same, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(&x.value == &i); +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct_meta()(1, 2, 3); + static_assert(std::is_same, decltype(t)>::value, ""); + BOOST_HOF_TEST_CHECK(t == std::make_tuple(1, 2, 3)); +// GCC 4.7 doesn't have fully constexpr tuple +#if BOOST_HOF_HAS_CONSTEXPR_TUPLE + BOOST_HOF_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == boost::hof::construct_meta()(1, 2, 3)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct_meta()(1, 2, 3); + static_assert(std::is_same, decltype(t)>::value, ""); + BOOST_HOF_TEST_CHECK(t == std::make_tuple(1, 2, 3)); +// GCC 4.7 doesn't have fully constexpr tuple +#if BOOST_HOF_HAS_CONSTEXPR_TUPLE + BOOST_HOF_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == boost::hof::construct_meta()(1, 2, 3)); +#endif +} + -- cgit v1.2.3