From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/hana/test/optional/any_of.cpp | 23 +++++++ src/boost/libs/hana/test/optional/ap.cpp | 34 ++++++++++ src/boost/libs/hana/test/optional/chain.cpp | 40 ++++++++++++ src/boost/libs/hana/test/optional/concat.cpp | 55 +++++++++++++++++ .../hana/test/optional/copy.trap_construct.cpp | 21 +++++++ src/boost/libs/hana/test/optional/empty.cpp | 17 +++++ src/boost/libs/hana/test/optional/equal.cpp | 30 +++++++++ src/boost/libs/hana/test/optional/find_if.cpp | 38 ++++++++++++ src/boost/libs/hana/test/optional/flatten.cpp | 28 +++++++++ src/boost/libs/hana/test/optional/fold_left.cpp | 28 +++++++++ src/boost/libs/hana/test/optional/fold_right.cpp | 28 +++++++++ src/boost/libs/hana/test/optional/is_just.cpp | 16 +++++ src/boost/libs/hana/test/optional/is_nothing.cpp | 17 +++++ src/boost/libs/hana/test/optional/laws.cpp | 72 ++++++++++++++++++++++ src/boost/libs/hana/test/optional/less.cpp | 52 ++++++++++++++++ src/boost/libs/hana/test/optional/lift.cpp | 20 ++++++ src/boost/libs/hana/test/optional/make.cpp | 36 +++++++++++ src/boost/libs/hana/test/optional/maybe.cpp | 28 +++++++++ src/boost/libs/hana/test/optional/nested_type.cpp | 33 ++++++++++ .../libs/hana/test/optional/operator_arrow.cpp | 37 +++++++++++ .../libs/hana/test/optional/operator_deref.cpp | 33 ++++++++++ .../libs/hana/test/optional/representation.cpp | 19 ++++++ src/boost/libs/hana/test/optional/sfinae.cpp | 71 +++++++++++++++++++++ src/boost/libs/hana/test/optional/transform.cpp | 29 +++++++++ src/boost/libs/hana/test/optional/unpack.cpp | 34 ++++++++++ src/boost/libs/hana/test/optional/value.cpp | 33 ++++++++++ src/boost/libs/hana/test/optional/value_or.cpp | 26 ++++++++ 27 files changed, 898 insertions(+) create mode 100644 src/boost/libs/hana/test/optional/any_of.cpp create mode 100644 src/boost/libs/hana/test/optional/ap.cpp create mode 100644 src/boost/libs/hana/test/optional/chain.cpp create mode 100644 src/boost/libs/hana/test/optional/concat.cpp create mode 100644 src/boost/libs/hana/test/optional/copy.trap_construct.cpp create mode 100644 src/boost/libs/hana/test/optional/empty.cpp create mode 100644 src/boost/libs/hana/test/optional/equal.cpp create mode 100644 src/boost/libs/hana/test/optional/find_if.cpp create mode 100644 src/boost/libs/hana/test/optional/flatten.cpp create mode 100644 src/boost/libs/hana/test/optional/fold_left.cpp create mode 100644 src/boost/libs/hana/test/optional/fold_right.cpp create mode 100644 src/boost/libs/hana/test/optional/is_just.cpp create mode 100644 src/boost/libs/hana/test/optional/is_nothing.cpp create mode 100644 src/boost/libs/hana/test/optional/laws.cpp create mode 100644 src/boost/libs/hana/test/optional/less.cpp create mode 100644 src/boost/libs/hana/test/optional/lift.cpp create mode 100644 src/boost/libs/hana/test/optional/make.cpp create mode 100644 src/boost/libs/hana/test/optional/maybe.cpp create mode 100644 src/boost/libs/hana/test/optional/nested_type.cpp create mode 100644 src/boost/libs/hana/test/optional/operator_arrow.cpp create mode 100644 src/boost/libs/hana/test/optional/operator_deref.cpp create mode 100644 src/boost/libs/hana/test/optional/representation.cpp create mode 100644 src/boost/libs/hana/test/optional/sfinae.cpp create mode 100644 src/boost/libs/hana/test/optional/transform.cpp create mode 100644 src/boost/libs/hana/test/optional/unpack.cpp create mode 100644 src/boost/libs/hana/test/optional/value.cpp create mode 100644 src/boost/libs/hana/test/optional/value_or.cpp (limited to 'src/boost/libs/hana/test/optional') diff --git a/src/boost/libs/hana/test/optional/any_of.cpp b/src/boost/libs/hana/test/optional/any_of.cpp new file mode 100644 index 00000000..74070fb2 --- /dev/null +++ b/src/boost/libs/hana/test/optional/any_of.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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + ct_eq<2> x{}; + ct_eq<3> y{}; + + BOOST_HANA_CONSTANT_CHECK(hana::any_of(hana::just(x), hana::equal.to(x))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of(hana::just(x), hana::equal.to(y)))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of(hana::nothing, hana::equal.to(x)))); +} diff --git a/src/boost/libs/hana/test/optional/ap.cpp b/src/boost/libs/hana/test/optional/ap.cpp new file mode 100644 index 00000000..2636729c --- /dev/null +++ b/src/boost/libs/hana/test/optional/ap.cpp @@ -0,0 +1,34 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(hana::nothing, hana::nothing), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(hana::just(f), hana::nothing), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(hana::nothing, hana::just(ct_eq<3>{})), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::ap(hana::just(f), hana::just(ct_eq<3>{})), + hana::just(f(ct_eq<3>{})) + )); +} diff --git a/src/boost/libs/hana/test/optional/chain.cpp b/src/boost/libs/hana/test/optional/chain.cpp new file mode 100644 index 00000000..be3f0ec6 --- /dev/null +++ b/src/boost/libs/hana/test/optional/chain.cpp @@ -0,0 +1,40 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + auto f = [](auto x) { + return hana::just(hana::test::_injection<0>{}(x)); + }; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::chain(hana::just(ct_eq<3>{}), f), + f(ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::chain(hana::nothing, f), + hana::nothing + )); + + // test with operators + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::just(ct_eq<3>{}) | f, + f(ct_eq<3>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::nothing | f, + hana::nothing + )); +} diff --git a/src/boost/libs/hana/test/optional/concat.cpp b/src/boost/libs/hana/test/optional/concat.cpp new file mode 100644 index 00000000..40a2a0da --- /dev/null +++ b/src/boost/libs/hana/test/optional/concat.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; +using hana::test::ct_eq; + + +int main() { + auto rv_nothing = [] { return hana::nothing; }; // rvalue nothing + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(rv_nothing(), hana::nothing), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::nothing, rv_nothing()), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(rv_nothing(), rv_nothing()), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(rv_nothing(), hana::just(ct_eq<0>{})), + hana::just(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::just(ct_eq<0>{}), rv_nothing()), + hana::just(ct_eq<0>{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::nothing, hana::nothing), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::nothing, hana::just(ct_eq<0>{})), + hana::just(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::just(ct_eq<0>{}), hana::nothing), + hana::just(ct_eq<0>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::concat(hana::just(ct_eq<0>{}), hana::just(ct_eq<1>{})), + hana::just(ct_eq<0>{}) + )); +} diff --git a/src/boost/libs/hana/test/optional/copy.trap_construct.cpp b/src/boost/libs/hana/test/optional/copy.trap_construct.cpp new file mode 100644 index 00000000..09410ab3 --- /dev/null +++ b/src/boost/libs/hana/test/optional/copy.trap_construct.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 + +#include +namespace hana = boost::hana; + + +// This test makes sure that we do not instantiate rogue contructors when +// trying to copy a hana::just. + +int main() { + auto just = hana::just(hana::test::trap_construct{}); + auto implicit_copy = just; + decltype(just) explicit_copy(just); + + (void)implicit_copy; + (void)explicit_copy; +} diff --git a/src/boost/libs/hana/test/optional/empty.cpp b/src/boost/libs/hana/test/optional/empty.cpp new file mode 100644 index 00000000..38f25f39 --- /dev/null +++ b/src/boost/libs/hana/test/optional/empty.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::empty(), + hana::nothing + )); +} diff --git a/src/boost/libs/hana/test/optional/equal.cpp b/src/boost/libs/hana/test/optional/equal.cpp new file mode 100644 index 00000000..476888fb --- /dev/null +++ b/src/boost/libs/hana/test/optional/equal.cpp @@ -0,0 +1,30 @@ +// 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 // for operator != +#include + +#include +namespace hana = boost::hana; + + +int main() { + hana::test::ct_eq<3> x{}; + hana::test::ct_eq<4> y{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::nothing, hana::nothing)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::nothing, hana::just(x)))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::just(x), hana::nothing))); + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::just(x), hana::just(x))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::just(x), hana::just(y)))); + + BOOST_HANA_CONSTANT_CHECK(hana::nothing == hana::nothing); + BOOST_HANA_CONSTANT_CHECK(hana::just(x) == hana::just(x)); + BOOST_HANA_CONSTANT_CHECK(hana::just(x) != hana::just(y)); + BOOST_HANA_CONSTANT_CHECK(hana::just(x) != hana::nothing); + BOOST_HANA_CONSTANT_CHECK(hana::nothing != hana::just(x)); +} diff --git a/src/boost/libs/hana/test/optional/find_if.cpp b/src/boost/libs/hana/test/optional/find_if.cpp new file mode 100644 index 00000000..7ee20f82 --- /dev/null +++ b/src/boost/libs/hana/test/optional/find_if.cpp @@ -0,0 +1,38 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + ct_eq<2> x{}; + ct_eq<3> y{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(hana::just(x), hana::equal.to(x)), + hana::just(x) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(hana::just(x), hana::equal.to(y)), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(hana::nothing, hana::equal.to(x)), + hana::nothing + )); + + // Previously, there was a bug that would make this fail. + auto non_const_nothing = hana::nothing; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(non_const_nothing, hana::equal.to(x)), + hana::nothing + )); +} diff --git a/src/boost/libs/hana/test/optional/flatten.cpp b/src/boost/libs/hana/test/optional/flatten.cpp new file mode 100644 index 00000000..6a21a50f --- /dev/null +++ b/src/boost/libs/hana/test/optional/flatten.cpp @@ -0,0 +1,28 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::flatten(hana::nothing), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::flatten(hana::just(hana::nothing)), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::flatten(hana::just(hana::just(ct_eq<4>{}))), + hana::just(ct_eq<4>{}) + )); +} diff --git a/src/boost/libs/hana/test/optional/fold_left.cpp b/src/boost/libs/hana/test/optional/fold_left.cpp new file mode 100644 index 00000000..8b9dd801 --- /dev/null +++ b/src/boost/libs/hana/test/optional/fold_left.cpp @@ -0,0 +1,28 @@ +// 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; + + +int main() { + hana::test::ct_eq<2> x{}; + hana::test::ct_eq<3> s{}; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(hana::just(x), s, f), + f(s, x) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_left(hana::nothing, s, f), + s + )); +} diff --git a/src/boost/libs/hana/test/optional/fold_right.cpp b/src/boost/libs/hana/test/optional/fold_right.cpp new file mode 100644 index 00000000..2d3c1f5c --- /dev/null +++ b/src/boost/libs/hana/test/optional/fold_right.cpp @@ -0,0 +1,28 @@ +// 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; + + +int main() { + hana::test::ct_eq<2> x{}; + hana::test::ct_eq<3> s{}; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(hana::just(x), s, f), + f(x, s) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::fold_right(hana::nothing, s, f), + s + )); +} diff --git a/src/boost/libs/hana/test/optional/is_just.cpp b/src/boost/libs/hana/test/optional/is_just.cpp new file mode 100644 index 00000000..49b1f98c --- /dev/null +++ b/src/boost/libs/hana/test/optional/is_just.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +namespace hana = boost::hana; + + +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::is_just(hana::just(undefined{}))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_just(hana::nothing))); +} diff --git a/src/boost/libs/hana/test/optional/is_nothing.cpp b/src/boost/libs/hana/test/optional/is_nothing.cpp new file mode 100644 index 00000000..6bf772ba --- /dev/null +++ b/src/boost/libs/hana/test/optional/is_nothing.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +namespace hana = boost::hana; + + +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::is_nothing(hana::nothing)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_nothing(hana::just(undefined{})))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_nothing(hana::just(hana::nothing)))); +} diff --git a/src/boost/libs/hana/test/optional/laws.cpp b/src/boost/libs/hana/test/optional/laws.cpp new file mode 100644 index 00000000..9b0b87cc --- /dev/null +++ b/src/boost/libs/hana/test/optional/laws.cpp @@ -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) + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace hana = boost::hana; +using hana::test::ct_eq; +using hana::test::ct_ord; + + +int main() { + auto ords = hana::make_tuple( + hana::nothing, + hana::just(ct_ord<0>{}), + hana::just(ct_ord<1>{}), + hana::just(ct_ord<2>{}) + ); + + auto eqs = hana::make_tuple( + hana::nothing, + hana::just(ct_eq<0>{}), + hana::just(ct_eq<1>{}), + hana::just(ct_eq<2>{}) + ); + + auto eq_values = hana::make_tuple(ct_eq<0>{}, ct_eq<2>{}, ct_eq<3>{}); + + auto predicates = hana::make_tuple( + hana::equal.to(ct_eq<0>{}), + hana::equal.to(ct_eq<2>{}), + hana::equal.to(ct_eq<3>{}), + hana::always(hana::false_c), + hana::always(hana::true_c) + ); + + auto nested_eqs = hana::make_tuple( + hana::nothing, + hana::just(hana::just(ct_eq<0>{})), + hana::just(hana::nothing), + hana::just(hana::just(ct_eq<2>{})) + ); + + + hana::test::TestComparable{eqs}; + hana::test::TestOrderable{ords}; + hana::test::TestFunctor{eqs, eq_values}; + hana::test::TestApplicative{eqs}; + hana::test::TestMonad{eqs, nested_eqs}; + hana::test::TestMonadPlus{eqs, predicates, eq_values}; + hana::test::TestSearchable{eqs, eq_values}; + hana::test::TestSearchable{ + hana::make_tuple( + hana::just(hana::true_c), + hana::just(hana::false_c), + hana::nothing + ), + hana::make_tuple(hana::true_c, hana::false_c) + }; + hana::test::TestFoldable{eqs}; +} diff --git a/src/boost/libs/hana/test/optional/less.cpp b/src/boost/libs/hana/test/optional/less.cpp new file mode 100644 index 00000000..05c5d8a7 --- /dev/null +++ b/src/boost/libs/hana/test/optional/less.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 +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_ord; + + +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::nothing < hana::just(undefined{})); + BOOST_HANA_CONSTANT_CHECK(hana::just(ct_ord<3>{}) < hana::just(ct_ord<4>{})); + BOOST_HANA_CONSTANT_CHECK(hana::just(ct_ord<3>{}) <= hana::just(ct_ord<4>{})); + BOOST_HANA_CONSTANT_CHECK(hana::just(ct_ord<4>{}) > hana::just(ct_ord<3>{})); + BOOST_HANA_CONSTANT_CHECK(hana::just(ct_ord<4>{}) >= hana::just(ct_ord<3>{})); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + hana::nothing, + hana::just(undefined{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + hana::just(undefined{}), + hana::nothing + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + hana::nothing, + hana::nothing + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + hana::just(ct_ord<3>{}), + hana::just(ct_ord<4>{}) + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + hana::just(ct_ord<3>{}), + hana::just(ct_ord<3>{}) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + hana::just(ct_ord<4>{}), + hana::just(ct_ord<3>{}) + ))); +} diff --git a/src/boost/libs/hana/test/optional/lift.cpp b/src/boost/libs/hana/test/optional/lift.cpp new file mode 100644 index 00000000..25641bee --- /dev/null +++ b/src/boost/libs/hana/test/optional/lift.cpp @@ -0,0 +1,20 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lift(ct_eq<3>{}), + hana::just(ct_eq<3>{}) + )); +} diff --git a/src/boost/libs/hana/test/optional/make.cpp b/src/boost/libs/hana/test/optional/make.cpp new file mode 100644 index 00000000..e436d6ce --- /dev/null +++ b/src/boost/libs/hana/test/optional/make.cpp @@ -0,0 +1,36 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(ct_eq<3>{}), + hana::just(ct_eq<3>{}) + )); + + // Check that make_optional == make + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_optional(), + hana::make() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_optional(ct_eq<3>{}), + hana::make(ct_eq<3>{}) + )); +} diff --git a/src/boost/libs/hana/test/optional/maybe.cpp b/src/boost/libs/hana/test/optional/maybe.cpp new file mode 100644 index 00000000..ca3d154e --- /dev/null +++ b/src/boost/libs/hana/test/optional/maybe.cpp @@ -0,0 +1,28 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct undefined { }; + +int main() { + hana::test::_injection<0> f{}; + hana::test::ct_eq<2> x{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::maybe(x, undefined{}, hana::nothing), + x + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::maybe(undefined{}, f, hana::just(x)), + f(x) + )); +} diff --git a/src/boost/libs/hana/test/optional/nested_type.cpp b/src/boost/libs/hana/test/optional/nested_type.cpp new file mode 100644 index 00000000..6e85c204 --- /dev/null +++ b/src/boost/libs/hana/test/optional/nested_type.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include + +#include +namespace hana = boost::hana; + + +// This test makes sure that an optional holding a hana::type has a +// nested ::type alias. + + +template +using void_t = void; + +template +struct has_type : std::false_type { }; + +template +struct has_type> + : std::true_type +{ }; + + +struct T; + +static_assert(std::is_same))::type, T>{}, ""); +static_assert(!has_type{}, ""); + +int main() { } diff --git a/src/boost/libs/hana/test/optional/operator_arrow.cpp b/src/boost/libs/hana/test/optional/operator_arrow.cpp new file mode 100644 index 00000000..691d8981 --- /dev/null +++ b/src/boost/libs/hana/test/optional/operator_arrow.cpp @@ -0,0 +1,37 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct object { + ct_eq<3> member; +}; + +int main() { + auto lvalue = hana::just(object{}); + ct_eq<3>& ref = lvalue->member; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + ref, + ct_eq<3>{} + )); + + auto const const_lvalue = hana::just(object{}); + ct_eq<3> const& const_ref = const_lvalue->member; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + const_ref, + ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::just(object{})->member, + ct_eq<3>{} + )); +} diff --git a/src/boost/libs/hana/test/optional/operator_deref.cpp b/src/boost/libs/hana/test/optional/operator_deref.cpp new file mode 100644 index 00000000..271094b4 --- /dev/null +++ b/src/boost/libs/hana/test/optional/operator_deref.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + auto lvalue = hana::just(ct_eq<3>{}); + ct_eq<3>& ref = *lvalue; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + ref, + ct_eq<3>{} + )); + + auto const const_lvalue = hana::just(ct_eq<3>{}); + ct_eq<3> const& const_ref = *const_lvalue; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + const_ref, + ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + *hana::just(ct_eq<3>{}), + ct_eq<3>{} + )); +} diff --git a/src/boost/libs/hana/test/optional/representation.cpp b/src/boost/libs/hana/test/optional/representation.cpp new file mode 100644 index 00000000..d7a719e3 --- /dev/null +++ b/src/boost/libs/hana/test/optional/representation.cpp @@ -0,0 +1,19 @@ +// 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 +namespace hana = boost::hana; + + +struct Foo { }; + +int main() { + auto just = hana::just(Foo{}); + static_assert(std::is_same>{}, ""); + + auto nothing = hana::nothing; + static_assert(std::is_same>{}, ""); +} diff --git a/src/boost/libs/hana/test/optional/sfinae.cpp b/src/boost/libs/hana/test/optional/sfinae.cpp new file mode 100644 index 00000000..e821c248 --- /dev/null +++ b/src/boost/libs/hana/test/optional/sfinae.cpp @@ -0,0 +1,71 @@ +// 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; + + +struct undefined { }; + +int main() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(f)(), + hana::just(f()) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(f)(ct_eq<0>{}), + hana::just(f(ct_eq<0>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(f)(ct_eq<0>{}, ct_eq<1>{}), + hana::just(f(ct_eq<0>{}, ct_eq<1>{})) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(undefined{})(), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(undefined{})(ct_eq<0>{}), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sfinae(undefined{})(ct_eq<0>{}, ct_eq<1>{}), + hana::nothing + )); + + auto incr = hana::sfinae([](auto x) -> decltype(x + 1) { + return x + 1; + }); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + incr(1), + hana::just(2) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + incr(undefined{}), + hana::nothing + )); + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::chain(hana::just(1), incr), + hana::just(2) + )); + + // using `sfinae` with a non-pod argument used to fail + hana::sfinae(undefined{})(Tracked{1}); + hana::sfinae([t = Tracked{1}](auto) { return 1; })(Tracked{1}); +} diff --git a/src/boost/libs/hana/test/optional/transform.cpp b/src/boost/libs/hana/test/optional/transform.cpp new file mode 100644 index 00000000..84f44dcf --- /dev/null +++ b/src/boost/libs/hana/test/optional/transform.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 +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct undefined { }; + +int main() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(hana::nothing, undefined{}), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::transform(hana::just(ct_eq<3>{}), f), + hana::just(f(ct_eq<3>{})) + )); +} diff --git a/src/boost/libs/hana/test/optional/unpack.cpp b/src/boost/libs/hana/test/optional/unpack.cpp new file mode 100644 index 00000000..5968d33a --- /dev/null +++ b/src/boost/libs/hana/test/optional/unpack.cpp @@ -0,0 +1,34 @@ +// 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; + + +int main() { + hana::test::ct_eq<2> x{}; + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(hana::nothing, f), + f() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(hana::just(x), f), + f(x) + )); + + // Previously, there was a bug that would make this fail. + auto non_const_nothing = hana::nothing; + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(non_const_nothing, f), + f() + )); +} diff --git a/src/boost/libs/hana/test/optional/value.cpp b/src/boost/libs/hana/test/optional/value.cpp new file mode 100644 index 00000000..710d73c7 --- /dev/null +++ b/src/boost/libs/hana/test/optional/value.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + auto lvalue = hana::just(ct_eq<3>{}); + ct_eq<3>& ref = lvalue.value(); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + ref, + ct_eq<3>{} + )); + + auto const const_lvalue = hana::just(ct_eq<3>{}); + ct_eq<3> const& const_ref = const_lvalue.value(); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + const_ref, + ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::just(ct_eq<3>{}).value(), + ct_eq<3>{} + )); +} diff --git a/src/boost/libs/hana/test/optional/value_or.cpp b/src/boost/libs/hana/test/optional/value_or.cpp new file mode 100644 index 00000000..05fa784f --- /dev/null +++ b/src/boost/libs/hana/test/optional/value_or.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +#include +namespace hana = boost::hana; +using hana::test::ct_eq; + + +struct undefined { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::nothing.value_or(ct_eq<3>{}), + ct_eq<3>{} + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::just(ct_eq<4>{}).value_or(undefined{}), + ct_eq<4>{} + )); +} -- cgit v1.2.3