summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/example/sequence
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/boost/libs/hana/example/sequence/applicative.cpp31
-rw-r--r--src/boost/libs/hana/example/sequence/comparable.cpp15
-rw-r--r--src/boost/libs/hana/example/sequence/foldable.cpp27
-rw-r--r--src/boost/libs/hana/example/sequence/functor.cpp26
-rw-r--r--src/boost/libs/hana/example/sequence/iterable.cpp19
-rw-r--r--src/boost/libs/hana/example/sequence/make.cpp15
-rw-r--r--src/boost/libs/hana/example/sequence/monad.ints.cpp21
-rw-r--r--src/boost/libs/hana/example/sequence/monad.types.cpp67
-rw-r--r--src/boost/libs/hana/example/sequence/monad_plus.cpp27
-rw-r--r--src/boost/libs/hana/example/sequence/orderable.cpp13
-rw-r--r--src/boost/libs/hana/example/sequence/searchable.cpp26
11 files changed, 287 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/sequence/applicative.cpp b/src/boost/libs/hana/example/sequence/applicative.cpp
new file mode 100644
index 000000000..c46ffcea8
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/applicative.cpp
@@ -0,0 +1,31 @@
+// 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/ap.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/ext/std/tuple.hpp>
+#include <boost/hana/functional/flip.hpp>
+#include <boost/hana/lift.hpp>
+#include <boost/hana/pair.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <tuple>
+namespace hana = boost::hana;
+
+
+static_assert(hana::lift<hana::tuple_tag>('x') == hana::make_tuple('x'), "");
+static_assert(hana::equal(hana::lift<hana::ext::std::tuple_tag>('x'), std::make_tuple('x')), "");
+
+constexpr auto f = hana::make_pair;
+constexpr auto g = hana::flip(hana::make_pair);
+static_assert(
+ hana::ap(hana::make_tuple(f, g), hana::make_tuple(1, 2, 3), hana::make_tuple('a', 'b'))
+ ==
+ hana::make_tuple(
+ f(1, 'a'), f(1, 'b'), f(2, 'a'), f(2, 'b'), f(3, 'a'), f(3, 'b'),
+ g(1, 'a'), g(1, 'b'), g(2, 'a'), g(2, 'b'), g(3, 'a'), g(3, 'b')
+ )
+, "");
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/comparable.cpp b/src/boost/libs/hana/example/sequence/comparable.cpp
new file mode 100644
index 000000000..5888a653a
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/comparable.cpp
@@ -0,0 +1,15 @@
+// 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/not_equal.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+static_assert(hana::make_tuple(1, 2, 3) == hana::make_tuple(1, 2, 3), "");
+BOOST_HANA_CONSTANT_CHECK(hana::make_tuple(1, 2, 3) != hana::make_tuple(1, 2, 3, 4));
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/foldable.cpp b/src/boost/libs/hana/example/sequence/foldable.cpp
new file mode 100644
index 000000000..cdef35f17
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/foldable.cpp
@@ -0,0 +1,27 @@
+// 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/fold_left.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <sstream>
+namespace hana = boost::hana;
+
+
+auto to_string = [](auto x) {
+ std::ostringstream ss;
+ ss << x;
+ return ss.str();
+};
+
+auto show = [](auto x, auto y) {
+ return "(" + to_string(x) + " + " + to_string(y) + ")";
+};
+
+int main() {
+ BOOST_HANA_RUNTIME_CHECK(
+ hana::fold_left(hana::make_tuple(2, "3", '4'), "1", show) == "(((1 + 2) + 3) + 4)"
+ );
+}
diff --git a/src/boost/libs/hana/example/sequence/functor.cpp b/src/boost/libs/hana/example/sequence/functor.cpp
new file mode 100644
index 000000000..0b26e6474
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/functor.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/equal.hpp>
+#include <boost/hana/transform.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <sstream>
+#include <string>
+namespace hana = boost::hana;
+
+
+auto to_string = [](auto x) {
+ std::ostringstream ss;
+ ss << x;
+ return ss.str();
+};
+
+int main() {
+ BOOST_HANA_RUNTIME_CHECK(
+ hana::transform(hana::make_tuple(1, '2', "345", std::string{"67"}), to_string) ==
+ hana::make_tuple("1", "2", "345", "67")
+ );
+}
diff --git a/src/boost/libs/hana/example/sequence/iterable.cpp b/src/boost/libs/hana/example/sequence/iterable.cpp
new file mode 100644
index 000000000..5a9a87944
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/iterable.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/drop_front.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/front.hpp>
+#include <boost/hana/is_empty.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+static_assert(hana::front(hana::make_tuple(1, '2', 3.3)) == 1, "");
+static_assert(hana::drop_front(hana::make_tuple(1, '2', 3.3)) == hana::make_tuple('2', 3.3), "");
+BOOST_HANA_CONSTANT_CHECK(!hana::is_empty(hana::make_tuple(1, '2', 3.3)));
+BOOST_HANA_CONSTANT_CHECK(hana::is_empty(hana::make_tuple()));
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/make.cpp b/src/boost/libs/hana/example/sequence/make.cpp
new file mode 100644
index 000000000..658e4a194
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/make.cpp
@@ -0,0 +1,15 @@
+// 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>
+namespace hana = boost::hana;
+
+
+BOOST_HANA_CONSTANT_CHECK(hana::make<hana::tuple_tag>() == hana::make_tuple());
+static_assert(hana::make<hana::tuple_tag>(1, '2', 3.3) == hana::make_tuple(1, '2', 3.3), "");
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/monad.ints.cpp b/src/boost/libs/hana/example/sequence/monad.ints.cpp
new file mode 100644
index 000000000..3dccdb8a9
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/monad.ints.cpp
@@ -0,0 +1,21 @@
+// 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/equal.hpp>
+#include <boost/hana/flatten.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+static_assert(
+ hana::flatten(hana::make_tuple(
+ hana::make_tuple(1, 2),
+ hana::make_tuple(3, 4),
+ hana::make_tuple(hana::make_tuple(5, 6))
+ ))
+ == hana::make_tuple(1, 2, 3, 4, hana::make_tuple(5, 6))
+, "");
+
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/monad.types.cpp b/src/boost/libs/hana/example/sequence/monad.types.cpp
new file mode 100644
index 000000000..27ea46da8
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/monad.types.cpp
@@ -0,0 +1,67 @@
+// 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/chain.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/for_each.hpp>
+#include <boost/hana/traits.hpp>
+#include <boost/hana/tuple.hpp>
+#include <boost/hana/type.hpp>
+
+#include <type_traits>
+#include <utility>
+namespace hana = boost::hana;
+
+
+// Using the `tuple` Monad, we generate all the possible combinations of
+// cv-qualifiers and reference qualifiers. Then, we use the `optional`
+// Monad to make sure that our generic function can be called with
+// arguments of any of those types.
+
+// cv_qualifiers : type -> tuple(type)
+auto cv_qualifiers = [](auto t) {
+ return hana::make_tuple(
+ t,
+ hana::traits::add_const(t),
+ hana::traits::add_volatile(t),
+ hana::traits::add_volatile(hana::traits::add_const(t))
+ );
+};
+
+// ref_qualifiers : type -> tuple(type)
+auto ref_qualifiers = [](auto t) {
+ return hana::make_tuple(
+ hana::traits::add_lvalue_reference(t),
+ hana::traits::add_rvalue_reference(t)
+ );
+};
+
+auto possible_args = cv_qualifiers(hana::type_c<int>) | ref_qualifiers;
+
+BOOST_HANA_CONSTANT_CHECK(
+ possible_args == hana::make_tuple(
+ hana::type_c<int&>,
+ hana::type_c<int&&>,
+ hana::type_c<int const&>,
+ hana::type_c<int const&&>,
+ hana::type_c<int volatile&>,
+ hana::type_c<int volatile&&>,
+ hana::type_c<int const volatile&>,
+ hana::type_c<int const volatile&&>
+ )
+);
+
+struct some_function {
+ template <typename T>
+ void operator()(T&&) const { }
+};
+
+int main() {
+ hana::for_each(possible_args, [](auto t) {
+ using T = typename decltype(t)::type;
+ static_assert(decltype(hana::is_valid(some_function{})(std::declval<T>())){},
+ "some_function should be callable with any type of argument");
+ });
+}
diff --git a/src/boost/libs/hana/example/sequence/monad_plus.cpp b/src/boost/libs/hana/example/sequence/monad_plus.cpp
new file mode 100644
index 000000000..ba2f89a3f
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/monad_plus.cpp
@@ -0,0 +1,27 @@
+// 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/append.hpp>
+#include <boost/hana/assert.hpp>
+#include <boost/hana/concat.hpp>
+#include <boost/hana/empty.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <string>
+namespace hana = boost::hana;
+using namespace std::string_literals;
+
+
+BOOST_HANA_CONSTANT_CHECK(hana::empty<hana::tuple_tag>() == hana::make_tuple());
+
+static_assert(hana::append(hana::make_tuple(1, '2', 3.3), nullptr)
+ == hana::make_tuple(1, '2', 3.3, nullptr), "");
+
+int main() {
+ BOOST_HANA_RUNTIME_CHECK(
+ hana::concat(hana::make_tuple(1, '2', 3.3), hana::make_tuple("abcdef"s)) ==
+ hana::make_tuple(1, '2', 3.3, "abcdef"s)
+ );
+}
diff --git a/src/boost/libs/hana/example/sequence/orderable.cpp b/src/boost/libs/hana/example/sequence/orderable.cpp
new file mode 100644
index 000000000..00003587d
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/orderable.cpp
@@ -0,0 +1,13 @@
+// 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/less.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+static_assert(hana::make_tuple(1, 2, 3) < hana::make_tuple(2, 3, 4), "");
+static_assert(hana::make_tuple(1, 2, 3) < hana::make_tuple(1, 2, 3, 4), "");
+
+int main() { }
diff --git a/src/boost/libs/hana/example/sequence/searchable.cpp b/src/boost/libs/hana/example/sequence/searchable.cpp
new file mode 100644
index 000000000..568592bfd
--- /dev/null
+++ b/src/boost/libs/hana/example/sequence/searchable.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/contains.hpp>
+#include <boost/hana/core/is_a.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/find_if.hpp>
+#include <boost/hana/optional.hpp>
+#include <boost/hana/tuple.hpp>
+
+#include <string>
+namespace hana = boost::hana;
+using namespace std::string_literals;
+
+
+int main() {
+ BOOST_HANA_RUNTIME_CHECK(
+ hana::find_if(hana::make_tuple(1, '2', 3.3, "abc"s), hana::is_a<std::string>) == hana::just("abc"s)
+ );
+
+ BOOST_HANA_RUNTIME_CHECK(
+ "abc"s ^hana::in^ hana::make_tuple(1, '2', 3.3, "abc"s)
+ );
+}