diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/hof/test/construct.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/hof/test/construct.cpp')
-rw-r--r-- | src/boost/libs/hof/test/construct.cpp | 222 |
1 files changed, 222 insertions, 0 deletions
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 <boost/hof/construct.hpp> +#include "test.hpp" + +#include <boost/hof/first_of.hpp> +#include <boost/hof/proj.hpp> +#include <boost/hof/placeholders.hpp> + +#include <tuple> +#include <type_traits> +#include <vector> + +template<class T> +struct ac +{ + T value; + constexpr ac(T i) : value(i) + {} +}; + +template<class... Ts> +struct tuple_meta +{ + typedef std::tuple<Ts...> type; +}; + +struct tuple_meta_class +{ + template<class... Ts> + struct apply + { + typedef std::tuple<Ts...> 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<class T> +struct template_user_construct +{ + int mem1; + std::string mem2; + template_user_construct(T) { } +}; + + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct<std::vector<int>>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector<int>{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct_basic<std::vector<int>>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector<int>{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct_forward<std::vector<int>>()(5, 5); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector<int>{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct<implicit_default>()(); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct<user_default>()(); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct<user_construct>()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct<template_user_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<template_user_construct>()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct_basic<template_user_construct>()(3); + BOOST_HOF_TEST_CHECK(x.mem1 == 0); + BOOST_HOF_TEST_CHECK(x.mem2 == ""); +} + +BOOST_HOF_TEST_CASE() +{ + auto v = boost::hof::construct<std::vector<int>>()({5, 5, 5, 5, 5}); + BOOST_HOF_TEST_CHECK(v.size() == 5); + BOOST_HOF_TEST_CHECK(v == std::vector<int>{5, 5, 5, 5, 5}); +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct<std::tuple>()(1, 2, 3); + static_assert(std::is_same<std::tuple<int, int, int>, 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<std::tuple>()(1, 2, 3)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct<std::pair>()(1, 2); + static_assert(std::is_same<std::pair<int, int>, 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<std::pair>()(1, 2)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto f = boost::hof::first_of(boost::hof::construct<std::pair>(), 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<ac>()(1); + static_assert(std::is_same<ac<int>, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(x.value == ac<int>(1).value); + BOOST_HOF_STATIC_TEST_CHECK(ac<int>(1).value == boost::hof::construct<ac>()(1).value); +} + +BOOST_HOF_TEST_CASE() +{ + auto x = boost::hof::construct_basic<ac>()(1); + static_assert(std::is_same<ac<int>, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(x.value == ac<int>(1).value); + BOOST_HOF_STATIC_TEST_CHECK(ac<int>(1).value == boost::hof::construct<ac>()(1).value); +} + +BOOST_HOF_TEST_CASE() +{ + int i = 1; + auto x = boost::hof::construct_forward<ac>()(i); + static_assert(std::is_same<ac<int&>, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(&x.value == &i); +} + +BOOST_HOF_TEST_CASE() +{ + int i = 1; + auto x = boost::hof::construct_basic<ac>()(i); + static_assert(std::is_same<ac<int&>, decltype(x)>::value, ""); + BOOST_HOF_TEST_CHECK(&x.value == &i); +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct_meta<tuple_meta>()(1, 2, 3); + static_assert(std::is_same<std::tuple<int, int, int>, 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<tuple_meta>()(1, 2, 3)); +#endif +} + +BOOST_HOF_TEST_CASE() +{ + auto t = boost::hof::construct_meta<tuple_meta_class>()(1, 2, 3); + static_assert(std::is_same<std::tuple<int, int, int>, 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<tuple_meta_class>()(1, 2, 3)); +#endif +} + |