diff options
Diffstat (limited to 'src/boost/libs/hana/test/_include/auto')
38 files changed, 4000 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/_include/auto/README.md b/src/boost/libs/hana/test/_include/auto/README.md new file mode 100644 index 000000000..082906c28 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/README.md @@ -0,0 +1,44 @@ +The headers in this directory provide facilities for automatic unit testing. +Basically, each header defines unit tests for an algorithm or a set of related +algorithms. To get the tests for these algorithms, simply include the header +at global scope. However, before including the header, you must define the +following macros: + + `MAKE_TUPLE(...)` + Must expand to a sequence holding `__VA_ARGS__`. A valid definition + would be `hana::make_tuple(__VA_ARGS__)`. + + `TUPLE_TYPE(...)` + Must expand to the type of a sequence holding objects of type `__VA_ARGS__`. + A valid definition would be `hana::tuple<__VA_ARGS__>`. + + `TUPLE_TAG` + Must expand to the tag of the sequence. A valid definition would + be `hana::tuple_tag`. + + +The following macros may or may not be defined: + + `MAKE_TUPLE_NO_CONSTEXPR` + Must be defined if the `MAKE_TUPLE` macro can't be used inside a + constant expression. Otherwise, `MAKE_TUPLE` is assumed to be able + to construct a `constexpr` container. + +The following directories contain automatic unit tests, and the following is +sufficient when adding a new automatic unit test (in a file `${FILE}`): + +```sh +DIRECTORIES=$(find test -type d -name auto | grep -v test/_include/auto) +for d in ${DIRECTORIES}; do + cat > ${d}/${FILE}.cpp <<EOF +// 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 "_specs.hpp" +#include <auto/${FILE}.hpp> + +int main() { } +EOF +done +``` diff --git a/src/boost/libs/hana/test/_include/auto/all_of.hpp b/src/boost/libs/hana/test/_include/auto/all_of.hpp new file mode 100644 index 000000000..b1bdc1125 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/all_of.hpp @@ -0,0 +1,120 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_ALL_OF_HPP +#define BOOST_HANA_TEST_AUTO_ALL_OF_HPP + +#include <boost/hana/all_of.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/bool.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_all_of{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(), + [](auto) { return hana::false_c; } + )); + + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::equal.to(ct_eq<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<999>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<999>{}), + hana::equal.to(ct_eq<0>{}) + ))); + + // Make sure `all_of` short-circuits with runtime predicates + // See http://stackoverflow.com/q/42012512/627587 + { + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}); + hana::all_of(tuple, [&](auto) { ++counter; return false; }); + BOOST_HANA_RUNTIME_CHECK(counter == 1); + } + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{}); + hana::all_of(tuple, [&](auto x) -> bool { + ++counter; + return hana::equal(x, ct_eq<0>{}); + }); + BOOST_HANA_RUNTIME_CHECK(counter == 2); + } + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_ALL_OF_HPP diff --git a/src/boost/libs/hana/test/_include/auto/any_of.hpp b/src/boost/libs/hana/test/_include/auto/any_of.hpp new file mode 100644 index 000000000..400b5a3b1 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/any_of.hpp @@ -0,0 +1,173 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_ANY_OF_HPP +#define BOOST_HANA_TEST_AUTO_ANY_OF_HPP + +#include <boost/hana/any_of.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/bool.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_any_of{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(), + [](auto) { return hana::true_c; } + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::equal.to(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::equal.to(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::equal.to(ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::equal.to(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::equal.to(ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::equal.to(ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + [](auto) { return hana::false_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + [](auto) { return hana::true_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<999>{}) + ))); + + // Make sure `any_of` short-circuits with runtime predicates + // See http://stackoverflow.com/q/42012512/627587 + { + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}); + hana::any_of(tuple, [&](auto) { ++counter; return true; }); + BOOST_HANA_RUNTIME_CHECK(counter == 1); + } + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}); + hana::any_of(tuple, [&](auto x) -> bool { + ++counter; + return hana::equal(x, ct_eq<1>{}); + }); + BOOST_HANA_RUNTIME_CHECK(counter == 2); + } + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_ANY_OF_HPP diff --git a/src/boost/libs/hana/test/_include/auto/ap.hpp b/src/boost/libs/hana/test/_include/auto/ap.hpp new file mode 100644 index 000000000..7fe0fc5be --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/ap.hpp @@ -0,0 +1,76 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_AP_HPP +#define BOOST_HANA_TEST_AUTO_AP_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/ap.hpp> +#include <boost/hana/equal.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_ap{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + hana::test::_injection<0> f{}; + hana::test::_injection<1> g{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f), MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(f(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{}), f(ct_eq<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f, g), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f, g), MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(f(ct_eq<0>{}), g(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f, g), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{}), g(ct_eq<0>{}), g(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(MAKE_TUPLE(f, g), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{}), f(ct_eq<2>{}), + g(ct_eq<0>{}), g(ct_eq<1>{}), g(ct_eq<2>{})) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_AP_HPP diff --git a/src/boost/libs/hana/test/_include/auto/at.hpp b/src/boost/libs/hana/test/_include/auto/at.hpp new file mode 100644 index 000000000..66574a361 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/at.hpp @@ -0,0 +1,91 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_AT_HPP +#define BOOST_HANA_TEST_AUTO_AT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/at.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/tracked.hpp> + + +namespace _test_at_detail { template <int> struct invalid { }; } + + +TestCase test_at{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + using _test_at_detail::invalid; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + ct_eq<0>{} + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(ct_eq<0>{}, invalid<1>{}), hana::size_c<0>), + ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(invalid<0>{}, ct_eq<1>{}), hana::size_c<1>), + ct_eq<1>{} + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(invalid<0>{}, ct_eq<1>{}, invalid<2>{}), hana::size_c<1>), + ct_eq<1>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(invalid<0>{}, invalid<1>{}, ct_eq<2>{}), hana::size_c<2>), + ct_eq<2>{} + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(MAKE_TUPLE(invalid<0>{}, invalid<1>{}, ct_eq<2>{}, invalid<3>{}), hana::size_c<2>), + ct_eq<2>{} + )); + +#ifndef MAKE_TUPLE_NO_CONSTEXPR + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1), hana::size_c<0>), + 1 + ), ""); + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1, '2'), hana::size_c<0>), + 1 + ), ""); + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1, '2', 3.3), hana::size_c<0>), + 1 + ), ""); + + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1, '2'), hana::size_c<1>), + '2' + ), ""); + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1, '2', 3.3), hana::size_c<1>), + '2' + ), ""); + + static_assert(hana::equal( + hana::at(MAKE_TUPLE(1, '2', 3.3), hana::size_c<2>), + 3.3 + ), ""); +#endif + + // make sure we can use non-pods on both sides + { + // store the result to make sure `at` is executed. + auto result = hana::at(MAKE_TUPLE(Tracked{0}, ct_eq<1>{}, Tracked{1}), hana::size_c<1>);; + BOOST_HANA_CONSTANT_CHECK(hana::equal(result, ct_eq<1>{})); + } + +}}; + +#endif // !BOOST_HANA_TEST_AUTO_AT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/cartesian_product.hpp b/src/boost/libs/hana/test/_include/auto/cartesian_product.hpp new file mode 100644 index 000000000..8aecf3649 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/cartesian_product.hpp @@ -0,0 +1,234 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_CARTESIAN_PRODUCT_HPP +#define BOOST_HANA_TEST_AUTO_CARTESIAN_PRODUCT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/cartesian_product.hpp> +#include <boost/hana/equal.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_cartesian_product{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + // 0 lists + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE()), + MAKE_TUPLE() + )); + + // 1 list + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE() + )), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}), + MAKE_TUPLE(ct_eq<3>{}) + ) + )); + + // 2 lists + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(), + MAKE_TUPLE() + )), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}), + MAKE_TUPLE() + )), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}), + MAKE_TUPLE(ct_eq<10>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<01>{}), + MAKE_TUPLE(ct_eq<10>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}), + MAKE_TUPLE(ct_eq<01>{}, ct_eq<10>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}), + MAKE_TUPLE(ct_eq<10>{}, ct_eq<11>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<11>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<01>{}), + MAKE_TUPLE(ct_eq<10>{}, ct_eq<11>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<11>{}), + MAKE_TUPLE(ct_eq<01>{}, ct_eq<10>{}), + MAKE_TUPLE(ct_eq<01>{}, ct_eq<11>{}) + ) + )); + + // misc + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}), + MAKE_TUPLE(ct_eq<10>{}), + MAKE_TUPLE(ct_eq<20>{}), + MAKE_TUPLE(ct_eq<30>{}, ct_eq<31>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<20>{}, ct_eq<30>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<20>{}, ct_eq<31>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}), + MAKE_TUPLE(ct_eq<10>{}), + MAKE_TUPLE(ct_eq<20>{}, ct_eq<21>{}), + MAKE_TUPLE(ct_eq<30>{}, ct_eq<31>{}) + )), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<20>{}, ct_eq<30>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<20>{}, ct_eq<31>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<21>{}, ct_eq<30>{}), + MAKE_TUPLE(ct_eq<00>{}, ct_eq<10>{}, ct_eq<21>{}, ct_eq<31>{}) + ) + )); + + + // cartesian_product in a constexpr context +#ifndef MAKE_TUPLE_NO_CONSTEXPR + static_assert(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(1), + MAKE_TUPLE('a', 'b') + )), + MAKE_TUPLE( + MAKE_TUPLE(1, 'a'), + MAKE_TUPLE(1, 'b') + ) + ), ""); + + static_assert(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(1, 2), + MAKE_TUPLE('a') + )), + MAKE_TUPLE( + MAKE_TUPLE(1, 'a'), + MAKE_TUPLE(2, 'a') + ) + ), ""); + + static_assert(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(1, 2), + MAKE_TUPLE('a', 'b') + )), + MAKE_TUPLE( + MAKE_TUPLE(1, 'a'), + MAKE_TUPLE(1, 'b'), + MAKE_TUPLE(2, 'a'), + MAKE_TUPLE(2, 'b') + ) + ), ""); + + static_assert(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(1), + MAKE_TUPLE('a'), + MAKE_TUPLE(1.f), + MAKE_TUPLE(1l, 2l) + )), + MAKE_TUPLE( + MAKE_TUPLE(1, 'a', 1.f, 1l), + MAKE_TUPLE(1, 'a', 1.f, 2l) + ) + ), ""); + + static_assert(hana::equal( + hana::cartesian_product(MAKE_TUPLE( + MAKE_TUPLE(1), + MAKE_TUPLE('a'), + MAKE_TUPLE(1.f), + MAKE_TUPLE(1l, 2l), + MAKE_TUPLE(nullptr) + )), + MAKE_TUPLE( + MAKE_TUPLE(1, 'a', 1.f, 1l, nullptr), + MAKE_TUPLE(1, 'a', 1.f, 2l, nullptr) + ) + ), ""); +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_CARTESIAN_PRODUCT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/drop_back.hpp b/src/boost/libs/hana/test/_include/auto/drop_back.hpp new file mode 100644 index 000000000..e3ea42e0c --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/drop_back.hpp @@ -0,0 +1,99 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_DROP_BACK_HPP +#define BOOST_HANA_TEST_AUTO_DROP_BACK_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/drop_back.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_drop_back{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<3>), + MAKE_TUPLE() + )); + + // make sure hana::drop_back(xs) == hana::drop_back(xs, hana::size_c<1>) + BOOST_HANA_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE()), + hana::drop_back(MAKE_TUPLE(), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{})), + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{})), + hana::drop_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}), hana::size_c<1>) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_DROP_BACK_HPP diff --git a/src/boost/libs/hana/test/_include/auto/drop_front.hpp b/src/boost/libs/hana/test/_include/auto/drop_front.hpp new file mode 100644 index 000000000..05988ace2 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/drop_front.hpp @@ -0,0 +1,160 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_DROP_FRONT_HPP +#define BOOST_HANA_TEST_AUTO_DROP_FRONT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/drop_front.hpp> +#include <boost/hana/drop_front_exactly.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_drop_front{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<3>), + MAKE_TUPLE() + )); + + // make sure hana::drop_front(xs) == hana::drop_front(xs, size_c<1>) + BOOST_HANA_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE()), + hana::drop_front(MAKE_TUPLE(), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{})), + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{})), + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}), hana::size_c<1>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); +}}; + +TestCase test_drop_front_exactly{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(), hana::size_c<0>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, + ct_eq<4>{}, ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}), hana::size_c<4>), + MAKE_TUPLE(ct_eq<4>{}, ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}) + )); + + // make sure drop_front_exactly(xs) == drop_front_exactly(xs, size_c<1>) + BOOST_HANA_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{})), + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>) + )); + + BOOST_HANA_CHECK(hana::equal( + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{})), + hana::drop_front_exactly(MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}), hana::size_c<1>) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_DROP_FRONT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/drop_while.hpp b/src/boost/libs/hana/test/_include/auto/drop_while.hpp new file mode 100644 index 000000000..054d79be0 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/drop_while.hpp @@ -0,0 +1,72 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_DROP_WHILE_HPP +#define BOOST_HANA_TEST_AUTO_DROP_WHILE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/bool.hpp> +#include <boost/hana/drop_while.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/functional/id.hpp> +#include <boost/hana/not_equal.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_drop_while{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(), hana::id), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::true_c), hana::id), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::false_c), hana::id), + MAKE_TUPLE(hana::false_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::true_c, hana::true_c), hana::id), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::true_c, hana::false_c), hana::id), + MAKE_TUPLE(hana::false_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::false_c, hana::true_c), hana::id), + MAKE_TUPLE(hana::false_c, hana::true_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(hana::false_c, hana::false_c), hana::id), + MAKE_TUPLE(hana::false_c, hana::false_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::not_equal.to(ct_eq<99>{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::not_equal.to(ct_eq<1>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::not_equal.to(ct_eq<3>{})), + MAKE_TUPLE(ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_while(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::not_equal.to(ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_DROP_WHILE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/for_each.hpp b/src/boost/libs/hana/test/_include/auto/for_each.hpp new file mode 100644 index 000000000..4e36e9853 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/for_each.hpp @@ -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) + +#ifndef BOOST_HANA_TEST_AUTO_FOR_EACH_HPP +#define BOOST_HANA_TEST_AUTO_FOR_EACH_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/for_each.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + +#include <vector> + + +TestCase test_for_each{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + // Make sure the function is applied in left-to-right order. + { + auto check = [](auto ...xs) { + std::vector<int> seen{}; + hana::for_each(MAKE_TUPLE(xs...), [&](int x) { + seen.push_back(x); + }); + BOOST_HANA_RUNTIME_CHECK(seen == std::vector<int>{xs...}); + }; + + check(); + check(0); + check(0, 1); + check(0, 1, 2); + check(0, 1, 2, 3); + check(0, 1, 2, 3, 4); + } + + // Make sure the function is never called when the sequence is empty. + { + struct undefined { }; + hana::for_each(MAKE_TUPLE(), undefined{}); + } + + // Make sure it works with heterogeneous sequences. + { + hana::for_each(MAKE_TUPLE(ct_eq<0>{}), [](auto) { }); + hana::for_each(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), [](auto) { }); + hana::for_each(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), [](auto) { }); + hana::for_each(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), [](auto) { }); + } + + // Make sure for_each is constexpr when used with a constexpr function + // and constexpr arguments. This used not to be the case. +#ifndef MAKE_TUPLE_NO_CONSTEXPR + { + struct f { constexpr void operator()(int) const { } }; + constexpr int i = (hana::for_each(MAKE_TUPLE(1, 2, 3), f{}), 0); + (void)i; + } +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_FOR_EACH_HPP diff --git a/src/boost/libs/hana/test/_include/auto/group.hpp b/src/boost/libs/hana/test/_include/auto/group.hpp new file mode 100644 index 000000000..1802ebd33 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/group.hpp @@ -0,0 +1,150 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_GROUP_HPP +#define BOOST_HANA_TEST_AUTO_GROUP_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/group.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/equivalence_class.hpp> + + +TestCase test_group{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + + // Test without a custom predicate + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE()), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}), + MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}, ct_eq<0>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<1>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<1>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<2>{}, ct_eq<2>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<2>{}, ct_eq<2>{})) + )); + } + + // Test with a custom predicate + { + auto a = [](auto z) { return ::equivalence_class(ct_eq<999>{}, z); }; + auto b = [](auto z) { return ::equivalence_class(ct_eq<888>{}, z); }; + + auto pred = [](auto x, auto y) { + return hana::equal(x.unwrap, y.unwrap); + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(a(ct_eq<0>{})), pred), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}))) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), pred), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}))) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), a(ct_eq<1>{})), pred), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), + MAKE_TUPLE(a(ct_eq<1>{}))) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), a(ct_eq<1>{}), b(ct_eq<1>{})), pred), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), + MAKE_TUPLE(a(ct_eq<1>{}), b(ct_eq<1>{}))) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), a(ct_eq<1>{}), b(ct_eq<1>{}), b(ct_eq<0>{})), pred), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), + MAKE_TUPLE(a(ct_eq<1>{}), b(ct_eq<1>{})), + MAKE_TUPLE(b(ct_eq<0>{}))) + )); + + // Test group.by syntactic sugar + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group.by(pred, MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), a(ct_eq<1>{}), b(ct_eq<1>{}), b(ct_eq<0>{}))), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), + MAKE_TUPLE(a(ct_eq<1>{}), b(ct_eq<1>{})), + MAKE_TUPLE(b(ct_eq<0>{}))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::group.by(pred)(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), a(ct_eq<1>{}), b(ct_eq<1>{}), b(ct_eq<0>{}))), + MAKE_TUPLE( + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), + MAKE_TUPLE(a(ct_eq<1>{}), b(ct_eq<1>{})), + MAKE_TUPLE(b(ct_eq<0>{}))) + )); + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_GROUP_HPP diff --git a/src/boost/libs/hana/test/_include/auto/index_if.hpp b/src/boost/libs/hana/test/_include/auto/index_if.hpp new file mode 100644 index 000000000..af7c86bbc --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/index_if.hpp @@ -0,0 +1,81 @@ +// Copyright Louis Dionne 2013-2017 +// Copyright Jason Rice 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) + +#ifndef BOOST_HANA_TEST_AUTO_INDEX_IF_HPP +#define BOOST_HANA_TEST_AUTO_INDEX_IF_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/index_if.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/optional.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/tracked.hpp> + + +namespace _test_index_if_detail { template <int> struct invalid { }; } + + +TestCase test_index_if{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + using _test_index_if_detail::invalid; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(), hana::equal.to(ct_eq<0>{})), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}), hana::equal.to(ct_eq<0>{})), + hana::just(hana::size_c<0>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}), hana::equal.to(ct_eq<42>{})), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<0>{})), + hana::just(hana::size_c<0>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<1>{})), + hana::just(hana::size_c<1>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<2>{})), + hana::just(hana::size_c<2>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::index_if(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<42>{})), + hana::nothing + )); + +#ifndef MAKE_TUPLE_NO_CONSTEXPR + auto type_equal = [](auto type) { return [=](auto&& value) { + return hana::equal(hana::typeid_(value), type); + };}; + + static_assert(decltype(hana::equal( + hana::index_if(MAKE_TUPLE(1, '2', 3.3), type_equal(hana::type_c<int>)), + hana::just(hana::size_c<0>) + )){}, ""); + static_assert(decltype(hana::equal( + hana::index_if(MAKE_TUPLE(1, '2', 3.3), type_equal(hana::type_c<char>)), + hana::just(hana::size_c<1>) + )){}, ""); + static_assert(decltype(hana::equal( + hana::index_if(MAKE_TUPLE(1, '2', 3.3), type_equal(hana::type_c<double>)), + hana::just(hana::size_c<2>) + )){}, ""); + static_assert(decltype(hana::equal( + hana::index_if(MAKE_TUPLE(1, '2', 3.3), type_equal(hana::type_c<invalid<42>>)), + hana::nothing + )){}, ""); +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_INDEX_IF_HPP diff --git a/src/boost/libs/hana/test/_include/auto/insert.hpp b/src/boost/libs/hana/test/_include/auto/insert.hpp new file mode 100644 index 000000000..c9715452a --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/insert.hpp @@ -0,0 +1,84 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_INSERT_HPP +#define BOOST_HANA_TEST_AUTO_INSERT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/insert.hpp> +#include <boost/hana/integral_constant.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_insert{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto z = ct_eq<999>{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>, z), + MAKE_TUPLE(z, ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>, z), + MAKE_TUPLE(ct_eq<0>{}, z) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>, z), + MAKE_TUPLE(z, ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>, z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, z) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<0>, z), + MAKE_TUPLE(z, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<1>, z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<2>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, z, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::size_c<3>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, z) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<0>, z), + MAKE_TUPLE(z, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<1>, z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<2>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, z, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<3>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, z, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<4>, z), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, z) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_INSERT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/insert_range.hpp b/src/boost/libs/hana/test/_include/auto/insert_range.hpp new file mode 100644 index 000000000..ac929d7ed --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/insert_range.hpp @@ -0,0 +1,105 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_INSERT_RANGE_HPP +#define BOOST_HANA_TEST_AUTO_INSERT_RANGE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/insert_range.hpp> +#include <boost/hana/integral_constant.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/seq.hpp> + + +TestCase test_insert_range{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto foldable = ::seq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}), + hana::size_c<0>, + foldable()), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}), + hana::size_c<0>, + foldable(ct_eq<-1>{})), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}), + hana::size_c<0>, + foldable(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}), + hana::size_c<0>, + foldable(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<-3>{})), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<-3>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<0>, + foldable()), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<0>, + foldable(ct_eq<-1>{})), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<0>, + foldable(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<1>, + foldable()), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<1>, + foldable(ct_eq<-1>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<-1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<1>, + foldable(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<2>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::insert_range( + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<2>, + foldable(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<3>{}, ct_eq<4>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_INSERT_RANGE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/intersperse.hpp b/src/boost/libs/hana/test/_include/auto/intersperse.hpp new file mode 100644 index 000000000..83e7e8148 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/intersperse.hpp @@ -0,0 +1,54 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_INTERSPERSE_HPP +#define BOOST_HANA_TEST_AUTO_INTERSPERSE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/intersperse.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_intersperse{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + + auto z = ct_eq<999>{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}), undefined{}), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, z, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, z, ct_eq<2>{}, z, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, z, ct_eq<2>{}, z, ct_eq<3>{}, z, ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::intersperse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, ct_eq<5>{}), z), + MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<1>{}, z, ct_eq<2>{}, z, ct_eq<3>{}, z, ct_eq<4>{}, z, ct_eq<5>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_INTERSPERSE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/is_empty.hpp b/src/boost/libs/hana/test/_include/auto/is_empty.hpp new file mode 100644 index 000000000..99ae879dd --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/is_empty.hpp @@ -0,0 +1,55 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_IS_EMPTY_HPP +#define BOOST_HANA_TEST_AUTO_IS_EMPTY_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/is_empty.hpp> +#include <boost/hana/not.hpp> + +#include "test_case.hpp" + + +namespace _test_is_empty_detail { template <int i> struct undefined { }; } + +TestCase test_is_empty{[]{ + namespace hana = boost::hana; + using _test_is_empty_detail::undefined; + + BOOST_HANA_CONSTANT_CHECK(hana::is_empty( + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty( + MAKE_TUPLE(undefined<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty( + MAKE_TUPLE(undefined<0>{}, undefined<1>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty( + MAKE_TUPLE(undefined<0>{}, undefined<1>{}, undefined<2>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty( + MAKE_TUPLE(undefined<0>{}, undefined<1>{}, undefined<2>{}, undefined<3>{}) + ))); + + // Check with a runtime value + { + int i = 3; // <- runtime value + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(MAKE_TUPLE(i)))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(MAKE_TUPLE(i, i)))); + } + +#ifndef MAKE_TUPLE_NO_CONSTEXPR + static_assert(hana::is_empty(MAKE_TUPLE()), ""); + static_assert(hana::not_(hana::is_empty(MAKE_TUPLE(undefined<0>{}))), ""); + static_assert(hana::not_(hana::is_empty(MAKE_TUPLE(undefined<0>{}, undefined<1>{}))), ""); +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_IS_EMPTY_HPP diff --git a/src/boost/libs/hana/test/_include/auto/length.hpp b/src/boost/libs/hana/test/_include/auto/length.hpp new file mode 100644 index 000000000..25f75dc4d --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/length.hpp @@ -0,0 +1,48 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_LENGTH_HPP +#define BOOST_HANA_TEST_AUTO_LENGTH_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/length.hpp> + +#include "test_case.hpp" + + +namespace _test_length_detail { template <int> struct undefined { }; } + +TestCase test_length{[]{ + namespace hana = boost::hana; + using _test_length_detail::undefined; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(MAKE_TUPLE()), + hana::size_c<0> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(MAKE_TUPLE(undefined<1>{})), + hana::size_c<1> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(MAKE_TUPLE(undefined<1>{}, undefined<2>{})), + hana::size_c<2> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(MAKE_TUPLE(undefined<1>{}, undefined<2>{}, undefined<3>{})), + hana::size_c<3> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(MAKE_TUPLE(undefined<1>{}, undefined<2>{}, undefined<3>{}, undefined<4>{}, undefined<5>{}, undefined<6>{})), + hana::size_c<6> + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_LENGTH_HPP diff --git a/src/boost/libs/hana/test/_include/auto/lexicographical_compare.hpp b/src/boost/libs/hana/test/_include/auto/lexicographical_compare.hpp new file mode 100644 index 000000000..83870d561 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/lexicographical_compare.hpp @@ -0,0 +1,109 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_LEXICOGRAPHICAL_COMPARE_HPP +#define BOOST_HANA_TEST_AUTO_LEXICOGRAPHICAL_COMPARE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/lexicographical_compare.hpp> +#include <boost/hana/not.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_lexicographical_compare{[]{ + namespace hana = boost::hana; + using hana::test::ct_ord; + + struct undefined { }; + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(), + MAKE_TUPLE() + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(), + MAKE_TUPLE(undefined{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(undefined{}), + MAKE_TUPLE() + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}), + MAKE_TUPLE(ct_ord<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}), + MAKE_TUPLE(ct_ord<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<1>{}), + MAKE_TUPLE(ct_ord<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, undefined{}), + MAKE_TUPLE(ct_ord<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}), + MAKE_TUPLE(ct_ord<0>{}, undefined{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<0>{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<0>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<3>{}, undefined{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<3>{}, undefined{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::lexicographical_compare( + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<3>{}), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, undefined{}) + ))); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_LEXICOGRAPHICAL_COMPARE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/make.hpp b/src/boost/libs/hana/test/_include/auto/make.hpp new file mode 100644 index 000000000..83536edfd --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/make.hpp @@ -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) + +#ifndef BOOST_HANA_TEST_AUTO_MAKE_HPP +#define BOOST_HANA_TEST_AUTO_MAKE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/core/make.hpp> +#include <boost/hana/equal.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_make{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + MAKE_TUPLE(), + hana::make<TUPLE_TAG>() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + MAKE_TUPLE(ct_eq<0>{}), + hana::make<TUPLE_TAG>(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::make<TUPLE_TAG>(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::make<TUPLE_TAG>(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_MAKE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/none_of.hpp b/src/boost/libs/hana/test/_include/auto/none_of.hpp new file mode 100644 index 000000000..7e1dff2d8 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/none_of.hpp @@ -0,0 +1,90 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_NONE_OF_HPP +#define BOOST_HANA_TEST_AUTO_NONE_OF_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/bool.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/none_of.hpp> +#include <boost/hana/not.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_none_of{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::none_of( + MAKE_TUPLE(), + [](auto) { return hana::false_c; } + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::true_c; } + ))); + BOOST_HANA_CONSTANT_CHECK(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}), + [](auto) { return hana::false_c; } + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<0>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}), + hana::equal.to(ct_eq<999>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<0>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<1>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<2>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<3>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<4>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::none_of( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::equal.to(ct_eq<999>{}) + )); + + // Make sure `none_of` short-circuits with runtime predicates + // See http://stackoverflow.com/q/42012512/627587 + { + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}); + hana::none_of(tuple, [&](auto) { ++counter; return true; }); + BOOST_HANA_RUNTIME_CHECK(counter == 1); + } + { + int counter = 0; + auto tuple = MAKE_TUPLE(ct_eq<999>{}, ct_eq<0>{}, ct_eq<999>{}); + hana::none_of(tuple, [&](auto x) -> bool { + ++counter; + return hana::equal(x, ct_eq<0>{}); + }); + BOOST_HANA_RUNTIME_CHECK(counter == 2); + } + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_NONE_OF_HPP diff --git a/src/boost/libs/hana/test/_include/auto/partition.hpp b/src/boost/libs/hana/test/_include/auto/partition.hpp new file mode 100644 index 000000000..d1fa7212e --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/partition.hpp @@ -0,0 +1,74 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_PARTITION_HPP +#define BOOST_HANA_TEST_AUTO_PARTITION_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/contains.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/partition.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/minimal_product.hpp> + + +TestCase test_partition{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + + auto pair = ::minimal_product; + auto pred = hana::in ^ MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<-3>{}, ct_eq<-4>{}, ct_eq<-5>{}); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(), undefined{}), + pair(MAKE_TUPLE(), MAKE_TUPLE()) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<0>{}), pred), + pair(MAKE_TUPLE(), + MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), pred), + pair(MAKE_TUPLE(), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<-1>{}), pred), + pair(MAKE_TUPLE(ct_eq<-1>{}), + MAKE_TUPLE()) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<0>{}, ct_eq<2>{}), pred), + pair(MAKE_TUPLE(ct_eq<-1>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<0>{}, ct_eq<-3>{}, ct_eq<2>{}, ct_eq<-5>{}, ct_eq<6>{}), pred), + pair(MAKE_TUPLE(ct_eq<-3>{}, ct_eq<-5>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<6>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<2>{}, ct_eq<-3>{}, ct_eq<0>{}, ct_eq<-3>{}, ct_eq<4>{}), pred), + pair(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-3>{}, ct_eq<-3>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<0>{}, ct_eq<4>{})) + )); + + // partition.by + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition.by(pred, MAKE_TUPLE(ct_eq<-1>{}, ct_eq<0>{}, ct_eq<2>{})), + hana::partition(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<0>{}, ct_eq<2>{}), pred) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::partition.by(pred)(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<0>{}, ct_eq<2>{})), + hana::partition(MAKE_TUPLE(ct_eq<-1>{}, ct_eq<0>{}, ct_eq<2>{}), pred) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_PARTITION_HPP diff --git a/src/boost/libs/hana/test/_include/auto/permutations.hpp b/src/boost/libs/hana/test/_include/auto/permutations.hpp new file mode 100644 index 000000000..d854103ac --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/permutations.hpp @@ -0,0 +1,87 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_PERMUTATIONS_HPP +#define BOOST_HANA_TEST_AUTO_PERMUTATIONS_HPP + +#include <boost/hana/and.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/is_subset.hpp> +#include <boost/hana/permutations.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_permutations{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto is_permutation = [](auto xs, auto ys) { + return hana::and_(hana::is_subset(xs, ys), hana::is_subset(ys, xs)); + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::permutations(MAKE_TUPLE()), + MAKE_TUPLE(MAKE_TUPLE()) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::permutations(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(is_permutation( + hana::permutations(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(is_permutation( + hana::permutations(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<0>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}) + ) + )); + + BOOST_HANA_CONSTANT_CHECK(is_permutation( + hana::permutations(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})), + MAKE_TUPLE( + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<3>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<3>{}, ct_eq<1>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<3>{}, ct_eq<2>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}, ct_eq<2>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}, ct_eq<3>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<0>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<3>{}, ct_eq<0>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<3>{}, ct_eq<2>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<0>{}, ct_eq<3>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<1>{}, ct_eq<3>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<3>{}, ct_eq<0>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<3>{}, ct_eq<1>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<1>{}, ct_eq<0>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<0>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<2>{}, ct_eq<0>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}) + ) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_PERMUTATIONS_HPP diff --git a/src/boost/libs/hana/test/_include/auto/remove_at.hpp b/src/boost/libs/hana/test/_include/auto/remove_at.hpp new file mode 100644 index 000000000..296b989e8 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/remove_at.hpp @@ -0,0 +1,130 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_REMOVE_AT_HPP +#define BOOST_HANA_TEST_AUTO_REMOVE_AT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/remove_at.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_remove_at{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}), + hana::size_c<0>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::size_c<0>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<0>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<0>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<0>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<3>{}, ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + hana::size_c<4>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + // remove_at_c + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<0>(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<0>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<1>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<0>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<1>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_at_c<2>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_REMOVE_AT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/remove_range.hpp b/src/boost/libs/hana/test/_include/auto/remove_range.hpp new file mode 100644 index 000000000..51bbf9133 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/remove_range.hpp @@ -0,0 +1,114 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_REMOVE_RANGE_HPP +#define BOOST_HANA_TEST_AUTO_REMOVE_RANGE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/remove_range.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_remove_range{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(), hana::size_c<0>, hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(), hana::size_c<1>, hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(), hana::size_c<2>, hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>, hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>, hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>, hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<2>, hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>, hana::size_c<0>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>, hana::size_c<1>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>, hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>, hana::size_c<2>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>, hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::size_c<9999>, hana::size_c<9999>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<0>, hana::size_c<2>), + MAKE_TUPLE(ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + hana::size_c<1>, hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<0>, hana::size_c<2>), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::size_c<2>, hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, + ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}), + hana::size_c<4>, hana::size_c<7>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}) + )); + + // remove_range_c + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::remove_range_c<4, 7>(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, + ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_REMOVE_RANGE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/reverse.hpp b/src/boost/libs/hana/test/_include/auto/reverse.hpp new file mode 100644 index 000000000..c0c2000c5 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/reverse.hpp @@ -0,0 +1,55 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_REVERSE_HPP +#define BOOST_HANA_TEST_AUTO_REVERSE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/reverse.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_reverse{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + using hana::test::cx_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::reverse(MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::reverse(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::reverse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::reverse(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}) + )); + + +#ifndef MAKE_TUPLE_NO_CONSTEXPR + static_assert(hana::equal( + hana::reverse(MAKE_TUPLE(cx_eq<1>{})), + MAKE_TUPLE(cx_eq<1>{}) + ), ""); + static_assert(hana::equal( + hana::reverse(MAKE_TUPLE(cx_eq<1>{}, cx_eq<2>{})), + MAKE_TUPLE(cx_eq<2>{}, cx_eq<1>{}) + ), ""); + static_assert(hana::equal( + hana::reverse(MAKE_TUPLE(cx_eq<1>{}, cx_eq<2>{}, cx_eq<3>{})), + MAKE_TUPLE(cx_eq<3>{}, cx_eq<2>{}, cx_eq<1>{}) + ), ""); +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_REVERSE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/scans.hpp b/src/boost/libs/hana/test/_include/auto/scans.hpp new file mode 100644 index 000000000..5c5c0dd6a --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/scans.hpp @@ -0,0 +1,216 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_SCANS_HPP +#define BOOST_HANA_TEST_AUTO_SCANS_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/scan_left.hpp> +#include <boost/hana/scan_right.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_scan_left{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + hana::test::_injection<0> f{}; + + // Without initial state + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}), undefined{}), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), f), + MAKE_TUPLE(ct_eq<0>{}, f(ct_eq<0>{}, ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f), + MAKE_TUPLE( + ct_eq<0>{}, + f(ct_eq<0>{}, ct_eq<1>{}), + f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}) + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), f), + MAKE_TUPLE( + ct_eq<0>{}, + f(ct_eq<0>{}, ct_eq<1>{}), + f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), + f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}) + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), f), + MAKE_TUPLE( + ct_eq<0>{}, + f(ct_eq<0>{}, ct_eq<1>{}), + f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), + f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), + f(f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), ct_eq<4>{}) + ) + )); + + // With initial state + auto s = ct_eq<999>{}; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(), s, undefined{}), + MAKE_TUPLE(s) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}), s, f), + MAKE_TUPLE(s, f(s, ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), s, f), + MAKE_TUPLE(s, f(s, ct_eq<0>{}), f(f(s, ct_eq<0>{}), ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f), + MAKE_TUPLE( + s, + f(s, ct_eq<0>{}), + f(f(s, ct_eq<0>{}), ct_eq<1>{}), + f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}) + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), s, f), + MAKE_TUPLE( + s, + f(s, ct_eq<0>{}), + f(f(s, ct_eq<0>{}), ct_eq<1>{}), + f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), + f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}) + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), s, f), + MAKE_TUPLE( + s, + f(s, ct_eq<0>{}), + f(f(s, ct_eq<0>{}), ct_eq<1>{}), + f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), + f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), + f(f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), ct_eq<4>{}) + ) + )); +}}; + + +TestCase test_scan_right{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + hana::test::_injection<0> f{}; + + // Without initial state + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}), undefined{}), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), f), + MAKE_TUPLE( + f(ct_eq<0>{}, ct_eq<1>{}), + ct_eq<1>{} + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, ct_eq<2>{})), + f(ct_eq<1>{}, ct_eq<2>{}), + ct_eq<2>{} + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, ct_eq<3>{}))), + f(ct_eq<1>{}, f(ct_eq<2>{}, ct_eq<3>{})), + f(ct_eq<2>{}, ct_eq<3>{}), + ct_eq<3>{} + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{})))), + f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{}))), + f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{})), + f(ct_eq<3>{}, ct_eq<4>{}), + ct_eq<4>{} + ) + )); + + // With initial state + auto s = ct_eq<999>{}; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(), s, undefined{}), + MAKE_TUPLE(s) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}), s, f), + MAKE_TUPLE( + f(ct_eq<0>{}, s), + s + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), s, f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, s)), + f(ct_eq<1>{}, s), + s + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, s))), + f(ct_eq<1>{}, f(ct_eq<2>{}, s)), + f(ct_eq<2>{}, s), + s + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), s, f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, s)))), + f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, s))), + f(ct_eq<2>{}, f(ct_eq<3>{}, s)), + f(ct_eq<3>{}, s), + s + ) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), s, f), + MAKE_TUPLE( + f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s))))), + f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s)))), + f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s))), + f(ct_eq<3>{}, f(ct_eq<4>{}, s)), + f(ct_eq<4>{}, s), + s + ) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_SCANS_HPP diff --git a/src/boost/libs/hana/test/_include/auto/sequence.hpp b/src/boost/libs/hana/test/_include/auto/sequence.hpp new file mode 100644 index 000000000..280b7355b --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/sequence.hpp @@ -0,0 +1,13 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_SEQUENCE_HPP +#define BOOST_HANA_TEST_AUTO_SEQUENCE_HPP + +#include <boost/hana/concept/sequence.hpp> + + +static_assert(boost::hana::Sequence<TUPLE_TAG>::value, ""); + +#endif // !BOOST_HANA_TEST_AUTO_SEQUENCE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/slice.hpp b/src/boost/libs/hana/test/_include/auto/slice.hpp new file mode 100644 index 000000000..3beb2ef0a --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/slice.hpp @@ -0,0 +1,182 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_SLICE_HPP +#define BOOST_HANA_TEST_AUTO_SLICE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/range.hpp> +#include <boost/hana/slice.hpp> +#include <boost/hana/tuple.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/seq.hpp> + +#include <cstddef> + + +TestCase test_slice{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + constexpr auto foldable = ::seq; + + struct undefined { }; + + ////////////////////////////////////////////////////////////////////////// + // Test with arbitrary indices + ////////////////////////////////////////////////////////////////////////// + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(), + foldable()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}), + foldable()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, undefined{}), + foldable()), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}), + foldable(hana::size_c<0>)), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, undefined{}), + foldable(hana::size_c<0>)), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, ct_eq<1>{}), + foldable(hana::size_c<1>)), + MAKE_TUPLE(ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + foldable(hana::size_c<0>, hana::size_c<1>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + foldable(hana::size_c<1>, hana::size_c<0>)), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + foldable(hana::size_c<0>, hana::size_c<0>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + foldable(hana::size_c<1>, hana::size_c<1>)), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + foldable(hana::size_c<0>, hana::size_c<1>, hana::size_c<2>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + foldable(hana::size_c<0>, hana::size_c<2>, hana::size_c<1>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + foldable(hana::size_c<0>, hana::size_c<2>, hana::size_c<1>, hana::size_c<0>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + foldable(hana::size_c<0>, hana::size_c<2>, hana::size_c<1>, hana::size_c<0>, hana::size_c<1>)), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<2>{}, ct_eq<1>{}, ct_eq<0>{}, ct_eq<1>{}) + )); + + // Try with a tuple_c + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + hana::tuple_c<unsigned, 1, 3, 2>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<3>{}, ct_eq<2>{}) + )); + + + + ////////////////////////////////////////////////////////////////////////// + // Test with a `range` (check the optimization for contiguous indices) + ////////////////////////////////////////////////////////////////////////// + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(), + hana::range_c<std::size_t, 0, 0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}), + hana::range_c<std::size_t, 0, 0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, undefined{}), + hana::range_c<std::size_t, 0, 0>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}), + hana::range_c<std::size_t, 0, 1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, undefined{}), + hana::range_c<std::size_t, 0, 1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, ct_eq<1>{}), + hana::range_c<std::size_t, 1, 2>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, ct_eq<1>{}, undefined{}), + hana::range_c<std::size_t, 1, 2>), + MAKE_TUPLE(ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + hana::range_c<std::size_t, 0, 2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, undefined{}), + hana::range_c<std::size_t, 0, 2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, ct_eq<1>{}, ct_eq<2>{}), + hana::range_c<std::size_t, 1, 3>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::slice(MAKE_TUPLE(undefined{}, ct_eq<1>{}, ct_eq<2>{}, undefined{}), + hana::range_c<std::size_t, 1, 3>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_SLICE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/sort.hpp b/src/boost/libs/hana/test/_include/auto/sort.hpp new file mode 100644 index 000000000..398584fef --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/sort.hpp @@ -0,0 +1,111 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_SORT_HPP +#define BOOST_HANA_TEST_AUTO_SORT_HPP + +#include <boost/hana/all_of.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/less.hpp> +#include <boost/hana/permutations.hpp> +#include <boost/hana/sort.hpp> +#include <boost/hana/transform.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/equivalence_class.hpp> + + +TestCase test_sort{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + using hana::test::ct_ord; + + // Test without a custom predicate + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(ct_ord<0>{})), + MAKE_TUPLE(ct_ord<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{})), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(ct_ord<1>{}, ct_ord<0>{})), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(ct_ord<1>{}, ct_ord<0>{}, ct_ord<4>{}, ct_ord<2>{})), + MAKE_TUPLE(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, ct_ord<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(ct_ord<1>{}, ct_ord<0>{}, ct_ord<-4>{}, ct_ord<2>{})), + MAKE_TUPLE(ct_ord<-4>{}, ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}) + )); + } + + // Test with a custom predicate + { + auto pred = [](auto x, auto y) { + return hana::less(x.unwrap, y.unwrap); + }; + auto a = [](auto z) { return ::equivalence_class(ct_eq<999>{}, z); }; + auto b = [](auto z) { return ::equivalence_class(ct_eq<888>{}, z); }; + + auto check = [=](auto ...sorted) { + auto perms = hana::transform( + hana::permutations(MAKE_TUPLE(a(sorted)...)), + hana::sort.by(pred) + ); + BOOST_HANA_CONSTANT_CHECK(hana::all_of(perms, [=](auto xs) { + return hana::equal(xs, MAKE_TUPLE(a(sorted)...)); + })); + }; + + check(); + check(ct_ord<1>{}); + check(ct_ord<1>{}, ct_ord<2>{}); + check(ct_ord<1>{}, ct_ord<2>{}, ct_ord<3>{}); + + // check stability + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{})), pred), + MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(b(ct_ord<1>{}), a(ct_ord<1>{})), pred), + MAKE_TUPLE(b(ct_ord<1>{}), a(ct_ord<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})), pred), + MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(a(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<1>{}), b(ct_ord<2>{})), pred), + MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(b(ct_ord<1>{}), a(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})), pred), + MAKE_TUPLE(b(ct_ord<1>{}), a(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(a(ct_ord<2>{}), b(ct_ord<1>{}), b(ct_ord<2>{}), a(ct_ord<1>{})), pred), + MAKE_TUPLE(b(ct_ord<1>{}), a(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sort(MAKE_TUPLE(a(ct_ord<1>{}), a(ct_ord<3>{}), b(ct_ord<1>{}), a(ct_ord<2>{}), b(ct_ord<3>{})), pred), + MAKE_TUPLE(a(ct_ord<1>{}), b(ct_ord<1>{}), a(ct_ord<2>{}), a(ct_ord<3>{}), b(ct_ord<3>{})) + )); + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_SORT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/span.hpp b/src/boost/libs/hana/test/_include/auto/span.hpp new file mode 100644 index 000000000..1a15d408b --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/span.hpp @@ -0,0 +1,84 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_SPAN_HPP +#define BOOST_HANA_TEST_AUTO_SPAN_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/span.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/minimal_product.hpp> + + +TestCase test_span{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto z = ct_eq<999>{}; + auto pair = ::minimal_product; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE()) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(ct_eq<0>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(z), hana::equal.to(z)), + pair(MAKE_TUPLE(z), MAKE_TUPLE()) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(ct_eq<0>{}, z), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, z)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(z, ct_eq<0>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(z), MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(z, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(z), MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<2>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(), MAKE_TUPLE(ct_eq<0>{}, z, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(z, z, ct_eq<2>{}), hana::equal.to(z)), + pair(MAKE_TUPLE(z, z), MAKE_TUPLE(ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span(MAKE_TUPLE(z, z, z), hana::equal.to(z)), + pair(MAKE_TUPLE(z, z, z), MAKE_TUPLE()) + )); + + // span.by + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span.by(hana::equal.to(z), MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + hana::span(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(z)) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::span.by(hana::equal.to(z))(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + hana::span(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(z)) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_SPAN_HPP diff --git a/src/boost/libs/hana/test/_include/auto/take_back.hpp b/src/boost/libs/hana/test/_include/auto/take_back.hpp new file mode 100644 index 000000000..11a795e00 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/take_back.hpp @@ -0,0 +1,82 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_TAKE_BACK_HPP +#define BOOST_HANA_TEST_AUTO_TAKE_BACK_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/take_back.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_take_back{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::size_c<3>), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_back(MAKE_TUPLE( + ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, + ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}), + hana::size_c<5>), + MAKE_TUPLE(ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_TAKE_BACK_HPP diff --git a/src/boost/libs/hana/test/_include/auto/take_front.hpp b/src/boost/libs/hana/test/_include/auto/take_front.hpp new file mode 100644 index 000000000..5e9b67338 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/take_front.hpp @@ -0,0 +1,77 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_TAKE_FRONT_HPP +#define BOOST_HANA_TEST_AUTO_TAKE_FRONT_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/take_front.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_take{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(), hana::size_c<1>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(), hana::size_c<2>), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}), hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<0>), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<1>), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<2>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), hana::size_c<3>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_front(MAKE_TUPLE( + ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, ct_eq<5>{}, ct_eq<6>{}, + ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}, ct_eq<10>{}, ct_eq<11>{}, ct_eq<12>{}, ct_eq<13>{}), + hana::size_c<10>), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, + ct_eq<5>{}, ct_eq<6>{}, ct_eq<7>{}, ct_eq<8>{}, ct_eq<9>{}) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_TAKE_FRONT_HPP diff --git a/src/boost/libs/hana/test/_include/auto/take_while.hpp b/src/boost/libs/hana/test/_include/auto/take_while.hpp new file mode 100644 index 000000000..72d0b8b11 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/take_while.hpp @@ -0,0 +1,68 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_TAKE_WHILE_HPP +#define BOOST_HANA_TEST_AUTO_TAKE_WHILE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not_equal.hpp> +#include <boost/hana/take_while.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_take_while{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto z = ct_eq<999>{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(), hana::not_equal.to(z)), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(z), hana::not_equal.to(z)), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}, z), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(z, ct_eq<2>{}), hana::not_equal.to(z)), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, z), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(ct_eq<1>{}, z, ct_eq<3>{}), hana::not_equal.to(z)), + MAKE_TUPLE(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::take_while(MAKE_TUPLE(z, ct_eq<2>{}, ct_eq<3>{}), hana::not_equal.to(z)), + MAKE_TUPLE() + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_TAKE_WHILE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/test_case.hpp b/src/boost/libs/hana/test/_include/auto/test_case.hpp new file mode 100644 index 000000000..03de19ac0 --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/test_case.hpp @@ -0,0 +1,13 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_TEST_CASE_HPP +#define BOOST_HANA_TEST_AUTO_TEST_CASE_HPP + +struct TestCase { + template <typename F> + explicit TestCase(F const& f) { f(); } +}; + +#endif // !BOOST_HANA_TEST_AUTO_TEST_CASE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/transform.hpp b/src/boost/libs/hana/test/_include/auto/transform.hpp new file mode 100644 index 000000000..478d725ac --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/transform.hpp @@ -0,0 +1,74 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_TRANSFORM_HPP +#define BOOST_HANA_TEST_AUTO_TRANSFORM_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/transform.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> + + +TestCase test_transform{[] { + namespace hana = boost::hana; + using hana::test::ct_eq; + struct undefined { }; + constexpr hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(MAKE_TUPLE(ct_eq<1>{}), f), + MAKE_TUPLE(f(ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), f), + MAKE_TUPLE(f(ct_eq<1>{}), f(ct_eq<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), f), + MAKE_TUPLE(f(ct_eq<1>{}), f(ct_eq<2>{}), f(ct_eq<3>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), f), + MAKE_TUPLE(f(ct_eq<1>{}), f(ct_eq<2>{}), f(ct_eq<3>{}), f(ct_eq<4>{})) + )); + +#ifndef MAKE_TUPLE_NO_CONSTEXPR + struct incr { + constexpr int operator()(int i) const { return i + 1; } + }; + + static_assert(hana::equal( + hana::transform(MAKE_TUPLE(1), incr{}), + MAKE_TUPLE(2) + ), ""); + + static_assert(hana::equal( + hana::transform(MAKE_TUPLE(1, 2), incr{}), + MAKE_TUPLE(2, 3) + ), ""); + + static_assert(hana::equal( + hana::transform(MAKE_TUPLE(1, 2, 3), incr{}), + MAKE_TUPLE(2, 3, 4) + ), ""); + + static_assert(hana::equal( + hana::transform(MAKE_TUPLE(1, 2, 3, 4), incr{}), + MAKE_TUPLE(2, 3, 4, 5) + ), ""); +#endif +}}; + +#endif // !BOOST_HANA_TEST_AUTO_TRANSFORM_HPP diff --git a/src/boost/libs/hana/test/_include/auto/unfolds.hpp b/src/boost/libs/hana/test/_include/auto/unfolds.hpp new file mode 100644 index 000000000..afa01d3fc --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/unfolds.hpp @@ -0,0 +1,170 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_UNFOLDS_HPP +#define BOOST_HANA_TEST_AUTO_UNFOLDS_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/fold_left.hpp> +#include <boost/hana/fold_right.hpp> +#include <boost/hana/if.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/plus.hpp> +#include <boost/hana/unfold_left.hpp> +#include <boost/hana/unfold_right.hpp> + +#include <laws/base.hpp> +#include <support/minimal_product.hpp> +#include "test_case.hpp" + + +TestCase test_unfold_left{[]{ + namespace hana = boost::hana; + + hana::test::_injection<0> f{}; + auto stop_at = [=](auto stop) { + return [=](auto x) { + return hana::if_(hana::equal(stop, x), + hana::nothing, + hana::just(::minimal_product(x + hana::int_c<1>, f(x))) + ); + }; + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<0>)), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<1>)), + MAKE_TUPLE(f(hana::int_c<0>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<2>)), + MAKE_TUPLE(f(hana::int_c<1>), f(hana::int_c<0>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<3>)), + MAKE_TUPLE(f(hana::int_c<2>), f(hana::int_c<1>), f(hana::int_c<0>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<4>)), + MAKE_TUPLE(f(hana::int_c<3>), f(hana::int_c<2>), f(hana::int_c<1>), f(hana::int_c<0>)) + )); +}}; + + +TestCase test_unfold_right{[]{ + namespace hana = boost::hana; + + hana::test::_injection<0> f{}; + auto stop_at = [=](auto stop) { + return [=](auto x) { + return hana::if_(hana::equal(stop, x), + hana::nothing, + hana::just(::minimal_product(f(x), x + hana::int_c<1>)) + ); + }; + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<0>)), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<1>)), + MAKE_TUPLE(f(hana::int_c<0>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<2>)), + MAKE_TUPLE(f(hana::int_c<0>), f(hana::int_c<1>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<3>)), + MAKE_TUPLE(f(hana::int_c<0>), f(hana::int_c<1>), f(hana::int_c<2>)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::int_c<0>, stop_at(hana::int_c<4>)), + MAKE_TUPLE(f(hana::int_c<0>), f(hana::int_c<1>), f(hana::int_c<2>), f(hana::int_c<3>)) + )); +}}; + +// Make sure unfolds can be reversed under certain conditions. +TestCase test_unfold_undo{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + auto z = ct_eq<999>{}; + auto f = ::minimal_product; + auto g = [=](auto k) { + return hana::if_(hana::equal(k, z), + hana::nothing, + hana::just(k) + ); + }; + + // Make sure the special conditions are met + BOOST_HANA_CONSTANT_CHECK(hana::equal( + g(z), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + g(f(ct_eq<0>{}, z)), + hana::just(::minimal_product(ct_eq<0>{}, z)) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + g(f(z, ct_eq<0>{})), + hana::just(::minimal_product(z, ct_eq<0>{})) + )); + + // Make sure the reversing works + { + auto xs = MAKE_TUPLE(); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::fold_left(xs, z, f), g), + xs + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::fold_right(xs, z, f), g), + xs + )); + } + { + auto xs = MAKE_TUPLE(ct_eq<0>{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::fold_left(xs, z, f), g), + xs + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::fold_right(xs, z, f), g), + xs + )); + } + { + auto xs = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::fold_left(xs, z, f), g), + xs + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::fold_right(xs, z, f), g), + xs + )); + } + { + auto xs = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_left<TUPLE_TAG>(hana::fold_left(xs, z, f), g), + xs + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unfold_right<TUPLE_TAG>(hana::fold_right(xs, z, f), g), + xs + )); + } +}}; + +#endif // !BOOST_HANA_TEST_AUTO_UNFOLDS_HPP diff --git a/src/boost/libs/hana/test/_include/auto/unique.hpp b/src/boost/libs/hana/test/_include/auto/unique.hpp new file mode 100644 index 000000000..8ef7076fb --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/unique.hpp @@ -0,0 +1,158 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_UNIQUE_HPP +#define BOOST_HANA_TEST_AUTO_UNIQUE_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/unique.hpp> + +#include "test_case.hpp" +#include <laws/base.hpp> +#include <support/equivalence_class.hpp> + + +TestCase test_unique{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE()), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<1>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE( + ct_eq<0>{}, ct_eq<0>{}, + ct_eq<1>{}, + ct_eq<2>{}, ct_eq<2>{}, ct_eq<2>{}, + ct_eq<3>{}, ct_eq<3>{}, ct_eq<3>{}, + ct_eq<0>{})), + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<0>{}) + )); +}}; + +TestCase test_unique_by{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + struct undefined { }; + + auto a = [](auto z) { return ::equivalence_class(ct_eq<999>{}, z); }; + auto b = [](auto z) { return ::equivalence_class(ct_eq<888>{}, z); }; + auto c = [](auto z) { return ::equivalence_class(ct_eq<777>{}, z); }; + + auto pred = [](auto x, auto y) { + return hana::equal(x.unwrap, y.unwrap); + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(), undefined{}), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), c(ct_eq<0>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), c(ct_eq<1>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), c(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<0>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<1>{}), b(ct_eq<1>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique(MAKE_TUPLE( + a(ct_eq<0>{}), b(ct_eq<0>{}), + a(ct_eq<1>{}), + a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}), + a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}), + a(ct_eq<0>{})), pred), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{})) + )); + + // unique.by + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique.by(pred, MAKE_TUPLE( + a(ct_eq<0>{}), b(ct_eq<0>{}), + a(ct_eq<1>{}), + a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}), + a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}), + a(ct_eq<0>{}))), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unique.by(pred)(MAKE_TUPLE( + a(ct_eq<0>{}), b(ct_eq<0>{}), + a(ct_eq<1>{}), + a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}), + a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}), + a(ct_eq<0>{}))), + MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{})) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_UNIQUE_HPP diff --git a/src/boost/libs/hana/test/_include/auto/zips.hpp b/src/boost/libs/hana/test/_include/auto/zips.hpp new file mode 100644 index 000000000..3d129c90d --- /dev/null +++ b/src/boost/libs/hana/test/_include/auto/zips.hpp @@ -0,0 +1,342 @@ +// 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) + +#ifndef BOOST_HANA_TEST_AUTO_ZIPS_HPP +#define BOOST_HANA_TEST_AUTO_ZIPS_HPP + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/zip.hpp> +#include <boost/hana/zip_shortest.hpp> +#include <boost/hana/zip_shortest_with.hpp> +#include <boost/hana/zip_with.hpp> + +#include <laws/base.hpp> +#include "test_case.hpp" + + +TestCase test_zip_shortest_with{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + hana::test::_injection<0> f{}; + auto zip = hana::zip_shortest_with; + struct undefined { }; + + // zip 1 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(f(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{}), f(ct_eq<2>{})) + )); + + // zip 2 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(undefined{}), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(undefined{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<-1>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), MAKE_TUPLE(ct_eq<-1>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{}), f(ct_eq<2>{}, ct_eq<-2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<-3>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{}), + f(ct_eq<2>{}, ct_eq<-2>{}), + f(ct_eq<3>{}, ct_eq<-3>{})) + )); + + // zip 3 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(undefined{}), MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(undefined{}), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(), MAKE_TUPLE(undefined{})), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(undefined{}), MAKE_TUPLE(undefined{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(undefined{}), MAKE_TUPLE(), MAKE_TUPLE(undefined{})), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(undefined{}, MAKE_TUPLE(undefined{}), MAKE_TUPLE(undefined{}), MAKE_TUPLE()), + MAKE_TUPLE() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})) + )); + + // zip 4 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, + MAKE_TUPLE(ct_eq<11>{}, ct_eq<12>{}, ct_eq<13>{}, ct_eq<14>{}), + MAKE_TUPLE(ct_eq<21>{}, ct_eq<22>{}, ct_eq<23>{}), + MAKE_TUPLE(ct_eq<31>{}, ct_eq<32>{}, ct_eq<33>{}, ct_eq<34>{}), + MAKE_TUPLE(ct_eq<41>{}, ct_eq<42>{}, ct_eq<43>{}, ct_eq<44>{}, ct_eq<45>{}) + ), + MAKE_TUPLE( + f(ct_eq<11>{}, ct_eq<21>{}, ct_eq<31>{}, ct_eq<41>{}), + f(ct_eq<12>{}, ct_eq<22>{}, ct_eq<32>{}, ct_eq<42>{}), + f(ct_eq<13>{}, ct_eq<23>{}, ct_eq<33>{}, ct_eq<43>{}) + ) + )); + + // zip 5 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + zip(f, + MAKE_TUPLE(ct_eq<11>{}, ct_eq<12>{}, ct_eq<13>{}, ct_eq<14>{}), + MAKE_TUPLE(ct_eq<21>{}, ct_eq<22>{}, ct_eq<23>{}, ct_eq<24>{}, ct_eq<25>{}), + MAKE_TUPLE(ct_eq<31>{}, ct_eq<32>{}, ct_eq<33>{}, ct_eq<34>{}), + MAKE_TUPLE(ct_eq<41>{}, ct_eq<42>{}, ct_eq<43>{}, ct_eq<44>{}, ct_eq<45>{}, ct_eq<46>{}), + MAKE_TUPLE(ct_eq<51>{}, ct_eq<52>{}, ct_eq<53>{}, ct_eq<54>{}, ct_eq<55>{}) + ), + MAKE_TUPLE( + f(ct_eq<11>{}, ct_eq<21>{}, ct_eq<31>{}, ct_eq<41>{}, ct_eq<51>{}), + f(ct_eq<12>{}, ct_eq<22>{}, ct_eq<32>{}, ct_eq<42>{}, ct_eq<52>{}), + f(ct_eq<13>{}, ct_eq<23>{}, ct_eq<33>{}, ct_eq<43>{}, ct_eq<53>{}), + f(ct_eq<14>{}, ct_eq<24>{}, ct_eq<34>{}, ct_eq<44>{}, ct_eq<54>{}) + ) + )); +}}; + +TestCase test_zip_with{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + hana::test::_injection<0> f{}; + struct undefined { }; + + // zip 1 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(undefined{}, MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(f(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}), f(ct_eq<1>{}), f(ct_eq<2>{})) + )); + + // zip 2 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(undefined{}, MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<-1>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}), MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{})), + MAKE_TUPLE(f(ct_eq<1>{}, ct_eq<-1>{}), f(ct_eq<2>{}, ct_eq<-2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, + MAKE_TUPLE(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<-1>{}, ct_eq<-2>{}, ct_eq<-3>{})), + MAKE_TUPLE( + f(ct_eq<1>{}, ct_eq<-1>{}), + f(ct_eq<2>{}, ct_eq<-2>{}), + f(ct_eq<3>{}, ct_eq<-3>{})) + )); + + // zip 3 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(undefined{}, MAKE_TUPLE(), MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<2>{})), + MAKE_TUPLE(f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, + MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<4>{}, ct_eq<5>{}) + ), + MAKE_TUPLE( + f(ct_eq<0>{}, ct_eq<2>{}, ct_eq<4>{}), + f(ct_eq<1>{}, ct_eq<3>{}, ct_eq<5>{}) + ) + )); + + // zip 4 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, + MAKE_TUPLE(ct_eq<11>{}, ct_eq<12>{}, ct_eq<13>{}), + MAKE_TUPLE(ct_eq<21>{}, ct_eq<22>{}, ct_eq<23>{}), + MAKE_TUPLE(ct_eq<31>{}, ct_eq<32>{}, ct_eq<33>{}), + MAKE_TUPLE(ct_eq<41>{}, ct_eq<42>{}, ct_eq<43>{}) + ), + MAKE_TUPLE( + f(ct_eq<11>{}, ct_eq<21>{}, ct_eq<31>{}, ct_eq<41>{}), + f(ct_eq<12>{}, ct_eq<22>{}, ct_eq<32>{}, ct_eq<42>{}), + f(ct_eq<13>{}, ct_eq<23>{}, ct_eq<33>{}, ct_eq<43>{}) + ) + )); + + // zip 5 + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_with(f, + MAKE_TUPLE(ct_eq<11>{}, ct_eq<12>{}, ct_eq<13>{}, ct_eq<14>{}), + MAKE_TUPLE(ct_eq<21>{}, ct_eq<22>{}, ct_eq<23>{}, ct_eq<24>{}), + MAKE_TUPLE(ct_eq<31>{}, ct_eq<32>{}, ct_eq<33>{}, ct_eq<34>{}), + MAKE_TUPLE(ct_eq<41>{}, ct_eq<42>{}, ct_eq<43>{}, ct_eq<44>{}), + MAKE_TUPLE(ct_eq<51>{}, ct_eq<52>{}, ct_eq<53>{}, ct_eq<54>{}) + ), + MAKE_TUPLE( + f(ct_eq<11>{}, ct_eq<21>{}, ct_eq<31>{}, ct_eq<41>{}, ct_eq<51>{}), + f(ct_eq<12>{}, ct_eq<22>{}, ct_eq<32>{}, ct_eq<42>{}, ct_eq<52>{}), + f(ct_eq<13>{}, ct_eq<23>{}, ct_eq<33>{}, ct_eq<43>{}, ct_eq<53>{}), + f(ct_eq<14>{}, ct_eq<24>{}, ct_eq<34>{}, ct_eq<44>{}, ct_eq<54>{}) + ) + )); +}}; + +TestCase test_zip{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<2>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip(MAKE_TUPLE(ct_eq<0>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<4>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<5>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<4>{}, ct_eq<5>{})) + )); +}}; + +TestCase test_zip_shortest{[]{ + namespace hana = boost::hana; + using hana::test::ct_eq; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{}), MAKE_TUPLE(ct_eq<2>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(), MAKE_TUPLE()), + MAKE_TUPLE() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{}), MAKE_TUPLE(ct_eq<1>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{}), + MAKE_TUPLE(ct_eq<1>{}), + MAKE_TUPLE(ct_eq<2>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zip_shortest(MAKE_TUPLE(ct_eq<0>{}, ct_eq<3>{}), + MAKE_TUPLE(ct_eq<1>{}, ct_eq<4>{}), + MAKE_TUPLE(ct_eq<2>{}, ct_eq<5>{}, ct_eq<8>{})), + MAKE_TUPLE(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), + MAKE_TUPLE(ct_eq<3>{}, ct_eq<4>{}, ct_eq<5>{})) + )); +}}; + +#endif // !BOOST_HANA_TEST_AUTO_ZIPS_HPP |