diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/hana/test/logical.cpp | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/hana/test/logical.cpp')
-rw-r--r-- | src/boost/libs/hana/test/logical.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/logical.cpp b/src/boost/libs/hana/test/logical.cpp new file mode 100644 index 00000000..b4148e48 --- /dev/null +++ b/src/boost/libs/hana/test/logical.cpp @@ -0,0 +1,84 @@ +// 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/concept/logical.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/eval_if.hpp> +#include <boost/hana/functional/always.hpp> +#include <boost/hana/not.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/while.hpp> + +#include <laws/logical.hpp> + +#include <vector> +namespace hana = boost::hana; + + +int main() { + hana::test::TestLogical<bool>{hana::make_tuple(true, false)}; + + // eval_if + { + BOOST_HANA_CONSTEXPR_CHECK(hana::equal( + hana::eval_if(true, hana::always(1), hana::always(2)), + 1 + )); + + BOOST_HANA_CONSTEXPR_CHECK(hana::equal( + hana::eval_if(false, hana::always(1), hana::always(2)), + 2 + )); + } + + // not_ + { + BOOST_HANA_CONSTEXPR_CHECK(hana::equal(hana::not_(true), false)); + BOOST_HANA_CONSTEXPR_CHECK(hana::equal(hana::not_(false), true)); + } + + // while_ + { + auto less_than = [](auto n) { + return [n](auto v) { return v.size() < n; }; + }; + auto f = [](auto v) { + v.push_back(v.size()); + return v; + }; + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(0u), std::vector<int>{}, f), + std::vector<int>{} + )); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(1u), std::vector<int>{}, f), + std::vector<int>{0} + )); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(2u), std::vector<int>{}, f), + std::vector<int>{0, 1} + )); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(3u), std::vector<int>{}, f), + std::vector<int>{0, 1, 2} + )); + + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(4u), std::vector<int>{}, f), + std::vector<int>{0, 1, 2, 3} + )); + + // Make sure it can be called with an lvalue state: + std::vector<int> v{}; + BOOST_HANA_RUNTIME_CHECK(hana::equal( + hana::while_(less_than(4u), v, f), + std::vector<int>{0, 1, 2, 3} + )); + } +} |