summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/example/ext/std/integer_sequence
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hana/example/ext/std/integer_sequence')
-rw-r--r--src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp22
-rw-r--r--src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp25
-rw-r--r--src/boost/libs/hana/example/ext/std/integer_sequence/iterable.cpp23
-rw-r--r--src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp25
4 files changed, 95 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp
new file mode 100644
index 000000000..10b62752a
--- /dev/null
+++ b/src/boost/libs/hana/example/ext/std/integer_sequence/comparable.cpp
@@ -0,0 +1,22 @@
+// 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/ext/std/integer_sequence.hpp>
+#include <boost/hana/not_equal.hpp>
+
+#include <utility>
+namespace hana = boost::hana;
+
+
+constexpr std::integer_sequence<int, 1, 2, 3, 4> xs{};
+constexpr std::integer_sequence<long, 1, 2, 3, 4> ys{};
+constexpr std::integer_sequence<long, 1, 2, 3, 4, 5> zs{};
+
+BOOST_HANA_CONSTANT_CHECK(hana::equal(xs, ys));
+BOOST_HANA_CONSTANT_CHECK(hana::not_equal(xs, zs));
+BOOST_HANA_CONSTANT_CHECK(hana::not_equal(ys, zs));
+
+int main() { }
diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp
new file mode 100644
index 000000000..4d7c3253f
--- /dev/null
+++ b/src/boost/libs/hana/example/ext/std/integer_sequence/foldable.cpp
@@ -0,0 +1,25 @@
+// 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/ext/std/integer_sequence.hpp>
+#include <boost/hana/unpack.hpp>
+
+#include <tuple>
+#include <utility>
+namespace hana = boost::hana;
+
+
+auto add = [](auto a, auto b, auto c) { return a + b + c; };
+
+int main() {
+ std::tuple<int, long, double> tuple{1, 2l, 3.3};
+
+ auto sum = hana::unpack(std::integer_sequence<int, 0, 1, 2>{}, [&](auto ...i) {
+ // the `i`s are `std::integral_constant<int, ...>`s
+ return add(std::get<decltype(i)::value>(tuple)...);
+ });
+
+ BOOST_HANA_RUNTIME_CHECK(sum == 6.3);
+}
diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.cpp
new file mode 100644
index 000000000..ef421ec37
--- /dev/null
+++ b/src/boost/libs/hana/example/ext/std/integer_sequence/iterable.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 <boost/hana/assert.hpp>
+#include <boost/hana/at.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/ext/std/integer_sequence.hpp>
+#include <boost/hana/ext/std/integral_constant.hpp>
+
+#include <type_traits>
+#include <utility>
+namespace hana = boost::hana;
+
+
+constexpr std::integer_sequence<int, 0, 1, 2, 3, 4> indices{};
+
+BOOST_HANA_CONSTANT_CHECK(hana::equal(
+ hana::at_c<2>(indices),
+ std::integral_constant<int, 2>{}
+));
+
+int main() { }
diff --git a/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp b/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp
new file mode 100644
index 000000000..c0a159bc8
--- /dev/null
+++ b/src/boost/libs/hana/example/ext/std/integer_sequence/searchable.cpp
@@ -0,0 +1,25 @@
+// 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/ext/std/integer_sequence.hpp>
+#include <boost/hana/ext/std/integral_constant.hpp>
+#include <boost/hana/find.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/optional.hpp>
+
+#include <type_traits>
+#include <utility>
+namespace hana = boost::hana;
+
+
+constexpr std::integer_sequence<int, 1, 2, 3, 4> xs{};
+
+BOOST_HANA_CONSTANT_CHECK(hana::equal(
+ hana::find(xs, hana::int_c<3>),
+ hana::just(std::integral_constant<int, 3>{})
+));
+
+int main() { }