diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/hana/example/ext/std | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/hana/example/ext/std')
14 files changed, 349 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/ext/std/array/comparable.cpp b/src/boost/libs/hana/example/ext/std/array/comparable.cpp new file mode 100644 index 000000000..c1c814877 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/array/comparable.cpp @@ -0,0 +1,24 @@ +// 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/ext/std/array.hpp> +#include <boost/hana/not_equal.hpp> + +#include <array> +namespace hana = boost::hana; + + +constexpr std::array<int, 4> xs = {{1, 2, 3, 4}}; +constexpr std::array<int, 5> ys = {{1, 2, 3, 4, 5}}; + +// arrays have different constexpr contents; result is a constexpr bool +static_assert(hana::equal(xs, xs), ""); + +// arrays have different lengths; result is an integral_constant +BOOST_HANA_CONSTANT_CHECK(hana::not_equal(xs, ys)); + + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/array/foldable.cpp b/src/boost/libs/hana/example/ext/std/array/foldable.cpp new file mode 100644 index 000000000..cff38e1c1 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/array/foldable.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/assert.hpp> +#include <boost/hana/ext/std/array.hpp> +#include <boost/hana/unpack.hpp> + +#include <array> +namespace hana = boost::hana; + + +int main() { + std::array<int, 5> a = {{0, 1, 2, 3, 4}}; + + auto b = hana::unpack(a, [](auto ...i) { + return std::array<int, sizeof...(i)>{{(i + 10)...}}; + }); + + BOOST_HANA_RUNTIME_CHECK(b == std::array<int, 5>{{10, 11, 12, 13, 14}}); +} diff --git a/src/boost/libs/hana/example/ext/std/array/iterable.cpp b/src/boost/libs/hana/example/ext/std/array/iterable.cpp new file mode 100644 index 000000000..d14dbd911 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/array/iterable.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/at.hpp> +#include <boost/hana/drop_front.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/array.hpp> + +#include <array> +namespace hana = boost::hana; + + +constexpr std::array<int, 5> a = {{0, 1, 2, 3, 4}}; + +static_assert(hana::at_c<2>(a) == 2, ""); + +static_assert(hana::equal(hana::drop_front(a), std::array<int, 4>{{1, 2, 3, 4}}), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/array/orderable.cpp b/src/boost/libs/hana/example/ext/std/array/orderable.cpp new file mode 100644 index 000000000..7f4c9f2b7 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/array/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 <boost/hana/ext/std/array.hpp> +#include <boost/hana/less.hpp> + +#include <array> +namespace hana = boost::hana; + + +constexpr std::array<int, 4> evens = {{2, 4, 6, 8}}; +constexpr std::array<int, 4> odds = {{1, 3, 5, 7}}; + +constexpr std::array<int, 5> up_to_5 = {{1, 2, 3, 4, 5}}; + +// arrays with same length +static_assert(hana::less(odds, evens), ""); + +// arrays with different lengths +static_assert(hana::less(up_to_5, odds), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp new file mode 100644 index 000000000..10b62752a --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp @@ -0,0 +1,22 @@ +// 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/ext/std/integer_sequence.hpp> +#include <boost/hana/not_equal.hpp> + +#include <utility> +namespace hana = boost::hana; + + +constexpr std::integer_sequence<int, 1, 2, 3, 4> xs{}; +constexpr std::integer_sequence<long, 1, 2, 3, 4> ys{}; +constexpr std::integer_sequence<long, 1, 2, 3, 4, 5> zs{}; + +BOOST_HANA_CONSTANT_CHECK(hana::equal(xs, ys)); +BOOST_HANA_CONSTANT_CHECK(hana::not_equal(xs, zs)); +BOOST_HANA_CONSTANT_CHECK(hana::not_equal(ys, zs)); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp new file mode 100644 index 000000000..4d7c3253f --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.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 <boost/hana/assert.hpp> +#include <boost/hana/ext/std/integer_sequence.hpp> +#include <boost/hana/unpack.hpp> + +#include <tuple> +#include <utility> +namespace hana = boost::hana; + + +auto add = [](auto a, auto b, auto c) { return a + b + c; }; + +int main() { + std::tuple<int, long, double> tuple{1, 2l, 3.3}; + + auto sum = hana::unpack(std::integer_sequence<int, 0, 1, 2>{}, [&](auto ...i) { + // the `i`s are `std::integral_constant<int, ...>`s + return add(std::get<decltype(i)::value>(tuple)...); + }); + + BOOST_HANA_RUNTIME_CHECK(sum == 6.3); +} diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.cpp new file mode 100644 index 000000000..ef421ec37 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.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/assert.hpp> +#include <boost/hana/at.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/integer_sequence.hpp> +#include <boost/hana/ext/std/integral_constant.hpp> + +#include <type_traits> +#include <utility> +namespace hana = boost::hana; + + +constexpr std::integer_sequence<int, 0, 1, 2, 3, 4> indices{}; + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_c<2>(indices), + std::integral_constant<int, 2>{} +)); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp new file mode 100644 index 000000000..c0a159bc8 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/integer_sequence.hpp> +#include <boost/hana/ext/std/integral_constant.hpp> +#include <boost/hana/find.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/optional.hpp> + +#include <type_traits> +#include <utility> +namespace hana = boost::hana; + + +constexpr std::integer_sequence<int, 1, 2, 3, 4> xs{}; + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(xs, hana::int_c<3>), + hana::just(std::integral_constant<int, 3>{}) +)); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/integral_constant.cpp b/src/boost/libs/hana/example/ext/std/integral_constant.cpp new file mode 100644 index 000000000..04e234f1a --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/integral_constant.cpp @@ -0,0 +1,22 @@ +// 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/ext/std/integral_constant.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/not_equal.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +static_assert(hana::value(std::integral_constant<int, 3>{}) == 3, ""); +static_assert(std::integral_constant<int, 3>::value == 3, ""); + +BOOST_HANA_CONSTANT_CHECK(hana::equal(std::integral_constant<int, 3>{}, hana::int_c<3>)); +BOOST_HANA_CONSTANT_CHECK(hana::equal(std::integral_constant<int, 3>{}, hana::long_c<3>)); +BOOST_HANA_CONSTANT_CHECK(hana::not_equal(std::integral_constant<int, 3>{}, hana::int_c<0>)); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/pair.cpp b/src/boost/libs/hana/example/ext/std/pair.cpp new file mode 100644 index 000000000..d118b18f8 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/pair.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/ext/std/pair.hpp> +#include <boost/hana/first.hpp> +#include <boost/hana/less.hpp> +#include <boost/hana/not_equal.hpp> +#include <boost/hana/second.hpp> +namespace hana = boost::hana; + + +constexpr auto pair = std::make_pair(1, 'x'); + +static_assert(hana::first(pair) == 1, ""); +static_assert(hana::second(pair) == 'x', ""); + +static_assert(hana::not_equal(pair, std::make_pair(3, 'z')), ""); +static_assert(hana::less(pair, std::make_pair(3, 'x')), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/ratio/arithmetic.cpp b/src/boost/libs/hana/example/ext/std/ratio/arithmetic.cpp new file mode 100644 index 000000000..7bcdbbd3f --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/ratio/arithmetic.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 <boost/hana/assert.hpp> +#include <boost/hana/div.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/ratio.hpp> +#include <boost/hana/minus.hpp> +#include <boost/hana/mod.hpp> +#include <boost/hana/mult.hpp> +#include <boost/hana/one.hpp> +#include <boost/hana/plus.hpp> +#include <boost/hana/zero.hpp> + +#include <ratio> +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(std::ratio<5, 3>{}, std::ratio<3, 12>{}), + std::ratio<23, 12>{} +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::minus(std::ratio<5, 3>{}, std::ratio<3, 13>{}), + std::ratio<56, 39>{} +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::mult(std::ratio<5, 3>{}, std::ratio<3, 13>{}), + std::ratio<15, 39>{} +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::div(std::ratio<5, 3>{}, std::ratio<3, 13>{}), + std::ratio<65, 9>{} +)); + +// The mod of two ratios is always 0, because they can always be +// divided without remainder. +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::mod(std::ratio<5, 3>{}, std::ratio<3, 13>{}), + std::ratio<0>{} +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zero<hana::ext::std::ratio_tag>(), + std::ratio<0>{} +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::one<hana::ext::std::ratio_tag>(), + std::ratio<1>{} +)); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/ratio/comparable.cpp b/src/boost/libs/hana/example/ext/std/ratio/comparable.cpp new file mode 100644 index 000000000..05d64de32 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/ratio/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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/ratio.hpp> +#include <boost/hana/not_equal.hpp> + +#include <ratio> +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::equal(std::ratio<3, 4>{}, std::ratio<15, 20>{})); +BOOST_HANA_CONSTANT_CHECK(hana::not_equal(std::ratio<3, 4>{}, std::ratio<3, 5>{})); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/ratio/orderable.cpp b/src/boost/libs/hana/example/ext/std/ratio/orderable.cpp new file mode 100644 index 000000000..7764bb12a --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/ratio/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 <boost/hana/assert.hpp> +#include <boost/hana/ext/std/ratio.hpp> +#include <boost/hana/less.hpp> +#include <boost/hana/less_equal.hpp> + +#include <ratio> +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::less(std::ratio<3, 12>{}, std::ratio<5, 12>{})); +BOOST_HANA_CONSTANT_CHECK(hana::less_equal(std::ratio<6, 12>{}, std::ratio<4, 8>{})); + +int main() { } diff --git a/src/boost/libs/hana/example/ext/std/tuple.cpp b/src/boost/libs/hana/example/ext/std/tuple.cpp new file mode 100644 index 000000000..d545d6fb4 --- /dev/null +++ b/src/boost/libs/hana/example/ext/std/tuple.cpp @@ -0,0 +1,32 @@ +// 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/ext/std/tuple.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/transform.hpp> + +#include <string> +#include <tuple> +namespace hana = boost::hana; + + +struct Fish { std::string name; }; +struct Cat { std::string name; }; +struct Dog { std::string name; }; + +int main() { + std::tuple<Fish, Cat, Dog> animals{{"Nemo"}, {"Garfield"}, {"Snoopy"}}; + hana::front(animals).name = "Moby Dick"; + + auto names = hana::transform(animals, [](auto a) { + return a.name; + }); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + names, + std::make_tuple("Moby Dick", "Garfield", "Snoopy") + )); +} |