summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/test/logical.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hana/test/logical.cpp')
-rw-r--r--src/boost/libs/hana/test/logical.cpp84
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 000000000..b4148e482
--- /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}
+ ));
+ }
+}