From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../hana/example/optional/applicative.complex.cpp | 50 ++++++++++++++++++++++ .../libs/hana/example/optional/applicative.cpp | 19 ++++++++ .../libs/hana/example/optional/comparable.cpp | 17 ++++++++ src/boost/libs/hana/example/optional/foldable.cpp | 14 ++++++ src/boost/libs/hana/example/optional/functor.cpp | 16 +++++++ src/boost/libs/hana/example/optional/is_just.cpp | 15 +++++++ .../libs/hana/example/optional/is_nothing.cpp | 15 +++++++ src/boost/libs/hana/example/optional/just.cpp | 13 ++++++ src/boost/libs/hana/example/optional/make.cpp | 20 +++++++++ src/boost/libs/hana/example/optional/maybe.cpp | 13 ++++++ src/boost/libs/hana/example/optional/monad.cpp | 23 ++++++++++ .../libs/hana/example/optional/monad_plus.cpp | 18 ++++++++ src/boost/libs/hana/example/optional/nothing.cpp | 13 ++++++ src/boost/libs/hana/example/optional/orderable.cpp | 17 ++++++++ .../libs/hana/example/optional/searchable.cpp | 27 ++++++++++++ src/boost/libs/hana/example/optional/sfinae.cpp | 21 +++++++++ .../optional/sfinae_friendly_metafunctions.cpp | 44 +++++++++++++++++++ src/boost/libs/hana/example/optional/value.cpp | 20 +++++++++ src/boost/libs/hana/example/optional/value_or.cpp | 13 ++++++ 19 files changed, 388 insertions(+) create mode 100644 src/boost/libs/hana/example/optional/applicative.complex.cpp create mode 100644 src/boost/libs/hana/example/optional/applicative.cpp create mode 100644 src/boost/libs/hana/example/optional/comparable.cpp create mode 100644 src/boost/libs/hana/example/optional/foldable.cpp create mode 100644 src/boost/libs/hana/example/optional/functor.cpp create mode 100644 src/boost/libs/hana/example/optional/is_just.cpp create mode 100644 src/boost/libs/hana/example/optional/is_nothing.cpp create mode 100644 src/boost/libs/hana/example/optional/just.cpp create mode 100644 src/boost/libs/hana/example/optional/make.cpp create mode 100644 src/boost/libs/hana/example/optional/maybe.cpp create mode 100644 src/boost/libs/hana/example/optional/monad.cpp create mode 100644 src/boost/libs/hana/example/optional/monad_plus.cpp create mode 100644 src/boost/libs/hana/example/optional/nothing.cpp create mode 100644 src/boost/libs/hana/example/optional/orderable.cpp create mode 100644 src/boost/libs/hana/example/optional/searchable.cpp create mode 100644 src/boost/libs/hana/example/optional/sfinae.cpp create mode 100644 src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp create mode 100644 src/boost/libs/hana/example/optional/value.cpp create mode 100644 src/boost/libs/hana/example/optional/value_or.cpp (limited to 'src/boost/libs/hana/example/optional') diff --git a/src/boost/libs/hana/example/optional/applicative.complex.cpp b/src/boost/libs/hana/example/optional/applicative.complex.cpp new file mode 100644 index 000000000..f8eb84a73 --- /dev/null +++ b/src/boost/libs/hana/example/optional/applicative.complex.cpp @@ -0,0 +1,50 @@ +// 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; + + +template +constexpr auto function = hana::nothing; + +template <> +BOOST_HANA_CONSTEXPR_LAMBDA auto function<'+'> = hana::just([](auto x, auto y) { + return x + y; +}); + +template <> +BOOST_HANA_CONSTEXPR_LAMBDA auto function<'-'> = hana::just([](auto x, auto y) { + return x - y; +}); + +// and so on... + +template +constexpr auto digit = hana::if_(hana::bool_c<(n >= '0' && n <= '9')>, + hana::just(static_cast(n - 48)), + hana::nothing +); + +template +BOOST_HANA_CONSTEXPR_LAMBDA auto evaluate = hana::ap(function, digit, digit); + +int main() { + BOOST_HANA_CONSTEXPR_CHECK(evaluate<'1', '+', '2'> == hana::just(1 + 2)); + BOOST_HANA_CONSTEXPR_CHECK(evaluate<'4', '-', '2'> == hana::just(4 - 2)); + + BOOST_HANA_CONSTANT_CHECK(evaluate<'?', '+', '2'> == hana::nothing); + BOOST_HANA_CONSTANT_CHECK(evaluate<'1', '?', '2'> == hana::nothing); + BOOST_HANA_CONSTANT_CHECK(evaluate<'1', '+', '?'> == hana::nothing); + BOOST_HANA_CONSTANT_CHECK(evaluate<'?', '?', '?'> == hana::nothing); + + static_assert(hana::lift(123) == hana::just(123), ""); +} diff --git a/src/boost/libs/hana/example/optional/applicative.cpp b/src/boost/libs/hana/example/optional/applicative.cpp new file mode 100644 index 000000000..3c67c30e9 --- /dev/null +++ b/src/boost/libs/hana/example/optional/applicative.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 +#include +#include +namespace hana = boost::hana; + + +constexpr char next(char c) { return c + 1; } + +static_assert(hana::ap(hana::just(next), hana::just('x')) == hana::just('y'), ""); +BOOST_HANA_CONSTANT_CHECK(hana::ap(hana::nothing, hana::just('x')) == hana::nothing); +BOOST_HANA_CONSTANT_CHECK(hana::ap(hana::just(next), hana::nothing) == hana::nothing); +BOOST_HANA_CONSTANT_CHECK(hana::ap(hana::nothing, hana::nothing) == hana::nothing); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/comparable.cpp b/src/boost/libs/hana/example/optional/comparable.cpp new file mode 100644 index 000000000..ba192b852 --- /dev/null +++ b/src/boost/libs/hana/example/optional/comparable.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; + + +BOOST_HANA_CONSTANT_CHECK(hana::nothing == hana::nothing); +static_assert(hana::just('x') == hana::just('x'), ""); +static_assert(hana::just('x') != hana::just('y'), ""); +BOOST_HANA_CONSTANT_CHECK(hana::just('x') != hana::nothing); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/foldable.cpp b/src/boost/libs/hana/example/optional/foldable.cpp new file mode 100644 index 000000000..21fc920c6 --- /dev/null +++ b/src/boost/libs/hana/example/optional/foldable.cpp @@ -0,0 +1,14 @@ +// 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; + + +static_assert(hana::fold_right(hana::nothing, 1, hana::plus) == 1, ""); +static_assert(hana::fold_right(hana::just(4), 1, hana::plus) == 5, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/functor.cpp b/src/boost/libs/hana/example/optional/functor.cpp new file mode 100644 index 000000000..6faf54a0f --- /dev/null +++ b/src/boost/libs/hana/example/optional/functor.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 +#include +#include +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::transform(hana::nothing, hana::_ + 1) == hana::nothing); +static_assert(hana::transform(hana::just(1), hana::_ + 1) == hana::just(2), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/is_just.cpp b/src/boost/libs/hana/example/optional/is_just.cpp new file mode 100644 index 000000000..7c7216ace --- /dev/null +++ b/src/boost/libs/hana/example/optional/is_just.cpp @@ -0,0 +1,15 @@ +// 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; + + +BOOST_HANA_CONSTANT_CHECK( hana::is_just(hana::just('x'))); +BOOST_HANA_CONSTANT_CHECK( hana::is_just(hana::just(hana::nothing))); +BOOST_HANA_CONSTANT_CHECK(!hana::is_just(hana::nothing)); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/is_nothing.cpp b/src/boost/libs/hana/example/optional/is_nothing.cpp new file mode 100644 index 000000000..ffde02df5 --- /dev/null +++ b/src/boost/libs/hana/example/optional/is_nothing.cpp @@ -0,0 +1,15 @@ +// 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; + + +BOOST_HANA_CONSTANT_CHECK( hana::is_nothing(hana::nothing)); +BOOST_HANA_CONSTANT_CHECK(!hana::is_nothing(hana::just('x'))); +BOOST_HANA_CONSTANT_CHECK(!hana::is_nothing(hana::just(hana::nothing))); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/just.cpp b/src/boost/libs/hana/example/optional/just.cpp new file mode 100644 index 000000000..bf7d32042 --- /dev/null +++ b/src/boost/libs/hana/example/optional/just.cpp @@ -0,0 +1,13 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +namespace hana = boost::hana; + + +constexpr auto just_x = hana::just('x'); +BOOST_HANA_CONSTANT_CHECK(hana::is_just(just_x)); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/make.cpp b/src/boost/libs/hana/example/optional/make.cpp new file mode 100644 index 000000000..fd0034a76 --- /dev/null +++ b/src/boost/libs/hana/example/optional/make.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 +namespace hana = boost::hana; + + +int main() { + constexpr auto x = hana::make(); + BOOST_HANA_CONSTANT_CHECK(x == hana::make_optional()); + BOOST_HANA_CONSTANT_CHECK(hana::is_nothing(x)); + + constexpr auto just_x = hana::make('x'); + static_assert(just_x == hana::make_optional('x'), ""); + BOOST_HANA_CONSTANT_CHECK(hana::is_just(just_x)); +} diff --git a/src/boost/libs/hana/example/optional/maybe.cpp b/src/boost/libs/hana/example/optional/maybe.cpp new file mode 100644 index 000000000..5e90cb652 --- /dev/null +++ b/src/boost/libs/hana/example/optional/maybe.cpp @@ -0,0 +1,13 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +namespace hana = boost::hana; + + +static_assert(hana::maybe('x', hana::_ + 1, hana::just(1)) == 2, ""); +static_assert(hana::maybe('x', hana::_ + 1, hana::nothing) == 'x', ""); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/monad.cpp b/src/boost/libs/hana/example/optional/monad.cpp new file mode 100644 index 000000000..2be7821a6 --- /dev/null +++ b/src/boost/libs/hana/example/optional/monad.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; + + +int main() { + BOOST_HANA_CONSTEXPR_LAMBDA auto inc = [](auto x) { + return hana::just(x + 1); + }; + + BOOST_HANA_CONSTEXPR_CHECK(hana::chain(hana::just(1), inc) == hana::just(2)); + BOOST_HANA_CONSTANT_CHECK(hana::chain(hana::nothing, inc) == hana::nothing); + + BOOST_HANA_CONSTEXPR_CHECK(hana::flatten(hana::just(hana::just(2))) == hana::just(2)); +} diff --git a/src/boost/libs/hana/example/optional/monad_plus.cpp b/src/boost/libs/hana/example/optional/monad_plus.cpp new file mode 100644 index 000000000..d32681526 --- /dev/null +++ b/src/boost/libs/hana/example/optional/monad_plus.cpp @@ -0,0 +1,18 @@ +// 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; + + +static_assert(hana::concat(hana::nothing, hana::just('x')) == hana::just('x'), ""); +BOOST_HANA_CONSTANT_CHECK(hana::concat(hana::nothing, hana::nothing) == hana::nothing); +static_assert(hana::concat(hana::just('x'), hana::just('y')) == hana::just('x'), ""); +BOOST_HANA_CONSTANT_CHECK(hana::empty() == hana::nothing); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/nothing.cpp b/src/boost/libs/hana/example/optional/nothing.cpp new file mode 100644 index 000000000..81f109e90 --- /dev/null +++ b/src/boost/libs/hana/example/optional/nothing.cpp @@ -0,0 +1,13 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +namespace hana = boost::hana; + + +constexpr auto x = hana::nothing; +BOOST_HANA_CONSTANT_CHECK(hana::is_nothing(x)); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/orderable.cpp b/src/boost/libs/hana/example/optional/orderable.cpp new file mode 100644 index 000000000..b8cb7e110 --- /dev/null +++ b/src/boost/libs/hana/example/optional/orderable.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; + + +BOOST_HANA_CONSTANT_CHECK(hana::nothing < hana::just(3)); +BOOST_HANA_CONSTANT_CHECK(hana::just(0) > hana::nothing); +static_assert(hana::just(1) < hana::just(3), ""); +static_assert(hana::just(3) > hana::just(2), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/searchable.cpp b/src/boost/libs/hana/example/optional/searchable.cpp new file mode 100644 index 000000000..e95d451af --- /dev/null +++ b/src/boost/libs/hana/example/optional/searchable.cpp @@ -0,0 +1,27 @@ +// 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; + + +auto odd = [](auto x) { + return x % hana::int_c<2> != hana::int_c<0>; +}; + +BOOST_HANA_CONSTANT_CHECK(hana::find_if(hana::just(hana::int_c<3>), odd) == hana::just(hana::int_c<3>)); +BOOST_HANA_CONSTANT_CHECK(hana::find_if(hana::just(hana::int_c<2>), odd) == hana::nothing); +BOOST_HANA_CONSTANT_CHECK(hana::find_if(hana::nothing, odd) == hana::nothing); + +BOOST_HANA_CONSTANT_CHECK(hana::all_of(hana::just(hana::int_c<3>), odd)); +BOOST_HANA_CONSTANT_CHECK(hana::all_of(hana::nothing, odd)); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/sfinae.cpp b/src/boost/libs/hana/example/optional/sfinae.cpp new file mode 100644 index 000000000..1fe9adf0e --- /dev/null +++ b/src/boost/libs/hana/example/optional/sfinae.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 +#include +#include +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTEXPR_LAMBDA auto incr = [](auto x) -> decltype(x + 1) { + return x + 1; + }; + + BOOST_HANA_CONSTEXPR_CHECK(hana::sfinae(incr)(1) == hana::just(2)); + + struct invalid { }; + BOOST_HANA_CONSTANT_CHECK(hana::sfinae(incr)(invalid{}) == hana::nothing); +} diff --git a/src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp b/src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp new file mode 100644 index 000000000..392154b39 --- /dev/null +++ b/src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.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 + +#include +#include +namespace hana = boost::hana; + + +template +using void_t = void; + +template +struct has_type : std::false_type { }; + +template +struct has_type> + : std::true_type +{ }; + +auto common_type_impl = hana::sfinae([](auto t, auto u) -> hana::type< + decltype(true ? hana::traits::declval(t) : hana::traits::declval(u)) +> { return {}; }); + +template +using common_type = decltype(common_type_impl(hana::type_c, hana::type_c)); + +BOOST_HANA_CONSTANT_CHECK( + common_type_impl(hana::type_c, hana::type_c) + == + hana::just(hana::type_c) +); + +static_assert(!has_type>{}, ""); +static_assert(std::is_same::type, float>{}, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/optional/value.cpp b/src/boost/libs/hana/example/optional/value.cpp new file mode 100644 index 000000000..adbb7aac5 --- /dev/null +++ b/src/boost/libs/hana/example/optional/value.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; + + +int main() { + static_assert(hana::just('x').value() == 'x', ""); + BOOST_HANA_CONSTANT_CHECK(*hana::just(hana::type_c) == hana::type_c); + BOOST_HANA_RUNTIME_CHECK(hana::just(std::string{"abcd"})->size() == 4); + + // hana::nothing.value(); // compile-time error +} diff --git a/src/boost/libs/hana/example/optional/value_or.cpp b/src/boost/libs/hana/example/optional/value_or.cpp new file mode 100644 index 000000000..1d0b22960 --- /dev/null +++ b/src/boost/libs/hana/example/optional/value_or.cpp @@ -0,0 +1,13 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +namespace hana = boost::hana; + + +static_assert(hana::just(1).value_or('x') == 1, ""); +static_assert(hana::nothing.value_or('x') == 'x', ""); + +int main() { } -- cgit v1.2.3