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/hana/test/functional/apply.cpp | 262 +++++++++++++++++++++ src/boost/libs/hana/test/functional/capture.cpp | 100 ++++++++ src/boost/libs/hana/test/functional/demux.cpp | 64 +++++ src/boost/libs/hana/test/functional/fix.cpp | 41 ++++ src/boost/libs/hana/test/functional/iterate.cpp | 151 ++++++++++++ src/boost/libs/hana/test/functional/lockstep.cpp | 36 +++ .../hana/test/functional/overload_linearly.cpp | 122 ++++++++++ src/boost/libs/hana/test/functional/partial.cpp | 64 +++++ .../libs/hana/test/functional/placeholder.cpp | 119 ++++++++++ .../libs/hana/test/functional/reverse_partial.cpp | 65 +++++ 10 files changed, 1024 insertions(+) create mode 100644 src/boost/libs/hana/test/functional/apply.cpp create mode 100644 src/boost/libs/hana/test/functional/capture.cpp create mode 100644 src/boost/libs/hana/test/functional/demux.cpp create mode 100644 src/boost/libs/hana/test/functional/fix.cpp create mode 100644 src/boost/libs/hana/test/functional/iterate.cpp create mode 100644 src/boost/libs/hana/test/functional/lockstep.cpp create mode 100644 src/boost/libs/hana/test/functional/overload_linearly.cpp create mode 100644 src/boost/libs/hana/test/functional/partial.cpp create mode 100644 src/boost/libs/hana/test/functional/placeholder.cpp create mode 100644 src/boost/libs/hana/test/functional/reverse_partial.cpp (limited to 'src/boost/libs/hana/test/functional') diff --git a/src/boost/libs/hana/test/functional/apply.cpp b/src/boost/libs/hana/test/functional/apply.cpp new file mode 100644 index 000000000..ff1c81cf9 --- /dev/null +++ b/src/boost/libs/hana/test/functional/apply.cpp @@ -0,0 +1,262 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +#include + +#include +#include +namespace hana = boost::hana; + + +template +struct nonpod : Tracked { + nonpod() : Tracked{i} { } +}; + +struct NonCopyable { + NonCopyable() = default; + NonCopyable(NonCopyable const&) = delete; + NonCopyable& operator=(NonCopyable const&) = delete; +}; + +struct TestClass { + explicit TestClass(int x) : data(x) { } + TestClass(TestClass const&) = delete; + TestClass& operator=(TestClass const&) = delete; + + int& operator()(NonCopyable&&) & { return data; } + int const& operator()(NonCopyable&&) const & { return data; } + int volatile& operator()(NonCopyable&&) volatile & { return data; } + int const volatile& operator()(NonCopyable&&) const volatile & { return data; } + + int&& operator()(NonCopyable&&) && { return std::move(data); } + int const&& operator()(NonCopyable&&) const && { return std::move(data); } + int volatile&& operator()(NonCopyable&&) volatile && { return std::move(data); } + int const volatile&& operator()(NonCopyable&&) const volatile && { return std::move(data); } + + int data; +}; + +struct DerivedFromTestClass : TestClass { + explicit DerivedFromTestClass(int x) : TestClass(x) { } +}; + + +template +void test_b12(Functor&& f) { + // Create the callable object. + using ClassFunc = Signature TestClass::*; + ClassFunc func_ptr = &TestClass::operator(); + + // Create the dummy arg. + NonCopyable arg; + + // Check that the deduced return type of invoke is what is expected. + using DeducedReturnType = decltype( + hana::apply(func_ptr, std::forward(f), std::move(arg)) + ); + static_assert(std::is_same::value, ""); + + // Check that result_of_t matches Expect. + using ResultOfReturnType = typename std::result_of::type; + static_assert(std::is_same::value, ""); + + // Run invoke and check the return value. + DeducedReturnType ret = hana::apply(func_ptr, std::forward(f), std::move(arg)); + BOOST_HANA_RUNTIME_CHECK(ret == 42); +} + +template +void test_b34(Functor&& f) { + // Create the callable object. + using ClassFunc = int TestClass::*; + ClassFunc func_ptr = &TestClass::data; + + // Check that the deduced return type of invoke is what is expected. + using DeducedReturnType = decltype( + hana::apply(func_ptr, std::forward(f)) + ); + static_assert(std::is_same::value, ""); + + // Check that result_of_t matches Expect. + using ResultOfReturnType = typename std::result_of::type; + static_assert(std::is_same::value, ""); + + // Run invoke and check the return value. + DeducedReturnType ret = hana::apply(func_ptr, std::forward(f)); + BOOST_HANA_RUNTIME_CHECK(ret == 42); +} + +template +void test_b5(Functor&& f) { + NonCopyable arg; + + // Check that the deduced return type of invoke is what is expected. + using DeducedReturnType = decltype( + hana::apply(std::forward(f), std::move(arg)) + ); + static_assert(std::is_same::value, ""); + + // Check that result_of_t matches Expect. + using ResultOfReturnType = typename std::result_of::type; + static_assert(std::is_same::value, ""); + + // Run invoke and check the return value. + DeducedReturnType ret = hana::apply(std::forward(f), std::move(arg)); + BOOST_HANA_RUNTIME_CHECK(ret == 42); +} + +int& foo(NonCopyable&&) { + static int data = 42; + return data; +} + +int main() { + // Test normal usage with a function object + { + hana::test::_injection<0> f{}; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::apply(f), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::apply(f, ct_eq<0>{}), + f(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::apply(f, ct_eq<0>{}, ct_eq<1>{}), + f(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::apply(f, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::apply(f, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + // Make sure we can use apply with non-PODs + hana::apply(f, nonpod<>{}); + } + + // Bullets 1 & 2 in the standard + { + TestClass cl(42); + test_b12(cl); + test_b12(cl); + test_b12(cl); + test_b12(cl); + + test_b12(std::move(cl)); + test_b12(std::move(cl)); + test_b12(std::move(cl)); + test_b12(std::move(cl)); + } + { + DerivedFromTestClass cl(42); + test_b12(cl); + test_b12(cl); + test_b12(cl); + test_b12(cl); + + test_b12(std::move(cl)); + test_b12(std::move(cl)); + test_b12(std::move(cl)); + test_b12(std::move(cl)); + } + { + TestClass cl_obj(42); + TestClass *cl = &cl_obj; + test_b12(cl); + test_b12(cl); + test_b12(cl); + test_b12(cl); + } + { + DerivedFromTestClass cl_obj(42); + DerivedFromTestClass *cl = &cl_obj; + test_b12(cl); + test_b12(cl); + test_b12(cl); + test_b12(cl); + } + + // Bullets 3 & 4 in the standard + { + using Fn = TestClass; + Fn cl(42); + test_b34(cl); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + } + { + using Fn = DerivedFromTestClass; + Fn cl(42); + test_b34(cl); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + } + { + using Fn = TestClass; + Fn cl_obj(42); + Fn* cl = &cl_obj; + test_b34(cl); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + } + { + using Fn = DerivedFromTestClass; + Fn cl_obj(42); + Fn* cl = &cl_obj; + test_b34(cl); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + test_b34(static_cast(cl)); + } + + // Bullet 5 in the standard + using FooType = int&(NonCopyable&&); + { + FooType& fn = foo; + test_b5(fn); + } + { + FooType* fn = foo; + test_b5(fn); + } + { + using Fn = TestClass; + Fn cl(42); + test_b5(cl); + test_b5(static_cast(cl)); + test_b5(static_cast(cl)); + test_b5(static_cast(cl)); + + test_b5(static_cast(cl)); + test_b5(static_cast(cl)); + test_b5(static_cast(cl)); + test_b5(static_cast(cl)); + } +} diff --git a/src/boost/libs/hana/test/functional/capture.cpp b/src/boost/libs/hana/test/functional/capture.cpp new file mode 100644 index 000000000..f64a65c0f --- /dev/null +++ b/src/boost/libs/hana/test/functional/capture.cpp @@ -0,0 +1,100 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + hana::test::_injection<0> f{}; + + // 0-arg capture + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture()(f)(), + f() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture()(f)(ct_eq<0>{}), + f(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture()(f)(ct_eq<0>{}, ct_eq<1>{}), + f(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture()(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + // 1-arg capture + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{})(f)(), + f(ct_eq<77>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}), + f(ct_eq<77>{}, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}, ct_eq<1>{}), + f(ct_eq<77>{}, ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<77>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + // 2-args capture + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(), + f(ct_eq<77>{}, ct_eq<88>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}, ct_eq<1>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + // 3-args capture + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}, ct_eq<1>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); +} diff --git a/src/boost/libs/hana/test/functional/demux.cpp b/src/boost/libs/hana/test/functional/demux.cpp new file mode 100644 index 000000000..07285bce5 --- /dev/null +++ b/src/boost/libs/hana/test/functional/demux.cpp @@ -0,0 +1,64 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct MoveOnly { + MoveOnly() = default; + MoveOnly(MoveOnly const&) = delete; + MoveOnly(MoveOnly&&) = default; +}; + +int main() { + hana::test::_injection<0> f{}; + hana::test::_injection<1> g{}; + hana::test::_injection<2> h{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)()(), + f() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g)(ct_eq<1>{}), + f(g(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g)(ct_eq<1>{}, ct_eq<2>{}), + f(g(ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(g(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g, h)(ct_eq<1>{}), + f(g(ct_eq<1>{}), h(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g, h)(ct_eq<1>{}, ct_eq<2>{}), + f(g(ct_eq<1>{}, ct_eq<2>{}), h(ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::demux(f)(g, h)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(g(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), h(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})) + )); + + // Make sure we can pass move-only types when a single function + // is demux'ed. In other words, make sure the arguments are + // perfect-forwarded when a single function is demux'ed. + { + hana::demux(f)(g)(MoveOnly{}); + hana::demux(f)(g)(MoveOnly{}, MoveOnly{}); + hana::demux(f)(g)(MoveOnly{}, MoveOnly{}, MoveOnly{}); + } +} diff --git a/src/boost/libs/hana/test/functional/fix.cpp b/src/boost/libs/hana/test/functional/fix.cpp new file mode 100644 index 000000000..79041b4a9 --- /dev/null +++ b/src/boost/libs/hana/test/functional/fix.cpp @@ -0,0 +1,41 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +namespace hana = boost::hana; + + +BOOST_HANA_CONSTEXPR_LAMBDA auto fact = hana::fix([](auto fact, auto n) { + return hana::eval_if(hana::equal(n, hana::ullong_c<0>), + hana::always(hana::ullong_c<1>), + [=](auto _) { return hana::mult(n, fact(_(n) - hana::ullong_c<1>)); } + ); +}); + +constexpr unsigned long long reference(unsigned long long n) +{ return n == 0 ? 1 : n * reference(n - 1); } + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + fact(hana::ullong_c), + hana::ullong_c + )); + test(); +} + +template <> void test<-1>() { } + +int main() { + test<15>(); +} diff --git a/src/boost/libs/hana/test/functional/iterate.cpp b/src/boost/libs/hana/test/functional/iterate.cpp new file mode 100644 index 000000000..f40805760 --- /dev/null +++ b/src/boost/libs/hana/test/functional/iterate.cpp @@ -0,0 +1,151 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include + +#include +#include + +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct undefined { }; + +constexpr int incr(int i) { return i + 1; } + +int main() { + hana::test::_injection<0> f{}; + + // "real usage" tests + static_assert(hana::iterate<3>(incr, 0) == 3, ""); + { + std::vector vec; + hana::iterate<10>([&](int i) { vec.push_back(i); return i + 1; }, 0); + BOOST_HANA_RUNTIME_CHECK( + vec == std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + ); + } + + // equivalence between iterate(f, x) and iterate(f)(x) + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<0>(undefined{})(ct_eq<0>{}), + hana::iterate<0>(undefined{}, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<4>(f)(ct_eq<0>{}), + hana::iterate<4>(f, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<10>(f)(ct_eq<0>{}), + hana::iterate<10>(f, ct_eq<0>{}) + )); + + // systematic tests + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<0>(undefined{}, ct_eq<0>{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<1>(f, ct_eq<0>{}), + f(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<2>(f, ct_eq<0>{}), + f(f(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<3>(f, ct_eq<0>{}), + f(f(f(ct_eq<0>{}))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<4>(f, ct_eq<0>{}), + f(f(f(f(ct_eq<0>{})))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<5>(f, ct_eq<0>{}), + f(f(f(f(f(ct_eq<0>{}))))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<6>(f, ct_eq<0>{}), + f(f(f(f(f(f(ct_eq<0>{})))))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<7>(f, ct_eq<0>{}), + f(f(f(f(f(f(f(ct_eq<0>{}))))))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<11>(f, ct_eq<0>{}), + f(f(f(f(f(f(f(f(f(f(f(ct_eq<0>{}))))))))))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<12>(f, ct_eq<0>{}), + f(f(f(f(f(f(f(f(f(f(f(f(ct_eq<0>{})))))))))))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::iterate<13>(f, ct_eq<0>{}), + f(f(f(f(f(f(f(f(f(f(f(f(f(ct_eq<0>{}))))))))))))) + )); + + // We can't nest too many calls to f, because that uses a hana::tuple + // internally and some implementation (libstdc++) have trouble with + // deeply-nested calls to `std::is_constructible`, which is required by + // hana::tuple. Hence, we use an homogeneous function for the remaining + // tests. + static_assert(hana::iterate<23>(incr, 0) == 23, ""); + static_assert(hana::iterate<24>(incr, 0) == 24, ""); + static_assert(hana::iterate<25>(incr, 0) == 25, ""); + static_assert(hana::iterate<26>(incr, 0) == 26, ""); + static_assert(hana::iterate<27>(incr, 0) == 27, ""); + static_assert(hana::iterate<28>(incr, 0) == 28, ""); + static_assert(hana::iterate<29>(incr, 0) == 29, ""); + + static_assert(hana::iterate<30>(incr, 0) == 30, ""); + static_assert(hana::iterate<31>(incr, 0) == 31, ""); + static_assert(hana::iterate<32>(incr, 0) == 32, ""); + static_assert(hana::iterate<33>(incr, 0) == 33, ""); + static_assert(hana::iterate<34>(incr, 0) == 34, ""); + static_assert(hana::iterate<35>(incr, 0) == 35, ""); + static_assert(hana::iterate<36>(incr, 0) == 36, ""); + static_assert(hana::iterate<37>(incr, 0) == 37, ""); + static_assert(hana::iterate<38>(incr, 0) == 38, ""); + static_assert(hana::iterate<39>(incr, 0) == 39, ""); + + static_assert(hana::iterate<40>(incr, 0) == 40, ""); + static_assert(hana::iterate<41>(incr, 0) == 41, ""); + static_assert(hana::iterate<42>(incr, 0) == 42, ""); + static_assert(hana::iterate<43>(incr, 0) == 43, ""); + static_assert(hana::iterate<44>(incr, 0) == 44, ""); + static_assert(hana::iterate<45>(incr, 0) == 45, ""); + static_assert(hana::iterate<46>(incr, 0) == 46, ""); + static_assert(hana::iterate<47>(incr, 0) == 47, ""); + static_assert(hana::iterate<48>(incr, 0) == 48, ""); + static_assert(hana::iterate<49>(incr, 0) == 49, ""); + + static_assert(hana::iterate<50>(incr, 0) == 50, ""); + static_assert(hana::iterate<51>(incr, 0) == 51, ""); + static_assert(hana::iterate<52>(incr, 0) == 52, ""); + static_assert(hana::iterate<53>(incr, 0) == 53, ""); + static_assert(hana::iterate<54>(incr, 0) == 54, ""); + static_assert(hana::iterate<55>(incr, 0) == 55, ""); + static_assert(hana::iterate<56>(incr, 0) == 56, ""); + static_assert(hana::iterate<57>(incr, 0) == 57, ""); + static_assert(hana::iterate<58>(incr, 0) == 58, ""); + static_assert(hana::iterate<59>(incr, 0) == 59, ""); +} diff --git a/src/boost/libs/hana/test/functional/lockstep.cpp b/src/boost/libs/hana/test/functional/lockstep.cpp new file mode 100644 index 000000000..086d02cad --- /dev/null +++ b/src/boost/libs/hana/test/functional/lockstep.cpp @@ -0,0 +1,36 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + hana::test::_injection<0> f{}; + hana::test::_injection<1> g{}; + hana::test::_injection<2> h{}; + hana::test::_injection<3> i{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lockstep(f)()(), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lockstep(f)(g)(ct_eq<1>{}), + f(g(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lockstep(f)(g, h)(ct_eq<1>{}, ct_eq<2>{}), + f(g(ct_eq<1>{}), h(ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lockstep(f)(g, h, i)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(g(ct_eq<1>{}), h(ct_eq<2>{}), i(ct_eq<3>{})) + )); +} diff --git a/src/boost/libs/hana/test/functional/overload_linearly.cpp b/src/boost/libs/hana/test/functional/overload_linearly.cpp new file mode 100644 index 000000000..6f537f589 --- /dev/null +++ b/src/boost/libs/hana/test/functional/overload_linearly.cpp @@ -0,0 +1,122 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include + +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct A { }; +struct AA : A { }; +struct B { }; +struct C { }; + +int main() { + // 2 functions without overlap + { + auto f = hana::overload_linearly( + [](A) { return ct_eq<0>{}; }, + [](B) { return ct_eq<1>{}; } + ); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(A{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(AA{}), + f(A{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(B{}), + ct_eq<1>{} + )); + } + + // 2 functions with overlap + { + auto f = hana::overload_linearly( + [](A) { return ct_eq<0>{}; }, + [](A) { return ct_eq<1>{}; } + ); + + auto g = hana::overload_linearly( + [](A) { return ct_eq<0>{}; }, + [](AA) { return ct_eq<1>{}; } + ); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(A{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(AA{}), + f(A{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + g(A{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + g(AA{}), + g(A{}) + )); + } + + // 3 functions + { + auto f = hana::overload_linearly( + [](A) { return ct_eq<0>{}; }, + [](B) { return ct_eq<1>{}; }, + [](C) { return ct_eq<2>{}; } + ); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(A{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(AA{}), + f(A{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(B{}), + ct_eq<1>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(C{}), + ct_eq<2>{} + )); + } + + // 1 function (github issue #280) + { + auto f = hana::overload_linearly( + [](A) { return ct_eq<0>{}; } + ); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(A{}), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + f(AA{}), + f(A{}) + )); + } +} diff --git a/src/boost/libs/hana/test/functional/partial.cpp b/src/boost/libs/hana/test/functional/partial.cpp new file mode 100644 index 000000000..e6f56243c --- /dev/null +++ b/src/boost/libs/hana/test/functional/partial.cpp @@ -0,0 +1,64 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f)(), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f)(ct_eq<1>{}), + f(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f)(ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{})(), + f(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{})(ct_eq<2>{}), + f(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{})(ct_eq<2>{}, ct_eq<3>{}), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{}, ct_eq<2>{})(), + f(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{}, ct_eq<2>{})(ct_eq<3>{}), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{}, ct_eq<2>{})(ct_eq<3>{}, ct_eq<4>{}), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partial(f, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})(), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); +} diff --git a/src/boost/libs/hana/test/functional/placeholder.cpp b/src/boost/libs/hana/test/functional/placeholder.cpp new file mode 100644 index 000000000..be6c9e610 --- /dev/null +++ b/src/boost/libs/hana/test/functional/placeholder.cpp @@ -0,0 +1,119 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include + +#include +namespace hana = boost::hana; +using hana::_; + + +struct extra_t { virtual ~extra_t() { } }; +extra_t extra{}; + +constexpr struct { } invalid{}; + +template using bool_t = bool; +constexpr bool valid_call(...) { return false; } +template +constexpr auto valid_call(F&& f, Args&& ...args) + -> bool_t(f)(std::forward(args)...))> +{ return true; } + +#define BOOST_HANA_TEST_BINARY_OP(op, x, y) \ + static_assert((_ op _)(x, y) == (x op y), ""); \ + BOOST_HANA_RUNTIME_CHECK((_ op _)(x, y, extra) == (x op y)); \ + BOOST_HANA_RUNTIME_CHECK((_ op _)(x, y, extra, extra) == (x op y)); \ + static_assert(!valid_call(_ op _), ""); \ + static_assert(!valid_call(_ op _, invalid), ""); \ + static_assert(!valid_call(_ op _, invalid, invalid), ""); \ + \ + static_assert((_ op y)(x) == (x op y), ""); \ + BOOST_HANA_RUNTIME_CHECK((_ op y)(x, extra) == (x op y)); \ + BOOST_HANA_RUNTIME_CHECK((_ op y)(x, extra, extra) == (x op y)); \ + static_assert(!valid_call(_ op y), ""); \ + static_assert(!valid_call(_ op y, invalid), ""); \ + \ + static_assert((x op _)(y) == (x op y), ""); \ + BOOST_HANA_RUNTIME_CHECK((x op _)(y, extra) == (x op y)); \ + BOOST_HANA_RUNTIME_CHECK((x op _)(y, extra, extra) == (x op y)); \ + static_assert(!valid_call(x op _), ""); \ + static_assert(!valid_call(x op _, invalid), ""); \ + static_assert(!valid_call(x op _, invalid), ""); \ +/**/ + +#define BOOST_HANA_TEST_UNARY_OP(op, x) \ + static_assert((op _)(x) == (op x), ""); \ + BOOST_HANA_RUNTIME_CHECK((op _)(x, extra) == (op x)); \ + BOOST_HANA_RUNTIME_CHECK((op _)(x, extra, extra) == (op x)); \ + static_assert(!valid_call(op _), ""); \ + static_assert(!valid_call(op _, invalid), ""); \ +/**/ + +struct incr_t { + template + constexpr auto operator()(X x) const -> decltype(x + 1) + { return x + 1; } +}; +constexpr incr_t incr{}; + +int main() { + // Arithmetic + BOOST_HANA_TEST_UNARY_OP(+, 1) + BOOST_HANA_TEST_UNARY_OP(-, 1) + BOOST_HANA_TEST_BINARY_OP(+, 6, 3) + BOOST_HANA_TEST_BINARY_OP(-, 6, 3) + BOOST_HANA_TEST_BINARY_OP(*, 6, 3) + BOOST_HANA_TEST_BINARY_OP(/, 6, 3) + BOOST_HANA_TEST_BINARY_OP(%, 6, 3) + + // Bitwise + BOOST_HANA_TEST_UNARY_OP(~, 5) + BOOST_HANA_TEST_BINARY_OP(&, 6, 3) + BOOST_HANA_TEST_BINARY_OP(|, 6, 3) + BOOST_HANA_TEST_BINARY_OP(^, 6, 3) + BOOST_HANA_TEST_BINARY_OP(<<, 6, 3) + BOOST_HANA_TEST_BINARY_OP(>>, 6, 3) + + // Comparison + BOOST_HANA_TEST_BINARY_OP(==, 6, 3) + BOOST_HANA_TEST_BINARY_OP(!=, 6, 3) + BOOST_HANA_TEST_BINARY_OP(<, 6, 3) + BOOST_HANA_TEST_BINARY_OP(<=, 6, 3) + BOOST_HANA_TEST_BINARY_OP(>, 6, 3) + BOOST_HANA_TEST_BINARY_OP(>=, 6, 3) + + // Logical + BOOST_HANA_TEST_BINARY_OP(||, true, false) + BOOST_HANA_TEST_BINARY_OP(&&, true, true) + BOOST_HANA_TEST_UNARY_OP(!, true) + + // Member access + constexpr int i = 4; + constexpr int array[] = {0, 1, 2}; + BOOST_HANA_TEST_UNARY_OP(*, &i) + + static_assert(_[0](array) == array[0], ""); + BOOST_HANA_RUNTIME_CHECK(_[0](array, extra) == array[0]); + BOOST_HANA_RUNTIME_CHECK(_[0](array, extra, extra) == array[0]); + static_assert(_[1](array) == array[1], ""); + static_assert(_[1](array) == array[1], ""); + static_assert(_[2](array) == array[2], ""); + static_assert(!valid_call(_[invalid]), ""); + static_assert(!valid_call(_[invalid], array), ""); + static_assert(!valid_call(_[invalid], invalid), ""); + static_assert(!valid_call(_[0], invalid), ""); + + // Call operator + static_assert(_(1)(incr) == incr(1), ""); + BOOST_HANA_RUNTIME_CHECK(_(1)(incr, extra) == incr(1)); + BOOST_HANA_RUNTIME_CHECK(_(1)(incr, extra, extra) == incr(1)); + static_assert(_(2)(incr) == incr(2), ""); + static_assert(_(3)(incr) == incr(3), ""); + static_assert(!valid_call(_(invalid)), ""); + static_assert(!valid_call(_(invalid), incr), ""); + static_assert(!valid_call(_(invalid), invalid), ""); + static_assert(!valid_call(_(1), invalid), ""); +} diff --git a/src/boost/libs/hana/test/functional/reverse_partial.cpp b/src/boost/libs/hana/test/functional/reverse_partial.cpp new file mode 100644 index 000000000..b5a131a11 --- /dev/null +++ b/src/boost/libs/hana/test/functional/reverse_partial.cpp @@ -0,0 +1,65 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + constexpr auto rp = hana::reverse_partial; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f)(), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f)(ct_eq<1>{}), + f(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f)(ct_eq<1>{}, ct_eq<2>{}), + f(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{})(), + f(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{})(ct_eq<2>{}), + f(ct_eq<2>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{})(ct_eq<2>{}, ct_eq<3>{}), + f(ct_eq<2>{}, ct_eq<3>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{}, ct_eq<2>{})(), + f(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{}, ct_eq<2>{})(ct_eq<3>{}), + f(ct_eq<3>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{}, ct_eq<2>{})(ct_eq<3>{}, ct_eq<4>{}), + f(ct_eq<3>{}, ct_eq<4>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + rp(f, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})(), + f(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); +} -- cgit v1.2.3