From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/hof/test/repeat_while.cpp | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/boost/libs/hof/test/repeat_while.cpp (limited to 'src/boost/libs/hof/test/repeat_while.cpp') diff --git a/src/boost/libs/hof/test/repeat_while.cpp b/src/boost/libs/hof/test/repeat_while.cpp new file mode 100644 index 00000000..3b1d9fc1 --- /dev/null +++ b/src/boost/libs/hof/test/repeat_while.cpp @@ -0,0 +1,95 @@ +/*============================================================================= + Copyright (c) 2017 Paul Fultz II + repeat_while.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 +#include "test.hpp" + +// TODO: Test default construction, and static initialization + +struct increment_constant +{ + template + constexpr std::integral_constant operator()(T) const noexcept + { + return std::integral_constant(); + } +}; + +struct increment +{ + template + constexpr T operator()(T x) const noexcept + { + return x + 1; + } +}; + +struct not_6_constant +{ + template + constexpr std::integral_constant + operator()(T) const noexcept + { + return std::integral_constant(); + } +}; + +struct not_6 +{ + template + constexpr bool operator()(T x) const noexcept + { + return x != 6; + } +}; + +struct not_limit +{ + template + constexpr bool operator()(T x) const + { + return x != (BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4); + } +}; + +#if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION +BOOST_HOF_TEST_CASE() +{ + static_assert(noexcept(boost::hof::repeat_while(not_6())(increment())(1)), "noexcept repeat_while"); + static_assert(noexcept(boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant())), "noexcept repeat_while"); +} +#endif + +BOOST_HOF_TEST_CASE() +{ + static_assert + ( + std::is_same< + std::integral_constant, + decltype(boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant())) + >::value, + "Error" + ); + + std::integral_constant x = boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant()); + boost::hof::test::unused(x); +} + +BOOST_HOF_TEST_CASE() +{ + BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat_while(not_6())(increment())(1) == 6); + BOOST_HOF_TEST_CHECK(boost::hof::repeat_while(not_6())(increment())(1) == 6); + BOOST_HOF_TEST_CHECK(boost::hof::reveal(boost::hof::repeat_while(not_6())(increment()))(1) == 6); +} + +BOOST_HOF_TEST_CASE() +{ + BOOST_HOF_TEST_CHECK(boost::hof::repeat_while(not_limit())(increment())(1) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4); +#if BOOST_HOF_HAS_RELAXED_CONSTEXPR + BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat_while(not_limit())(increment())(1) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4); +#endif +} -- cgit v1.2.3