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/test/integral_constant/times.cpp | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.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/test/integral_constant/times.cpp')
-rw-r--r-- | src/boost/libs/hana/test/integral_constant/times.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/integral_constant/times.cpp b/src/boost/libs/hana/test/integral_constant/times.cpp new file mode 100644 index 000000000..51f354fd7 --- /dev/null +++ b/src/boost/libs/hana/test/integral_constant/times.cpp @@ -0,0 +1,61 @@ +// 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/core/is_a.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/value.hpp> +namespace hana = boost::hana; + + +void function() { } +void function_index(...) { } + +int main() { + // times member function + { + int counter = 0; + hana::int_c<3>.times([&] { ++counter; }); + BOOST_HANA_RUNTIME_CHECK(counter == 3); + + // Call .times with a normal function used to fail. + hana::int_c<3>.times(function); + + // make sure times can be accessed as a static member function too + decltype(hana::int_c<5>)::times([]{ }); + + // make sure xxx.times can be used as a function object + auto z = hana::int_c<5>.times; + (void)z; + } + + // times.with_index + { + int index = 0; + hana::int_c<3>.times.with_index([&](auto i) { + static_assert(hana::is_an<hana::integral_constant_tag<int>>(i), ""); + BOOST_HANA_RUNTIME_CHECK(hana::value(i) == index); + ++index; + }); + + // Calling .times.with_index with a normal function used to fail. + hana::int_c<3>.times.with_index(function_index); + + // make sure times.with_index can be accessed as a static member + // function too + auto times = hana::int_c<5>.times; + decltype(times)::with_index([](auto) { }); + + // make sure xxx.times.with_index can be used as a function object + auto z = hana::int_c<5>.times.with_index; + (void)z; + + // make sure we're calling the function in the right order + int current = 0; + hana::int_c<5>.times.with_index([&](auto i) { + BOOST_HANA_RUNTIME_CHECK(hana::value(i) == current); + ++current; + }); + } +} |