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/find_if.cpp | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.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/find_if.cpp')
-rw-r--r-- | src/boost/libs/hana/example/find_if.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/find_if.cpp b/src/boost/libs/hana/example/find_if.cpp new file mode 100644 index 000000000..73264683a --- /dev/null +++ b/src/boost/libs/hana/example/find_if.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 <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/ext/std/integral_constant.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/functional/compose.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/type.hpp> + +#include <type_traits> +namespace hana = boost::hana; + + +// First get the type of the object, and then call the trait on it. +constexpr auto is_integral = hana::compose(hana::trait<std::is_integral>, hana::typeid_); +constexpr auto is_class = hana::compose(hana::trait<std::is_class>, hana::typeid_); + +static_assert( + hana::find_if(hana::make_tuple(1.0, 2, '3'), is_integral) == hana::just(2) +, ""); + +BOOST_HANA_CONSTANT_CHECK( + hana::find_if(hana::make_tuple(1.0, 2, '3'), is_class) == hana::nothing +); + +constexpr auto types = hana::tuple_t<char, int, unsigned, long, unsigned long>; +BOOST_HANA_CONSTANT_CHECK( + hana::find_if(types, hana::equal.to(hana::type_c<unsigned>)) == hana::just(hana::type_c<unsigned>) +); +BOOST_HANA_CONSTANT_CHECK( + hana::find_if(types, hana::equal.to(hana::type_c<void>)) == hana::nothing +); + +int main() { } |