summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/example/tuple
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hana/example/tuple')
-rw-r--r--src/boost/libs/hana/example/tuple/foldable.cpp26
-rw-r--r--src/boost/libs/hana/example/tuple/interop.cpp34
-rw-r--r--src/boost/libs/hana/example/tuple/make.cpp19
-rw-r--r--src/boost/libs/hana/example/tuple/tuple.cpp29
-rw-r--r--src/boost/libs/hana/example/tuple/tuple_c.cpp22
-rw-r--r--src/boost/libs/hana/example/tuple/tuple_t.cpp19
6 files changed, 149 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/tuple/foldable.cpp b/src/boost/libs/hana/example/tuple/foldable.cpp
new file mode 100644
index 000000000..8a5354e39
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/foldable.cpp
@@ -0,0 +1,26 @@
+// 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/config.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/fold_right.hpp>
+#include <boost/hana/if.hpp>
+#include <boost/hana/less.hpp>
+#include <boost/hana/prepend.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+using namespace hana::literals;
+
+
+int main() {
+ constexpr auto numbers = hana::tuple_c<int, 5, -1, 0, -7, -2, 0, -5, 4>;
+ constexpr auto negatives = hana::tuple_c<int, -1, -7, -2, -5>;
+
+ BOOST_HANA_CONSTEXPR_LAMBDA auto keep_negatives = [](auto n, auto acc) {
+ return hana::if_(n < 0_c, hana::prepend(acc, n), acc);
+ };
+
+ BOOST_HANA_CONSTANT_CHECK(hana::fold_right(numbers, hana::tuple_c<int>, keep_negatives) == negatives);
+}
diff --git a/src/boost/libs/hana/example/tuple/interop.cpp b/src/boost/libs/hana/example/tuple/interop.cpp
new file mode 100644
index 000000000..cc274aee8
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/interop.cpp
@@ -0,0 +1,34 @@
+// 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/to.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/ext/std/array.hpp>
+#include <boost/hana/ext/std/tuple.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/range.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <array>
+#include <tuple>
+namespace hana = boost::hana;
+
+
+int main() {
+ static_assert(
+ hana::to_tuple(std::make_tuple(1, '2', 3.3)) == hana::make_tuple(1, '2', 3.3)
+ , "");
+
+ BOOST_HANA_CONSTANT_CHECK(
+ hana::to_tuple(hana::make_range(hana::int_c<1>, hana::int_c<4>))
+ ==
+ hana::make_tuple(hana::int_c<1>, hana::int_c<2>, hana::int_c<3>)
+ );
+
+ // std::array's operator[] is not constexpr, so we can't use static_assert
+ BOOST_HANA_CONSTEXPR_CHECK(
+ hana::to_tuple(std::array<int, 3>{{1, 2, 3}}) == hana::make_tuple(1, 2, 3)
+ );
+}
diff --git a/src/boost/libs/hana/example/tuple/make.cpp b/src/boost/libs/hana/example/tuple/make.cpp
new file mode 100644
index 000000000..e88fe38ac
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/make.cpp
@@ -0,0 +1,19 @@
+// 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/make.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <string>
+namespace hana = boost::hana;
+
+
+int main() {
+ auto xs = hana::make<hana::tuple_tag>(1, 2, '3', std::string{"456"});
+
+ constexpr auto ys = hana::make<hana::tuple_tag>(1, '2', 3.456);
+ static_assert(ys == hana::make_tuple(1, '2', 3.456), "");
+}
diff --git a/src/boost/libs/hana/example/tuple/tuple.cpp b/src/boost/libs/hana/example/tuple/tuple.cpp
new file mode 100644
index 000000000..e16ff8d07
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/tuple.cpp
@@ -0,0 +1,29 @@
+// 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/integral_constant.hpp>
+#include <boost/hana/transform.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <string>
+namespace hana = boost::hana;
+using namespace hana::literals;
+
+
+struct Fish { std::string name; };
+struct Cat { std::string name; };
+struct Dog { std::string name; };
+
+int main() {
+ hana::tuple<Fish, Cat, Dog> animals{{"Nemo"}, {"Garfield"}, {"Snoopy"}};
+ animals[0_c].name = "Moby Dick"; // can modify elements in place, like std::tuple
+
+ auto names = hana::transform(animals, [](auto a) {
+ return a.name;
+ });
+
+ BOOST_HANA_RUNTIME_CHECK(names == hana::make_tuple("Moby Dick", "Garfield", "Snoopy"));
+}
diff --git a/src/boost/libs/hana/example/tuple/tuple_c.cpp b/src/boost/libs/hana/example/tuple/tuple_c.cpp
new file mode 100644
index 000000000..012221745
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/tuple_c.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/core/to.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/front.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+int main() {
+ BOOST_HANA_CONSTANT_CHECK(
+ hana::tuple_c<int, 0, 1, 2>
+ ==
+ hana::make_tuple(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>)
+ );
+
+ BOOST_HANA_CONSTANT_CHECK(hana::front(hana::tuple_c<int, 0, 1, 2>) == hana::int_c<0>);
+}
diff --git a/src/boost/libs/hana/example/tuple/tuple_t.cpp b/src/boost/libs/hana/example/tuple/tuple_t.cpp
new file mode 100644
index 000000000..7da9107e5
--- /dev/null
+++ b/src/boost/libs/hana/example/tuple/tuple_t.cpp
@@ -0,0 +1,19 @@
+// 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/to.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/tuple.hpp>
+#include <boost/hana/type.hpp>
+namespace hana = boost::hana;
+
+
+int main() {
+ BOOST_HANA_CONSTANT_CHECK(
+ hana::to_tuple(hana::tuple_t<int, char, void, int(float)>)
+ ==
+ hana::make_tuple(hana::type_c<int>, hana::type_c<char>, hana::type_c<void>, hana::type_c<int(float)>)
+ );
+}