diff options
Diffstat (limited to '')
27 files changed, 898 insertions, 0 deletions
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 000000000..74070fb2f --- /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 <boost/hana/any_of.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..2636729cb --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/ap.hpp> + +#include <laws/base.hpp> +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 000000000..be3f0ec65 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/chain.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..40a2a0daf --- /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 <boost/hana/assert.hpp> +#include <boost/hana/concat.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..09410ab3b --- /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 <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..38f25f396 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/empty.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::empty<hana::optional_tag>(), + 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 000000000..476888fba --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/not_equal.hpp> // for operator != +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..7ee20f828 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..6a21a50fa --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/flatten.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..8b9dd8014 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/fold_left.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..2d3c1f5cd --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/fold_right.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..49b1f98c7 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/optional.hpp> +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 000000000..6bf772bad --- /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 <boost/hana/assert.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/optional.hpp> +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 000000000..9b0b87cc0 --- /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 <boost/hana/bool.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/tuple.hpp> + +#include <laws/applicative.hpp> +#include <laws/base.hpp> +#include <laws/comparable.hpp> +#include <laws/foldable.hpp> +#include <laws/functor.hpp> +#include <laws/monad.hpp> +#include <laws/monad_plus.hpp> +#include <laws/orderable.hpp> +#include <laws/searchable.hpp> +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<hana::optional_tag>{eqs}; + hana::test::TestOrderable<hana::optional_tag>{ords}; + hana::test::TestFunctor<hana::optional_tag>{eqs, eq_values}; + hana::test::TestApplicative<hana::optional_tag>{eqs}; + hana::test::TestMonad<hana::optional_tag>{eqs, nested_eqs}; + hana::test::TestMonadPlus<hana::optional_tag>{eqs, predicates, eq_values}; + hana::test::TestSearchable<hana::optional_tag>{eqs, eq_values}; + hana::test::TestSearchable<hana::optional_tag>{ + 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<hana::optional_tag>{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 000000000..05c5d8a74 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/greater.hpp> +#include <boost/hana/greater_equal.hpp> +#include <boost/hana/less.hpp> +#include <boost/hana/less_equal.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..25641beed --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/lift.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::lift<hana::optional_tag>(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 000000000..e436d6ce0 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/core/make.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +namespace hana = boost::hana; +using hana::test::ct_eq; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make<hana::optional_tag>(), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make<hana::optional_tag>(ct_eq<3>{}), + hana::just(ct_eq<3>{}) + )); + + // Check that make_optional == make<optional_tag> + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_optional(), + hana::make<hana::optional_tag>() + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_optional(ct_eq<3>{}), + hana::make<hana::optional_tag>(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 000000000..ca3d154e0 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..6e85c2045 --- /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 <boost/hana/optional.hpp> +#include <boost/hana/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +// This test makes sure that an optional holding a hana::type has a +// nested ::type alias. + + +template <typename ...> +using void_t = void; + +template <typename T, typename = void> +struct has_type : std::false_type { }; + +template <typename T> +struct has_type<T, void_t<typename T::type>> + : std::true_type +{ }; + + +struct T; + +static_assert(std::is_same<decltype(hana::just(hana::type_c<T>))::type, T>{}, ""); +static_assert(!has_type<decltype(hana::nothing)>{}, ""); + +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 000000000..691d8981e --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..271094b48 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..d7a719e30 --- /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 <boost/hana/optional.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +struct Foo { }; + +int main() { + auto just = hana::just(Foo{}); + static_assert(std::is_same<decltype(just), hana::optional<Foo>>{}, ""); + + auto nothing = hana::nothing; + static_assert(std::is_same<decltype(nothing), hana::optional<>>{}, ""); +} 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 000000000..e821c248c --- /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 <boost/hana/assert.hpp> +#include <boost/hana/chain.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +#include <support/tracked.hpp> +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 000000000..84f44dcf8 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/transform.hpp> + +#include <laws/base.hpp> +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 000000000..5968d33a3 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/unpack.hpp> + +#include <laws/base.hpp> +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 000000000..710d73c75 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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 000000000..05fa784f8 --- /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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/optional.hpp> + +#include <laws/base.hpp> +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>{} + )); +} |