From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../libs/hana/test/concept/constant/arithmetic.cpp | 29 ++++ .../libs/hana/test/concept/constant/comparable.cpp | 23 +++ src/boost/libs/hana/test/concept/constant/laws.cpp | 25 +++ .../libs/hana/test/concept/constant/logical.cpp | 191 +++++++++++++++++++++ src/boost/libs/hana/test/concept/constant/mcd.cpp | 31 ++++ .../libs/hana/test/concept/constant/minimal.hpp | 45 +++++ .../libs/hana/test/concept/constant/orderable.cpp | 23 +++ src/boost/libs/hana/test/concept/constant/to.cpp | 21 +++ .../libs/hana/test/concept/integral_constant.cpp | 52 ++++++ .../libs/hana/test/concept/sequence/iterable.cpp | 6 + .../libs/hana/test/concept/sequence/monad.cpp | 6 + .../libs/hana/test/concept/sequence/monad_plus.cpp | 6 + .../libs/hana/test/concept/sequence/orderable.cpp | 6 + .../libs/hana/test/concept/sequence/searchable.cpp | 6 + .../libs/hana/test/concept/sequence/sequence.cpp | 6 + src/boost/libs/hana/test/concept/struct/any_of.cpp | 46 +++++ src/boost/libs/hana/test/concept/struct/at_key.cpp | 55 ++++++ src/boost/libs/hana/test/concept/struct/equal.cpp | 47 +++++ .../libs/hana/test/concept/struct/find_if.cpp | 48 ++++++ .../libs/hana/test/concept/struct/fold_left.cpp | 59 +++++++ .../libs/hana/test/concept/struct/fold_right.cpp | 59 +++++++ src/boost/libs/hana/test/concept/struct/keys.cpp | 46 +++++ src/boost/libs/hana/test/concept/struct/laws.cpp | 43 +++++ .../hana/test/concept/struct/macro.adapt_adt.cpp | 61 +++++++ .../test/concept/struct/macro.adapt_struct.cpp | 58 +++++++ .../test/concept/struct/macro.define_struct.cpp | 57 ++++++ .../hana/test/concept/struct/member_function.cpp | 43 +++++ .../libs/hana/test/concept/struct/members.cpp | 51 ++++++ .../hana/test/concept/struct/minimal_struct.hpp | 54 ++++++ src/boost/libs/hana/test/concept/struct/unpack.cpp | 44 +++++ 30 files changed, 1247 insertions(+) create mode 100644 src/boost/libs/hana/test/concept/constant/arithmetic.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/comparable.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/laws.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/logical.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/mcd.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/minimal.hpp create mode 100644 src/boost/libs/hana/test/concept/constant/orderable.cpp create mode 100644 src/boost/libs/hana/test/concept/constant/to.cpp create mode 100644 src/boost/libs/hana/test/concept/integral_constant.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/iterable.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/monad.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/monad_plus.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/orderable.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/searchable.cpp create mode 100644 src/boost/libs/hana/test/concept/sequence/sequence.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/any_of.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/at_key.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/equal.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/find_if.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/fold_left.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/fold_right.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/keys.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/laws.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/macro.adapt_adt.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/macro.adapt_struct.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/macro.define_struct.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/member_function.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/members.cpp create mode 100644 src/boost/libs/hana/test/concept/struct/minimal_struct.hpp create mode 100644 src/boost/libs/hana/test/concept/struct/unpack.cpp (limited to 'src/boost/libs/hana/test/concept') diff --git a/src/boost/libs/hana/test/concept/constant/arithmetic.cpp b/src/boost/libs/hana/test/concept/constant/arithmetic.cpp new file mode 100644 index 00000000..e01403ba --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/arithmetic.cpp @@ -0,0 +1,29 @@ +// 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 "minimal.hpp" + +#include + +#include +#include +#include +#include +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{} + ); + + hana::test::TestMonoid>{ints}; + hana::test::TestGroup>{ints}; + hana::test::TestRing>{ints}; + hana::test::TestEuclideanRing>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/comparable.cpp b/src/boost/libs/hana/test/concept/constant/comparable.cpp new file mode 100644 index 00000000..697a2389 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/comparable.cpp @@ -0,0 +1,23 @@ +// 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 "minimal.hpp" + +#include + +#include +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{} + ); + + hana::test::TestComparable>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/laws.cpp b/src/boost/libs/hana/test/concept/constant/laws.cpp new file mode 100644 index 00000000..5b132e3f --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/laws.cpp @@ -0,0 +1,25 @@ +// 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 "minimal.hpp" + +#include + +#include +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{} + ); + + constexpr auto convertible_types = hana::tuple_t; + + hana::test::TestConstant>{ints, convertible_types}; +} diff --git a/src/boost/libs/hana/test/concept/constant/logical.cpp b/src/boost/libs/hana/test/concept/constant/logical.cpp new file mode 100644 index 00000000..980273aa --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/logical.cpp @@ -0,0 +1,191 @@ +// 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 "minimal.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +namespace hana = boost::hana; + + +struct invalid { }; + +int main() { + constexpr auto bools = hana::make_tuple( + minimal_constant{}, + minimal_constant{} + ); + + hana::test::TestLogical>{bools}; + + + constexpr auto true_ = minimal_constant{}; + constexpr auto false_ = minimal_constant{}; + + // not_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(true_), false_)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(false_), true_)); + } + + // and_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_, invalid{}), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, true_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(true_, false_, invalid{}), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::and_(false_, invalid{}, invalid{}), + false_ + )); + } + + // or_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_), + false_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_, invalid{}), + true_ + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_, false_), + false_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, false_, true_), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(false_, true_, invalid{}), + true_ + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::or_(true_, invalid{}, invalid{}), + true_ + )); + } + + // if_ + { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::if_(true_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}), + hana::test::ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::if_(false_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}), + hana::test::ct_eq<4>{} + )); + } + + // eval_if + { + auto t = [](auto) { return hana::test::ct_eq<2>{}; }; + auto e = [](auto) { return hana::test::ct_eq<3>{}; }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::eval_if(true_, t, invalid{}), + hana::test::ct_eq<2>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::eval_if(false_, invalid{}, e), + hana::test::ct_eq<3>{} + )); + } + + // while_ + { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(hana::test::ct_eq<0>{}), hana::test::ct_eq<0>{}, invalid{}), + hana::test::ct_eq<0>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(hana::test::ct_eq<0>{})), hana::test::ct_eq<0>{}, f), + f(hana::test::ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(hana::test::ct_eq<0>{}))), hana::test::ct_eq<0>{}, f), + f(f(hana::test::ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(hana::test::ct_eq<0>{})))), hana::test::ct_eq<0>{}, f), + f(f(f(hana::test::ct_eq<0>{}))) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), hana::test::ct_eq<0>{}, f), + f(f(f(f(hana::test::ct_eq<0>{})))) + )); + + // Make sure it can be called with an lvalue state: + auto state = hana::test::ct_eq<0>{}; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), state, f), + f(f(f(f(hana::test::ct_eq<0>{})))) + )); + } +} diff --git a/src/boost/libs/hana/test/concept/constant/mcd.cpp b/src/boost/libs/hana/test/concept/constant/mcd.cpp new file mode 100644 index 00000000..f45327cd --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/mcd.cpp @@ -0,0 +1,31 @@ +// 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 "minimal.hpp" + +#include +#include +namespace hana = boost::hana; + + +// Make sure we really satisfy Constant. +static_assert(hana::Constant>::value, ""); +static_assert(hana::Constant>::value, ""); +static_assert(hana::Constant>::value, ""); +static_assert(hana::Constant>::value, ""); + +// Make sure we can use hana::value<> properly. +static_assert(hana::value>() == 0, ""); +static_assert(hana::value>() == 1, ""); +static_assert(hana::value>() == 2, ""); +static_assert(hana::value>() == 3, ""); + +// Check the equivalence between `value(...)` and `value()`. +static_assert(hana::value(minimal_constant{}) == hana::value>(), ""); +static_assert(hana::value(minimal_constant{}) == hana::value>(), ""); +static_assert(hana::value(minimal_constant{}) == hana::value>(), ""); +static_assert(hana::value(minimal_constant{}) == hana::value>(), ""); + + +int main() { } diff --git a/src/boost/libs/hana/test/concept/constant/minimal.hpp b/src/boost/libs/hana/test/concept/constant/minimal.hpp new file mode 100644 index 00000000..ebc2ae11 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/minimal.hpp @@ -0,0 +1,45 @@ +// 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 TEST_CONCEPT_CONSTANT_MINIMAL_HPP +#define TEST_CONCEPT_CONSTANT_MINIMAL_HPP + +#include +#include +#include +#include + + +template +struct minimal_constant_tag { + using value_type = T; +}; + +template +struct minimal_constant { + using hana_tag = minimal_constant_tag; + static constexpr T value_ = v; +}; + +namespace boost { namespace hana { + template + struct value_impl> { + template + static constexpr T apply() { return N::value_; } + }; + + template + struct to_impl, C, hana::when< + hana::Constant::value && + hana::is_convertible::value + >> + : hana::embedding::value> + { + template + static constexpr auto apply(N const&) + { return minimal_constant()>{}; } + }; +}} // end namespace boost::hana + +#endif // !TEST_CONCEPT_CONSTANT_MINIMAL_HPP diff --git a/src/boost/libs/hana/test/concept/constant/orderable.cpp b/src/boost/libs/hana/test/concept/constant/orderable.cpp new file mode 100644 index 00000000..08aba261 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/orderable.cpp @@ -0,0 +1,23 @@ +// 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 "minimal.hpp" + +#include + +#include +namespace hana = boost::hana; + + +int main() { + constexpr auto ints = hana::make_tuple( + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{}, + minimal_constant{} + ); + + hana::test::TestOrderable>{ints}; +} diff --git a/src/boost/libs/hana/test/concept/constant/to.cpp b/src/boost/libs/hana/test/concept/constant/to.cpp new file mode 100644 index 00000000..8500b1d9 --- /dev/null +++ b/src/boost/libs/hana/test/concept/constant/to.cpp @@ -0,0 +1,21 @@ +// 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 "minimal.hpp" + +#include +#include +namespace hana = boost::hana; + + +static_assert(hana::is_convertible, bool>::value, ""); +static_assert(hana::to(minimal_constant{}) == true, ""); + +static_assert(hana::is_convertible, int>::value, ""); +static_assert(hana::to(minimal_constant{}) == 1, ""); + +static_assert(hana::is_convertible, long>::value, ""); +static_assert(hana::to(minimal_constant{}) == 1l, ""); + +int main() { } diff --git a/src/boost/libs/hana/test/concept/integral_constant.cpp b/src/boost/libs/hana/test/concept/integral_constant.cpp new file mode 100644 index 00000000..ad69759f --- /dev/null +++ b/src/boost/libs/hana/test/concept/integral_constant.cpp @@ -0,0 +1,52 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +namespace hana = boost::hana; + + +// Define a simple model of IntegralConstant +struct constant_tag { using value_type = int; }; +template +struct constant { + static constexpr int value = i; + using hana_tag = constant_tag; +}; + +namespace boost { namespace hana { + template <> + struct IntegralConstant { + static constexpr bool value = true; + }; + + template + struct to_impl::value>> { + template + static constexpr auto apply(N const&) + { return constant{}; } + }; +}} + +// Make sure we really satisfy IntegralConstant<>. +static_assert(hana::IntegralConstant>::value, ""); +static_assert(hana::IntegralConstant>::value, ""); +static_assert(hana::IntegralConstant>::value, ""); + +// Make sure we're also a model of Constant automatically. +static_assert(hana::Constant>::value, ""); +static_assert(hana::Constant>::value, ""); +static_assert(hana::Constant>::value, ""); + +// Make sure we have the hana::value<> function defined automatically. +static_assert(hana::value>() == 0, ""); +static_assert(hana::value>() == 1, ""); +static_assert(hana::value>() == 2, ""); +static_assert(hana::value>() == 3, ""); + + +int main() { } diff --git a/src/boost/libs/hana/test/concept/sequence/iterable.cpp b/src/boost/libs/hana/test/concept/sequence/iterable.cpp new file mode 100644 index 00000000..75df0b1b --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/iterable.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_ITERABLE +#include diff --git a/src/boost/libs/hana/test/concept/sequence/monad.cpp b/src/boost/libs/hana/test/concept/sequence/monad.cpp new file mode 100644 index 00000000..8de1861f --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/monad.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_MONAD +#include diff --git a/src/boost/libs/hana/test/concept/sequence/monad_plus.cpp b/src/boost/libs/hana/test/concept/sequence/monad_plus.cpp new file mode 100644 index 00000000..3af644d2 --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/monad_plus.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_MONAD_PLUS +#include diff --git a/src/boost/libs/hana/test/concept/sequence/orderable.cpp b/src/boost/libs/hana/test/concept/sequence/orderable.cpp new file mode 100644 index 00000000..802ae289 --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/orderable.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_ORDERABLE +#include diff --git a/src/boost/libs/hana/test/concept/sequence/searchable.cpp b/src/boost/libs/hana/test/concept/sequence/searchable.cpp new file mode 100644 index 00000000..29a815cd --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/searchable.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_SEARCHABLE +#include diff --git a/src/boost/libs/hana/test/concept/sequence/sequence.cpp b/src/boost/libs/hana/test/concept/sequence/sequence.cpp new file mode 100644 index 00000000..2a096973 --- /dev/null +++ b/src/boost/libs/hana/test/concept/sequence/sequence.cpp @@ -0,0 +1,6 @@ +// 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) + +#define BOOST_HANA_TEST_SEQUENCE +#include diff --git a/src/boost/libs/hana/test/concept/struct/any_of.cpp b/src/boost/libs/hana/test/concept/struct/any_of.cpp new file mode 100644 index 00000000..8dd9082a --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/any_of.cpp @@ -0,0 +1,46 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +namespace hana = boost::hana; + + +template +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + obj(), + undefined<>{} + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + obj(undefined<0>{}), + hana::equal.to(hana::int_c<0>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + obj(undefined<0>{}), + hana::equal.to(hana::int_c<1>) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + obj(undefined<0>{}, undefined<1>{}), + hana::equal.to(hana::int_c<0>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + obj(undefined<0>{}, undefined<1>{}), + hana::equal.to(hana::int_c<1>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + obj(undefined<0>{}, undefined<1>{}), + hana::equal.to(hana::int_c<2>) + ))); +} diff --git a/src/boost/libs/hana/test/concept/struct/at_key.cpp b/src/boost/libs/hana/test/concept/struct/at_key.cpp new file mode 100644 index 00000000..2a9d757b --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/at_key.cpp @@ -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) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct Person { + BOOST_HANA_DEFINE_STRUCT(Person, + (std::string, name), + (std::string, last_name), + (int, age) + ); +}; + +int main() { + // non-const ref + { + Person john{"John", "Doe", 30}; + std::string& name = hana::at_key(john, BOOST_HANA_STRING("name")); + std::string& last_name = hana::at_key(john, BOOST_HANA_STRING("last_name")); + int& age = hana::at_key(john, BOOST_HANA_STRING("age")); + + name = "Bob"; + last_name = "Foo"; + age = 99; + + BOOST_HANA_RUNTIME_CHECK(john.name == "Bob"); + BOOST_HANA_RUNTIME_CHECK(john.last_name == "Foo"); + BOOST_HANA_RUNTIME_CHECK(john.age == 99); + } + + // const ref + { + Person john{"John", "Doe", 30}; + Person const& const_john = john; + std::string const& name = hana::at_key(const_john, BOOST_HANA_STRING("name")); + std::string const& last_name = hana::at_key(const_john, BOOST_HANA_STRING("last_name")); + int const& age = hana::at_key(const_john, BOOST_HANA_STRING("age")); + + john.name = "Bob"; + john.last_name = "Foo"; + john.age = 99; + + BOOST_HANA_RUNTIME_CHECK(name == "Bob"); + BOOST_HANA_RUNTIME_CHECK(last_name == "Foo"); + BOOST_HANA_RUNTIME_CHECK(age == 99); + } +} diff --git a/src/boost/libs/hana/test/concept/struct/equal.cpp b/src/boost/libs/hana/test/concept/struct/equal.cpp new file mode 100644 index 00000000..3bd91689 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/equal.cpp @@ -0,0 +1,47 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + obj(), + obj() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + obj(ct_eq<0>{}), + obj(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + obj(ct_eq<0>{}), + obj(ct_eq<1>{}) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + obj(ct_eq<0>{}, ct_eq<1>{}), + obj(ct_eq<0>{}, ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + obj(ct_eq<1>{}, ct_eq<0>{}), + obj(ct_eq<0>{}, ct_eq<1>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + obj(ct_eq<0>{}, ct_eq<99>{}), + obj(ct_eq<0>{}, ct_eq<1>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + obj(ct_eq<99>{}, ct_eq<1>{}), + obj(ct_eq<0>{}, ct_eq<1>{}) + ))); +} diff --git a/src/boost/libs/hana/test/concept/struct/find_if.cpp b/src/boost/libs/hana/test/concept/struct/find_if.cpp new file mode 100644 index 00000000..3e249239 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/find_if.cpp @@ -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) + +#include +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +template +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(), undefined<>{}), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(ct_eq<0>{}), hana::equal.to(hana::int_c<0>)), + hana::just(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(undefined<1>{}), hana::equal.to(hana::int_c<1>)), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(ct_eq<0>{}, ct_eq<1>{}), hana::equal.to(hana::int_c<0>)), + hana::just(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(ct_eq<0>{}, ct_eq<1>{}), hana::equal.to(hana::int_c<1>)), + hana::just(ct_eq<1>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(obj(undefined<0>{}, undefined<1>{}), hana::equal.to(hana::int_c<2>)), + hana::nothing + )); +} diff --git a/src/boost/libs/hana/test/concept/struct/fold_left.cpp b/src/boost/libs/hana/test/concept/struct/fold_left.cpp new file mode 100644 index 00000000..f7b63814 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/fold_left.cpp @@ -0,0 +1,59 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +template +struct undefined { }; + +struct MoveOnly { + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; + MoveOnly(MoveOnly const&) = delete; + MoveOnly& operator=(MoveOnly&&) = default; + MoveOnly& operator=(MoveOnly const&) = delete; +}; + +int main() { + constexpr auto pair = ::minimal_product; + ct_eq<999> s{}; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(obj(), s, undefined<>{}), + s + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(obj(ct_eq<0>{}), s, f), + f(s, pair(hana::int_c<0>, ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(obj(ct_eq<0>{}, ct_eq<1>{}), s, f), + f(f(s, pair(hana::int_c<0>, ct_eq<0>{})), pair(hana::int_c<1>, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(obj(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f), + f(f(f(s, pair(hana::int_c<0>, ct_eq<0>{})), + pair(hana::int_c<1>, ct_eq<1>{})), + pair(hana::int_c<2>, ct_eq<2>{})) + )); + + // fold_left with move-only members + hana::fold_left(obj(MoveOnly{}), 0, [](int, auto) { return 0; }); + hana::fold_left(obj(MoveOnly{}, MoveOnly{}), 0, [](int, auto) { return 0; }); +} diff --git a/src/boost/libs/hana/test/concept/struct/fold_right.cpp b/src/boost/libs/hana/test/concept/struct/fold_right.cpp new file mode 100644 index 00000000..3db67def --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/fold_right.cpp @@ -0,0 +1,59 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +template +struct undefined { }; + +struct MoveOnly { + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; + MoveOnly(MoveOnly const&) = delete; + MoveOnly& operator=(MoveOnly&&) = default; + MoveOnly& operator=(MoveOnly const&) = delete; +}; + +int main() { + constexpr auto pair = ::minimal_product; + ct_eq<999> s{}; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(obj(), s, undefined<>{}), + s + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(obj(ct_eq<0>{}), s, f), + f(pair(hana::int_c<0>, ct_eq<0>{}), s) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(obj(ct_eq<0>{}, ct_eq<1>{}), s, f), + f(pair(hana::int_c<0>, ct_eq<0>{}), f(pair(hana::int_c<1>, ct_eq<1>{}), s)) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(obj(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f), + f(pair(hana::int_c<0>, ct_eq<0>{}), + f(pair(hana::int_c<1>, ct_eq<1>{}), + f(pair(hana::int_c<2>, ct_eq<2>{}), s))) + )); + + // fold_right with move-only members + hana::fold_right(obj(MoveOnly{}), 0, [](auto, int) { return 0; }); + hana::fold_right(obj(MoveOnly{}, MoveOnly{}), 0, [](auto, int) { return 0; }); +} diff --git a/src/boost/libs/hana/test/concept/struct/keys.cpp b/src/boost/libs/hana/test/concept/struct/keys.cpp new file mode 100644 index 00000000..c07de9e1 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/keys.cpp @@ -0,0 +1,46 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +template +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::keys(obj()), + ::seq() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::keys(obj(undefined<0>{})), + ::seq(hana::int_c<0>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::keys(obj(undefined<0>{}, undefined<1>{})), + ::seq(hana::int_c<0>, hana::int_c<1>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::keys(obj(undefined<0>{}, undefined<1>{}, undefined<2>{})), + ::seq(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::keys(obj(undefined<0>{}, undefined<1>{}, undefined<2>{}, undefined<3>{})), + ::seq(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>, hana::int_c<3>) + )); +} diff --git a/src/boost/libs/hana/test/concept/struct/laws.cpp b/src/boost/libs/hana/test/concept/struct/laws.cpp new file mode 100644 index 00000000..b10955db --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/laws.cpp @@ -0,0 +1,43 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + auto eq0 = hana::make_tuple(obj()); + auto eq1 = hana::make_tuple( + obj(ct_eq<0>{}), obj(ct_eq<1>{}), obj(ct_eq<2>{}) + ); + auto eq2 = hana::make_tuple( + obj(ct_eq<0>{}, ct_eq<0>{}), + obj(ct_eq<0>{}, ct_eq<1>{}), + obj(ct_eq<1>{}, ct_eq<0>{}), + obj(ct_eq<1>{}, ct_eq<1>{}), + obj(ct_eq<0>{}, ct_eq<2>{}), + obj(ct_eq<2>{}, ct_eq<3>{}) + ); + + hana::test::TestComparable>{eq0}; + hana::test::TestComparable>{eq1}; + hana::test::TestComparable>{eq2}; + + hana::test::TestFoldable>{eq0}; + hana::test::TestFoldable>{eq1}; + hana::test::TestFoldable>{eq2}; + + hana::test::TestSearchable>{eq0, hana::make_tuple()}; + hana::test::TestSearchable>{eq1, hana::make_tuple(hana::int_c<0>)}; + hana::test::TestSearchable>{eq2, hana::make_tuple(hana::int_c<0>, hana::int_c<1>)}; +} diff --git a/src/boost/libs/hana/test/concept/struct/macro.adapt_adt.cpp b/src/boost/libs/hana/test/concept/struct/macro.adapt_adt.cpp new file mode 100644 index 00000000..dc759b42 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/macro.adapt_adt.cpp @@ -0,0 +1,61 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +namespace ns { + struct Data0 { }; + struct Data1 { + ct_eq<1> get_member1() const { return {}; } + }; + struct Data2 { + ct_eq<1> get_member1() const { return {}; } + ct_eq<2> get_member2() const { return {}; } + }; + struct Data3 { + ct_eq<1> get_member1() const { return {}; } + ct_eq<2> get_member2() const { return {}; } + ct_eq<3> get_member3() const { return {}; } + }; +} + +// Note: We use commas in the lambdas to make sure the macro can handle it. +BOOST_HANA_ADAPT_ADT(ns::Data0); +BOOST_HANA_ADAPT_ADT(ns::Data1, + (member1, [](auto const& d) { return 0, d.get_member1(); }) +); +BOOST_HANA_ADAPT_ADT(ns::Data2, + (member1, [](auto const& d) { return 0, d.get_member1(); }), + (member2, [](auto const& d) { return d.get_member2(); }) +); +BOOST_HANA_ADAPT_ADT(ns::Data3, + (member1, [](auto const& d) { return 0, d.get_member1(); }), + (member2, [](auto const& d) { return d.get_member2(); }), + (member3, [](auto const& d) { return d.get_member3(); }) +); + +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data1{}, BOOST_HANA_STRING("member1"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data2{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data2{}, BOOST_HANA_STRING("member2"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member2"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member3"))); +} diff --git a/src/boost/libs/hana/test/concept/struct/macro.adapt_struct.cpp b/src/boost/libs/hana/test/concept/struct/macro.adapt_struct.cpp new file mode 100644 index 00000000..6aec33d5 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/macro.adapt_struct.cpp @@ -0,0 +1,58 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +namespace ns { + struct Data0 { }; + struct Data1 { + ct_eq<1> member1; + }; + struct Data2 { + ct_eq<1> member1; + ct_eq<2> member2; + }; + struct Data3 { + ct_eq<1> member1; + ct_eq<2> member2; + ct_eq<3> member3; + }; + struct MemberArray { + int array[10]; + }; +} + +BOOST_HANA_ADAPT_STRUCT(ns::Data0); +BOOST_HANA_ADAPT_STRUCT(ns::Data1, member1); +BOOST_HANA_ADAPT_STRUCT(ns::Data2, member1, member2); +BOOST_HANA_ADAPT_STRUCT(ns::Data3, member1, member2, member3); +BOOST_HANA_ADAPT_STRUCT(ns::MemberArray, array); + +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data1{}, BOOST_HANA_STRING("member1"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data2{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data2{}, BOOST_HANA_STRING("member2"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member2"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::Data3{}, BOOST_HANA_STRING("member3"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(ns::MemberArray{}, BOOST_HANA_STRING("array"))); +} diff --git a/src/boost/libs/hana/test/concept/struct/macro.define_struct.cpp b/src/boost/libs/hana/test/concept/struct/macro.define_struct.cpp new file mode 100644 index 00000000..29ddbfdd --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/macro.define_struct.cpp @@ -0,0 +1,57 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +// This allows us to make sure we can enter template types +// containing commas in the macro. +template +using commas = T; + +struct Data0 { + BOOST_HANA_DEFINE_STRUCT(Data0); +}; +struct Data1 { + BOOST_HANA_DEFINE_STRUCT(Data1, + (commas, void>, member1) + ); +}; +struct Data2 { + BOOST_HANA_DEFINE_STRUCT(Data2, + (commas, void, void>, member1), + (ct_eq<2>, member2) + ); +}; +struct Data3 { + BOOST_HANA_DEFINE_STRUCT(Data3, + (ct_eq<1>, member1), + (ct_eq<2>, member2), + (commas, void, void, void>, member3) + ); +}; + +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); +static_assert(hana::Struct::value, ""); + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data1{}, BOOST_HANA_STRING("member1"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data2{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data2{}, BOOST_HANA_STRING("member2"))); + + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member1"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member2"))); + BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member3"))); +} diff --git a/src/boost/libs/hana/test/concept/struct/member_function.cpp b/src/boost/libs/hana/test/concept/struct/member_function.cpp new file mode 100644 index 00000000..1e3ab6ec --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/member_function.cpp @@ -0,0 +1,43 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +// +// Unit test inspired by http://stackoverflow.com/q/32678647/627587 +// + +struct Foo { + std::string get_name() const { return "louis"; } +}; + +namespace boost { namespace hana { + template <> + struct accessors_impl { + static auto apply() { + return hana::make_tuple( + hana::make_pair(BOOST_HANA_STRING("get_name"), [](auto const& foo) { + return foo.get_name(); + }) + ); + } + }; +}} + +int main() { + Foo foo; + hana::for_each(foo, hana::fuse([](auto /*key*/, std::string const& name) { + BOOST_HANA_RUNTIME_CHECK(name == "louis"); + })); +} diff --git a/src/boost/libs/hana/test/concept/struct/members.cpp b/src/boost/libs/hana/test/concept/struct/members.cpp new file mode 100644 index 00000000..1734b519 --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/members.cpp @@ -0,0 +1,51 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct MoveOnly { + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; + MoveOnly(MoveOnly const&) = delete; + MoveOnly& operator=(MoveOnly&&) = default; + MoveOnly& operator=(MoveOnly const&) = delete; +}; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::members(obj()), + ::seq() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::members(obj(ct_eq<0>{})), + ::seq(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::members(obj(ct_eq<0>{}, ct_eq<1>{})), + ::seq(ct_eq<0>{}, ct_eq<1>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::members(obj(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})), + ::seq(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}) + )); + + // make sure it works with move only types + auto z1 = hana::members(obj(MoveOnly{})); + auto z2 = hana::members(obj(MoveOnly{}, MoveOnly{})); + (void)z1; + (void)z2; +} diff --git a/src/boost/libs/hana/test/concept/struct/minimal_struct.hpp b/src/boost/libs/hana/test/concept/struct/minimal_struct.hpp new file mode 100644 index 00000000..4eea80df --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/minimal_struct.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_STRUCT_MINIMAL_STRUCT_HPP +#define BOOST_HANA_TEST_STRUCT_MINIMAL_STRUCT_HPP + +#include +#include +#include +#include +#include +#include + + +template +struct minimal_struct_tag; + +template +struct minimal_struct_t { + boost::hana::tuple members; + using hana_tag = minimal_struct_tag; +}; + +struct obj_t { + template + constexpr minimal_struct_t operator()(Members ...members) const { + return {{static_cast(members)...}}; + } +}; +constexpr obj_t obj{}; + +namespace boost { namespace hana { + template + struct accessors_impl> { + template + struct get_member { + template + constexpr decltype(auto) operator()(Struct&& s) const { + return hana::at_c(static_cast(s).members); + } + }; + + static auto apply() { + return hana::unpack(hana::range_c, [](auto ...k) { + return hana::make_tuple( + hana::make_pair(k, get_member{})... + ); + }); + } + }; +}} + +#endif // !BOOST_HANA_TEST_STRUCT_MINIMAL_STRUCT_HPP diff --git a/src/boost/libs/hana/test/concept/struct/unpack.cpp b/src/boost/libs/hana/test/concept/struct/unpack.cpp new file mode 100644 index 00000000..30b8982f --- /dev/null +++ b/src/boost/libs/hana/test/concept/struct/unpack.cpp @@ -0,0 +1,44 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include "minimal_struct.hpp" +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + constexpr auto pair = ::minimal_product; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(obj(), f), + f() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(obj(ct_eq<0>{}), f), + f(pair(hana::int_c<0>, ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(obj(ct_eq<0>{}, ct_eq<1>{}), f), + f(pair(hana::int_c<0>, ct_eq<0>{}), + pair(hana::int_c<1>, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(obj(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f), + f(pair(hana::int_c<0>, ct_eq<0>{}), + pair(hana::int_c<1>, ct_eq<1>{}), + pair(hana::int_c<2>, ct_eq<2>{})) + )); +} -- cgit v1.2.3