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 --- src/boost/libs/hana/example/map/comparable.cpp | 28 ++++++++ src/boost/libs/hana/example/map/difference.cpp | 45 +++++++++++++ src/boost/libs/hana/example/map/erase_key.cpp | 33 ++++++++++ src/boost/libs/hana/example/map/foldable.cpp | 39 +++++++++++ src/boost/libs/hana/example/map/insert.cpp | 32 +++++++++ src/boost/libs/hana/example/map/intersection.cpp | 47 +++++++++++++ src/boost/libs/hana/example/map/keys.cpp | 30 +++++++++ src/boost/libs/hana/example/map/make.cpp | 29 +++++++++ src/boost/libs/hana/example/map/map.cpp | 76 ++++++++++++++++++++++ src/boost/libs/hana/example/map/searchable.cpp | 30 +++++++++ .../libs/hana/example/map/symmetric_difference.cpp | 33 ++++++++++ src/boost/libs/hana/example/map/to.cpp | 30 +++++++++ src/boost/libs/hana/example/map/union.cpp | 53 +++++++++++++++ src/boost/libs/hana/example/map/values.cpp | 29 +++++++++ 14 files changed, 534 insertions(+) create mode 100644 src/boost/libs/hana/example/map/comparable.cpp create mode 100644 src/boost/libs/hana/example/map/difference.cpp create mode 100644 src/boost/libs/hana/example/map/erase_key.cpp create mode 100644 src/boost/libs/hana/example/map/foldable.cpp create mode 100644 src/boost/libs/hana/example/map/insert.cpp create mode 100644 src/boost/libs/hana/example/map/intersection.cpp create mode 100644 src/boost/libs/hana/example/map/keys.cpp create mode 100644 src/boost/libs/hana/example/map/make.cpp create mode 100644 src/boost/libs/hana/example/map/map.cpp create mode 100644 src/boost/libs/hana/example/map/searchable.cpp create mode 100644 src/boost/libs/hana/example/map/symmetric_difference.cpp create mode 100644 src/boost/libs/hana/example/map/to.cpp create mode 100644 src/boost/libs/hana/example/map/union.cpp create mode 100644 src/boost/libs/hana/example/map/values.cpp (limited to 'src/boost/libs/hana/example/map') diff --git a/src/boost/libs/hana/example/map/comparable.cpp b/src/boost/libs/hana/example/map/comparable.cpp new file mode 100644 index 000000000..4c3d348b0 --- /dev/null +++ b/src/boost/libs/hana/example/map/comparable.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 + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + BOOST_HANA_RUNTIME_CHECK( + hana::make_map( + hana::make_pair(hana::char_c<'a'>, "foobar"s), + hana::make_pair(hana::type_c, nullptr) + ) + == + hana::make_map( + hana::make_pair(hana::type_c, (void*)0), + hana::make_pair(hana::char_c<'a'>, "foobar"s) + ) + ); +} diff --git a/src/boost/libs/hana/example/map/difference.cpp b/src/boost/libs/hana/example/map/difference.cpp new file mode 100644 index 000000000..6b94b0a22 --- /dev/null +++ b/src/boost/libs/hana/example/map/difference.cpp @@ -0,0 +1,45 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +static auto m1 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c) +); + +static auto m2 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c) +); + +static auto m3 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c) +); + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::difference(m1, m2) == m1); + + BOOST_HANA_CONSTANT_CHECK(hana::difference(m1, m3) == hana::make_map()); + + BOOST_HANA_CONSTANT_CHECK(hana::difference(m3, m1) == hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::difference(m2, m3) == hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c) + )); +} diff --git a/src/boost/libs/hana/example/map/erase_key.cpp b/src/boost/libs/hana/example/map/erase_key.cpp new file mode 100644 index 000000000..2ba407145 --- /dev/null +++ b/src/boost/libs/hana/example/map/erase_key.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 +#include +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + auto m = hana::make_map( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234), + hana::make_pair(BOOST_HANA_STRING("foobar!"), hana::type_c) + ); + + BOOST_HANA_RUNTIME_CHECK( + hana::erase_key(m, BOOST_HANA_STRING("foobar!")) == + hana::make_map( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234) + ) + ); + + BOOST_HANA_RUNTIME_CHECK(hana::erase_key(m, hana::type_c) == m); +} diff --git a/src/boost/libs/hana/example/map/foldable.cpp b/src/boost/libs/hana/example/map/foldable.cpp new file mode 100644 index 000000000..1884220a3 --- /dev/null +++ b/src/boost/libs/hana/example/map/foldable.cpp @@ -0,0 +1,39 @@ +// 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 +namespace hana = boost::hana; + + +int main() { + // Given a map of (key, value) pairs, returns a map of (value, key) pairs. + // This requires both the keys and the values to be compile-time Comparable. + auto invert = [](auto map) { + return hana::fold_left(map, hana::make_map(), [](auto map, auto pair) { + return hana::insert(map, hana::make_pair(hana::second(pair), hana::first(pair))); + }); + }; + + auto m = hana::make_map( + hana::make_pair(hana::type_c, hana::int_c<1>), + hana::make_pair(hana::type_c, hana::int_c<2>), + hana::make_pair(hana::int_c<3>, hana::type_c) + ); + + BOOST_HANA_CONSTANT_CHECK(invert(m) == + hana::make_map( + hana::make_pair(hana::int_c<1>, hana::type_c), + hana::make_pair(hana::int_c<2>, hana::type_c), + hana::make_pair(hana::type_c, hana::int_c<3>) + ) + ); +} diff --git a/src/boost/libs/hana/example/map/insert.cpp b/src/boost/libs/hana/example/map/insert.cpp new file mode 100644 index 000000000..80aff7d5f --- /dev/null +++ b/src/boost/libs/hana/example/map/insert.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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + auto m = hana::make_map( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234) + ); + + BOOST_HANA_RUNTIME_CHECK( + hana::insert(m, hana::make_pair(hana::type_c, 'x')) == + hana::make_map( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234), + hana::make_pair(hana::type_c, 'x') + ) + ); + + BOOST_HANA_RUNTIME_CHECK(hana::insert(m, hana::make_pair(hana::type_c, 'x')) == m); +} diff --git a/src/boost/libs/hana/example/map/intersection.cpp b/src/boost/libs/hana/example/map/intersection.cpp new file mode 100644 index 000000000..1be8bf0b9 --- /dev/null +++ b/src/boost/libs/hana/example/map/intersection.cpp @@ -0,0 +1,47 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using namespace hana::literals; + + +static auto m1 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c) +); + +static auto m2 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c) +); + +BOOST_HANA_CONSTANT_CHECK(hana::intersection(m1, m2) == hana::make_map()); + +static auto m3 = hana::make_map( + hana::make_pair(hana::type_c, hana::int_c<1>), + hana::make_pair(hana::type_c, hana::bool_c), + hana::make_pair(hana::type_c, BOOST_HANA_STRING("hana")), + hana::make_pair(hana::type_c, hana::int_c<100>) +); + +static auto m4 = hana::make_map( + hana::make_pair(hana::type_c, hana::char_c<'c'>), + hana::make_pair(hana::type_c, hana::bool_c), + hana::make_pair(hana::type_c, BOOST_HANA_STRING("boost")) +); + +BOOST_HANA_CONSTANT_CHECK(hana::intersection(m3, m4) == hana::make_map( + hana::make_pair(hana::type_c, hana::bool_c), + hana::make_pair(hana::type_c, BOOST_HANA_STRING("hana")) +)); + +int main() { } diff --git a/src/boost/libs/hana/example/map/keys.cpp b/src/boost/libs/hana/example/map/keys.cpp new file mode 100644 index 000000000..073d6dec6 --- /dev/null +++ b/src/boost/libs/hana/example/map/keys.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 +#include +#include +#include +#include +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + auto m = hana::make_map( + hana::make_pair(hana::int_c<1>, "foobar"s), + hana::make_pair(hana::type_c, 1234) + ); + + // The order of the keys is unspecified. + BOOST_HANA_CONSTANT_CHECK( + hana::keys(m) ^hana::in^ hana::permutations(hana::make_tuple(hana::int_c<1>, hana::type_c)) + ); +} diff --git a/src/boost/libs/hana/example/map/make.cpp b/src/boost/libs/hana/example/map/make.cpp new file mode 100644 index 000000000..a9660e1cb --- /dev/null +++ b/src/boost/libs/hana/example/map/make.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 +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + BOOST_HANA_RUNTIME_CHECK( + hana::make_map( + hana::make_pair(hana::int_c<1>, "foobar"s), + hana::make_pair(hana::type_c, 1234) + ) + == + hana::make( + hana::make_pair(hana::int_c<1>, "foobar"s), + hana::make_pair(hana::type_c, 1234) + ) + ); +} diff --git a/src/boost/libs/hana/example/map/map.cpp b/src/boost/libs/hana/example/map/map.cpp new file mode 100644 index 000000000..a04ecfd73 --- /dev/null +++ b/src/boost/libs/hana/example/map/map.cpp @@ -0,0 +1,76 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +namespace hana = boost::hana; + + +template +struct event_system { + using Callback = std::function; + hana::map>...> map_; + + template + void on(Event e, F handler) { + auto is_known_event = hana::contains(map_, e); + static_assert(is_known_event, + "trying to add a handler to an unknown event"); + + map_[e].push_back(handler); + } + + template + void trigger(Event e) const { + auto is_known_event = hana::contains(map_, e); + static_assert(is_known_event, + "trying to trigger an unknown event"); + + for (auto& handler : this->map_[e]) + handler(); + } +}; + +template +event_system make_event_system(Events ...events) { + return {}; +} + + +int main() { + auto events = make_event_system( + BOOST_HANA_STRING("foo"), + BOOST_HANA_STRING("bar"), + BOOST_HANA_STRING("baz") + ); + + std::vector triggered_events; + events.on(BOOST_HANA_STRING("foo"), [&] { + triggered_events.push_back("foo:1"); + }); + events.on(BOOST_HANA_STRING("foo"), [&] { + triggered_events.push_back("foo:2"); + }); + events.on(BOOST_HANA_STRING("bar"), [&] { + triggered_events.push_back("bar:1"); + }); + events.on(BOOST_HANA_STRING("baz"), [&] { + triggered_events.push_back("baz:1"); + }); + + events.trigger(BOOST_HANA_STRING("foo")); + events.trigger(BOOST_HANA_STRING("bar")); + events.trigger(BOOST_HANA_STRING("baz")); + + BOOST_HANA_RUNTIME_CHECK(triggered_events == std::vector{ + "foo:1", "foo:2", "bar:1", "baz:1" + }); +} diff --git a/src/boost/libs/hana/example/map/searchable.cpp b/src/boost/libs/hana/example/map/searchable.cpp new file mode 100644 index 000000000..4f51e704e --- /dev/null +++ b/src/boost/libs/hana/example/map/searchable.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 +#include +#include +#include +#include +#include +namespace hana = boost::hana; + + +constexpr auto m = hana::make_map( + hana::make_pair(hana::type_c, 'i'), + hana::make_pair(hana::type_c, 'f') +); +static_assert(hana::find(m, hana::type_c) == hana::just('i'), ""); +static_assert(hana::find(m, hana::type_c) == hana::just('f'), ""); +BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::type_c) == hana::nothing); +BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::int_c<3>) == hana::nothing); + +// operator[] is equivalent to at_key +static_assert(m[hana::type_c] == 'i', ""); +static_assert(m[hana::type_c] == 'f', ""); + +int main() { } diff --git a/src/boost/libs/hana/example/map/symmetric_difference.cpp b/src/boost/libs/hana/example/map/symmetric_difference.cpp new file mode 100644 index 000000000..0f9784756 --- /dev/null +++ b/src/boost/libs/hana/example/map/symmetric_difference.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; + + +constexpr auto m1 = hana::make_map( + hana::make_pair(hana::type_c, 1), + hana::make_pair(hana::type_c, hana::true_c) +); + +constexpr auto m2 = hana::make_map( + hana::make_pair(hana::type_c, 1.0), + hana::make_pair(hana::type_c, 2LL), + hana::make_pair(hana::type_c, 3) +); + +constexpr auto result_m = hana::make_map( + hana::make_pair(hana::type_c, hana::true_c), + hana::make_pair(hana::type_c, 1.0), + hana::make_pair(hana::type_c, 2LL) +); + +int main() { + BOOST_HANA_RUNTIME_CHECK( + hana::symmetric_difference(m1, m2) == result_m + ); +} diff --git a/src/boost/libs/hana/example/map/to.cpp b/src/boost/libs/hana/example/map/to.cpp new file mode 100644 index 000000000..550c7665e --- /dev/null +++ b/src/boost/libs/hana/example/map/to.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 +#include +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + auto xs = hana::make_tuple( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234), + hana::make_pair(hana::type_c, nullptr) + ); + + BOOST_HANA_RUNTIME_CHECK( + hana::to(xs) == hana::make_map( + hana::make_pair(hana::type_c, "abcd"s), + hana::make_pair(hana::type_c, 1234) + ) + ); +} diff --git a/src/boost/libs/hana/example/map/union.cpp b/src/boost/libs/hana/example/map/union.cpp new file mode 100644 index 000000000..d214b34df --- /dev/null +++ b/src/boost/libs/hana/example/map/union.cpp @@ -0,0 +1,53 @@ +// 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 namespace hana::literals; + + +static auto m1 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c) +); + +static auto m2 = hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c) +); + +BOOST_HANA_CONSTANT_CHECK(hana::union_(m1, m2) == hana::make_map( + hana::make_pair(BOOST_HANA_STRING("key1"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key2"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key3"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key4"), hana::type_c), + hana::make_pair(BOOST_HANA_STRING("key5"), hana::type_c) +)); + +constexpr auto m3 = hana::make_map( + hana::make_pair(hana::type_c, hana::int_c<1>), + hana::make_pair(hana::type_c, hana::bool_c) +); + +constexpr auto m4 = hana::make_map( + hana::make_pair(hana::type_c, hana::char_c<'c'>), + hana::make_pair(hana::type_c, hana::bool_c) +); + +BOOST_HANA_CONSTANT_CHECK(hana::union_(m3, m4) == hana::make_map( + hana::make_pair(hana::type_c, hana::int_c<1>), + hana::make_pair(hana::type_c, hana::bool_c), + hana::make_pair(hana::type_c, hana::char_c<'c'>) +)); + +int main() { } diff --git a/src/boost/libs/hana/example/map/values.cpp b/src/boost/libs/hana/example/map/values.cpp new file mode 100644 index 000000000..4bbfb92f5 --- /dev/null +++ b/src/boost/libs/hana/example/map/values.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 +#include +#include +#include + +#include +namespace hana = boost::hana; +using namespace std::literals; + + +int main() { + auto m = hana::make_map( + hana::make_pair(hana::int_c<1>, "foobar"s), + hana::make_pair(hana::type_c, 1234) + ); + + // The order of the values is unspecified. + BOOST_HANA_RUNTIME_CHECK( + hana::values(m) ^hana::in^ hana::permutations(hana::make_tuple("foobar"s, 1234)) + ); +} -- cgit v1.2.3