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/type/alignof.cpp | 16 ++++++++++ src/boost/libs/hana/example/type/basic_type.cpp | 31 +++++++++++++++++++ src/boost/libs/hana/example/type/comparable.cpp | 17 ++++++++++ src/boost/libs/hana/example/type/decltype.cpp | 20 ++++++++++++ src/boost/libs/hana/example/type/hashable.cpp | 23 ++++++++++++++ src/boost/libs/hana/example/type/integral.cpp | 18 +++++++++++ src/boost/libs/hana/example/type/is_valid.cpp | 31 +++++++++++++++++++ src/boost/libs/hana/example/type/make.cpp | 19 ++++++++++++ src/boost/libs/hana/example/type/metafunction.cpp | 26 ++++++++++++++++ .../libs/hana/example/type/metafunction_class.cpp | 26 ++++++++++++++++ src/boost/libs/hana/example/type/sizeof.cpp | 16 ++++++++++ src/boost/libs/hana/example/type/template.cpp | 26 ++++++++++++++++ src/boost/libs/hana/example/type/trait.cpp | 17 ++++++++++ src/boost/libs/hana/example/type/typeid.cpp | 36 ++++++++++++++++++++++ 14 files changed, 322 insertions(+) create mode 100644 src/boost/libs/hana/example/type/alignof.cpp create mode 100644 src/boost/libs/hana/example/type/basic_type.cpp create mode 100644 src/boost/libs/hana/example/type/comparable.cpp create mode 100644 src/boost/libs/hana/example/type/decltype.cpp create mode 100644 src/boost/libs/hana/example/type/hashable.cpp create mode 100644 src/boost/libs/hana/example/type/integral.cpp create mode 100644 src/boost/libs/hana/example/type/is_valid.cpp create mode 100644 src/boost/libs/hana/example/type/make.cpp create mode 100644 src/boost/libs/hana/example/type/metafunction.cpp create mode 100644 src/boost/libs/hana/example/type/metafunction_class.cpp create mode 100644 src/boost/libs/hana/example/type/sizeof.cpp create mode 100644 src/boost/libs/hana/example/type/template.cpp create mode 100644 src/boost/libs/hana/example/type/trait.cpp create mode 100644 src/boost/libs/hana/example/type/typeid.cpp (limited to 'src/boost/libs/hana/example/type') diff --git a/src/boost/libs/hana/example/type/alignof.cpp b/src/boost/libs/hana/example/type/alignof.cpp new file mode 100644 index 000000000..b4fb94525 --- /dev/null +++ b/src/boost/libs/hana/example/type/alignof.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 +namespace hana = boost::hana; + + +struct X { }; +static_assert(hana::alignof_(hana::type_c) == alignof(X), ""); + +static_assert(hana::alignof_(1) == alignof(decltype(1)), ""); +static_assert(hana::alignof_(hana::type_c) == alignof(int), ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/basic_type.cpp b/src/boost/libs/hana/example/type/basic_type.cpp new file mode 100644 index 000000000..e3104d655 --- /dev/null +++ b/src/boost/libs/hana/example/type/basic_type.cpp @@ -0,0 +1,31 @@ +// 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 hana::type as a parameter type wouldn't work, since it may be +// a dependent type, in which case template argument deduction will fail. +// Using hana::basic_type is fine, since this one is guaranteed to be +// a non dependent base of hana::type. +template +std::string const& name_of(hana::basic_type) { + static std::string name = boost::core::demangle(typeid(T).name()); + return name; +} + +int main() { + hana::for_each(hana::tuple_t, [](auto type) { + std::cout << name_of(type) << std::endl; + }); +} diff --git a/src/boost/libs/hana/example/type/comparable.cpp b/src/boost/libs/hana/example/type/comparable.cpp new file mode 100644 index 000000000..19eb282bd --- /dev/null +++ b/src/boost/libs/hana/example/type/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; + + +struct T; +struct U; +BOOST_HANA_CONSTANT_CHECK(hana::type_c == hana::type_c); +BOOST_HANA_CONSTANT_CHECK(hana::type_c != hana::type_c); + +int main() { } diff --git a/src/boost/libs/hana/example/type/decltype.cpp b/src/boost/libs/hana/example/type/decltype.cpp new file mode 100644 index 000000000..45110f1ac --- /dev/null +++ b/src/boost/libs/hana/example/type/decltype.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 +namespace hana = boost::hana; + + +struct X { }; +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(X{}) == hana::type_c); +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(hana::type_c) == hana::type_c); + +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(1) == hana::type_c); + +static int const& i = 1; +BOOST_HANA_CONSTANT_CHECK(hana::decltype_(i) == hana::type_c); + +int main() { } diff --git a/src/boost/libs/hana/example/type/hashable.cpp b/src/boost/libs/hana/example/type/hashable.cpp new file mode 100644 index 000000000..eaecfff12 --- /dev/null +++ b/src/boost/libs/hana/example/type/hashable.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 +namespace hana = boost::hana; + + +// `hana::hash` is the identity on `hana::type`s. +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::type_c), + hana::type_c +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::type_c), + hana::type_c +)); + +int main() { } diff --git a/src/boost/libs/hana/example/type/integral.cpp b/src/boost/libs/hana/example/type/integral.cpp new file mode 100644 index 000000000..612665de9 --- /dev/null +++ b/src/boost/libs/hana/example/type/integral.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; + + +constexpr auto is_void = hana::integral(hana::metafunction); +BOOST_HANA_CONSTANT_CHECK(is_void(hana::type_c)); +BOOST_HANA_CONSTANT_CHECK(hana::not_(is_void(hana::type_c))); + +int main() { } diff --git a/src/boost/libs/hana/example/type/is_valid.cpp b/src/boost/libs/hana/example/type/is_valid.cpp new file mode 100644 index 000000000..a683e78f1 --- /dev/null +++ b/src/boost/libs/hana/example/type/is_valid.cpp @@ -0,0 +1,31 @@ +// 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() { + // Checking for a member + struct Person { std::string name; }; + auto has_name = hana::is_valid([](auto&& p) -> decltype((void)p.name) { }); + + Person joe{"Joe"}; + static_assert(has_name(joe), ""); + static_assert(!has_name(1), ""); + + + // Checking for a nested type + auto has_value_type = hana::is_valid([](auto t) -> hana::type< + typename decltype(t)::type::value_type + > { }); + + static_assert(has_value_type(hana::type_c>), ""); + static_assert(!has_value_type(hana::type_c), ""); +} diff --git a/src/boost/libs/hana/example/type/make.cpp b/src/boost/libs/hana/example/type/make.cpp new file mode 100644 index 000000000..97bb4a11f --- /dev/null +++ b/src/boost/libs/hana/example/type/make.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; + + +struct X { }; +BOOST_HANA_CONSTANT_CHECK(hana::make(X{}) == hana::type_c); +BOOST_HANA_CONSTANT_CHECK(hana::make(hana::type_c) == hana::type_c); + +BOOST_HANA_CONSTANT_CHECK(hana::make_type(X{}) == hana::type_c); +BOOST_HANA_CONSTANT_CHECK(hana::make_type(hana::type_c) == hana::type_c); + +int main() { } diff --git a/src/boost/libs/hana/example/type/metafunction.cpp b/src/boost/libs/hana/example/type/metafunction.cpp new file mode 100644 index 000000000..a60d60778 --- /dev/null +++ b/src/boost/libs/hana/example/type/metafunction.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; + + +template struct f { struct type; }; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::metafunction() == hana::type_c::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction(hana::type_c) == hana::type_c::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction(hana::type_c, hana::type_c) == hana::type_c::type>); + +static_assert(std::is_same< + decltype(hana::metafunction)::apply::type, + f::type +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/metafunction_class.cpp b/src/boost/libs/hana/example/type/metafunction_class.cpp new file mode 100644 index 000000000..f01e26719 --- /dev/null +++ b/src/boost/libs/hana/example/type/metafunction_class.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; + + +struct f { template struct apply { struct type; }; }; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class() == hana::type_c::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class(hana::type_c) == hana::type_c::type>); +BOOST_HANA_CONSTANT_CHECK(hana::metafunction_class(hana::type_c, hana::type_c) == hana::type_c::type>); + +static_assert(std::is_same< + decltype(hana::metafunction_class)::apply::type, + f::apply::type +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/sizeof.cpp b/src/boost/libs/hana/example/type/sizeof.cpp new file mode 100644 index 000000000..300015dd2 --- /dev/null +++ b/src/boost/libs/hana/example/type/sizeof.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 +namespace hana = boost::hana; + + +struct X { }; +static_assert(hana::sizeof_(hana::type_c) == sizeof(X), ""); + +static_assert(hana::sizeof_(1) == sizeof(1), ""); +static_assert(hana::sizeof_(hana::type_c) == sizeof(int), ""); + +int main() {} diff --git a/src/boost/libs/hana/example/type/template.cpp b/src/boost/libs/hana/example/type/template.cpp new file mode 100644 index 000000000..3840cc7c0 --- /dev/null +++ b/src/boost/libs/hana/example/type/template.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; + + +template struct f; +struct x; +struct y; + +BOOST_HANA_CONSTANT_CHECK(hana::template_() == hana::type_c>); +BOOST_HANA_CONSTANT_CHECK(hana::template_(hana::type_c) == hana::type_c>); +BOOST_HANA_CONSTANT_CHECK(hana::template_(hana::type_c, hana::type_c) == hana::type_c>); + +static_assert(std::is_same< + decltype(hana::template_)::apply::type, + f +>::value, ""); + +int main() { } diff --git a/src/boost/libs/hana/example/type/trait.cpp b/src/boost/libs/hana/example/type/trait.cpp new file mode 100644 index 000000000..31064bc7b --- /dev/null +++ b/src/boost/libs/hana/example/type/trait.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 + +#include +namespace hana = boost::hana; + + +BOOST_HANA_CONSTANT_CHECK(hana::trait(hana::type_c)); +BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::trait(hana::type_c))); + +int main() { } diff --git a/src/boost/libs/hana/example/type/typeid.cpp b/src/boost/libs/hana/example/type/typeid.cpp new file mode 100644 index 000000000..f219aec39 --- /dev/null +++ b/src/boost/libs/hana/example/type/typeid.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 + +#include +namespace hana = boost::hana; + + +struct Cat { std::string name; }; +struct Dog { std::string name; }; +struct Fish { std::string name; }; + +bool operator==(Cat const& a, Cat const& b) { return a.name == b.name; } +bool operator!=(Cat const& a, Cat const& b) { return a.name != b.name; } +bool operator==(Dog const& a, Dog const& b) { return a.name == b.name; } +bool operator!=(Dog const& a, Dog const& b) { return a.name != b.name; } +bool operator==(Fish const& a, Fish const& b) { return a.name == b.name; } +bool operator!=(Fish const& a, Fish const& b) { return a.name != b.name; } + +int main() { + hana::tuple animals{ + Cat{"Garfield"}, Fish{"Jaws"}, Dog{"Beethoven"}, Fish{"Nemo"} + }; + + auto mammals = hana::remove_if(animals, [](auto const& a) { + return hana::typeid_(a) == hana::type{}; + }); + + BOOST_HANA_RUNTIME_CHECK(mammals == hana::make_tuple(Cat{"Garfield"}, Dog{"Beethoven"})); +} -- cgit v1.2.3