summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/test/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hana/test/core')
-rw-r--r--src/boost/libs/hana/test/core/common.cpp32
-rw-r--r--src/boost/libs/hana/test/core/default.cpp18
-rw-r--r--src/boost/libs/hana/test/core/is_a.cpp18
-rw-r--r--src/boost/libs/hana/test/core/is_embedded.cpp62
-rw-r--r--src/boost/libs/hana/test/core/make.cpp16
-rw-r--r--src/boost/libs/hana/test/core/tag_of.cpp74
-rw-r--r--src/boost/libs/hana/test/core/to.cpp106
-rw-r--r--src/boost/libs/hana/test/core/when.cpp24
8 files changed, 350 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/core/common.cpp b/src/boost/libs/hana/test/core/common.cpp
new file mode 100644
index 000000000..c3b24f900
--- /dev/null
+++ b/src/boost/libs/hana/test/core/common.cpp
@@ -0,0 +1,32 @@
+// 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/core/common.hpp>
+
+#include <type_traits>
+namespace hana = boost::hana;
+
+
+template <typename T>
+struct ImplicitConvertibleTo {
+ constexpr operator T() const { return {}; }
+};
+
+struct T { };
+struct invalid;
+
+static_assert(std::is_same<hana::common_t<T, T>, T>{}, "");
+static_assert(std::is_same<hana::common_t<invalid, invalid>, invalid>{}, "");
+static_assert(std::is_same<hana::common_t<void, void>, void>{}, "");
+
+static_assert(std::is_same<hana::common_t<ImplicitConvertibleTo<T>, T>, T>{}, "");
+static_assert(std::is_same<hana::common_t<T, ImplicitConvertibleTo<T>>, T>{}, "");
+
+static_assert(hana::has_common<T, T>{}, "");
+static_assert(!hana::has_common<void, T>{}, "");
+static_assert(!hana::has_common<T, void>{}, "");
+static_assert(!hana::has_common<invalid, T>{}, "");
+static_assert(!hana::has_common<T, invalid>{}, "");
+
+int main() { }
diff --git a/src/boost/libs/hana/test/core/default.cpp b/src/boost/libs/hana/test/core/default.cpp
new file mode 100644
index 000000000..9846c22b8
--- /dev/null
+++ b/src/boost/libs/hana/test/core/default.cpp
@@ -0,0 +1,18 @@
+// 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/core/default.hpp>
+namespace hana = boost::hana;
+
+
+template <typename T>
+struct method_impl : hana::default_ { };
+
+template <>
+struct method_impl<int> { };
+
+static_assert(hana::is_default<method_impl<void>>{}, "");
+static_assert(!hana::is_default<method_impl<int>>{}, "");
+
+int main() { }
diff --git a/src/boost/libs/hana/test/core/is_a.cpp b/src/boost/libs/hana/test/core/is_a.cpp
new file mode 100644
index 000000000..08d390030
--- /dev/null
+++ b/src/boost/libs/hana/test/core/is_a.cpp
@@ -0,0 +1,18 @@
+// 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/core/is_a.hpp>
+namespace hana = boost::hana;
+
+
+int main() {
+ // This used to trigger a compilation error on Clang 3.5.
+ {
+ auto f = [](auto i) {
+ constexpr auto result = hana::is_an<int>(i);
+ (void)result;
+ };
+ f(1);
+ }
+}
diff --git a/src/boost/libs/hana/test/core/is_embedded.cpp b/src/boost/libs/hana/test/core/is_embedded.cpp
new file mode 100644
index 000000000..12a440901
--- /dev/null
+++ b/src/boost/libs/hana/test/core/is_embedded.cpp
@@ -0,0 +1,62 @@
+// 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/core/to.hpp>
+#include <boost/hana/equal.hpp>
+
+#include <climits>
+namespace hana = boost::hana;
+
+
+// This test makes sure that fundamental types are properly embedded in
+// each other, when sensible.
+
+static_assert(hana::is_embedded<double, long double>{}, "");
+static_assert(hana::is_embedded<float, long double>{}, "");
+static_assert(hana::is_embedded<float, double>{}, "");
+
+static_assert(hana::is_embedded<signed long, signed long long>{}, "");
+static_assert(hana::is_embedded<signed int, signed long long>{}, "");
+static_assert(hana::is_embedded<signed short, signed long long>{}, "");
+static_assert(hana::is_embedded<signed char, signed long long>{}, "");
+static_assert(hana::is_embedded<signed int, signed long>{}, "");
+static_assert(hana::is_embedded<signed short, signed long>{}, "");
+static_assert(hana::is_embedded<signed char, signed long>{}, "");
+static_assert(hana::is_embedded<signed short, signed int>{}, "");
+static_assert(hana::is_embedded<signed char, signed int>{}, "");
+static_assert(hana::is_embedded<signed char, signed short>{}, "");
+
+static_assert(hana::is_embedded<unsigned long, unsigned long long>{}, "");
+static_assert(hana::is_embedded<unsigned int, unsigned long long>{}, "");
+static_assert(hana::is_embedded<unsigned short, unsigned long long>{}, "");
+static_assert(hana::is_embedded<unsigned char, unsigned long long>{}, "");
+static_assert(hana::is_embedded<unsigned int, unsigned long>{}, "");
+static_assert(hana::is_embedded<unsigned short, unsigned long>{}, "");
+static_assert(hana::is_embedded<unsigned char, unsigned long>{}, "");
+static_assert(hana::is_embedded<unsigned short, unsigned int>{}, "");
+static_assert(hana::is_embedded<unsigned char, unsigned int>{}, "");
+static_assert(hana::is_embedded<unsigned char, unsigned short>{}, "");
+
+#if CHAR_MIN < 0 // char is signed
+
+ static_assert(hana::is_embedded<char, signed long long>{}, "");
+ static_assert(hana::is_embedded<char, signed long>{}, "");
+ static_assert(hana::is_embedded<char, signed int>{}, "");
+ static_assert(hana::is_embedded<char, signed short>{}, "");
+
+ static_assert(hana::equal('a', static_cast<signed int>('a')), "");
+
+#else // char is unsigned
+
+ static_assert(hana::is_embedded<char, unsigned long long>{}, "");
+ static_assert(hana::is_embedded<char, unsigned long>{}, "");
+ static_assert(hana::is_embedded<char, unsigned int>{}, "");
+ static_assert(hana::is_embedded<char, unsigned short>{}, "");
+
+ static_assert(hana::equal('a', static_cast<unsigned int>('a')), "");
+
+#endif
+
+
+int main() { }
diff --git a/src/boost/libs/hana/test/core/make.cpp b/src/boost/libs/hana/test/core/make.cpp
new file mode 100644
index 000000000..01677f7b0
--- /dev/null
+++ b/src/boost/libs/hana/test/core/make.cpp
@@ -0,0 +1,16 @@
+// 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/core/make.hpp>
+namespace hana = boost::hana;
+
+
+struct udt {
+ int value;
+ constexpr explicit udt(int v) : value(v) { }
+};
+
+static_assert(hana::make<udt>(1).value == 1, "");
+
+int main() { }
diff --git a/src/boost/libs/hana/test/core/tag_of.cpp b/src/boost/libs/hana/test/core/tag_of.cpp
new file mode 100644
index 000000000..99afe5c7e
--- /dev/null
+++ b/src/boost/libs/hana/test/core/tag_of.cpp
@@ -0,0 +1,74 @@
+// 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/core/tag_of.hpp>
+#include <boost/hana/core/when.hpp>
+
+#include <type_traits>
+namespace hana = boost::hana;
+
+
+template <typename T, typename ExpectedDatatype>
+struct test {
+ static_assert(std::is_same<hana::tag_of_t<T>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T volatile>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const volatile>, ExpectedDatatype>::value, "");
+
+ static_assert(std::is_same<hana::tag_of_t<T&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T volatile&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const volatile&>, ExpectedDatatype>::value, "");
+
+ static_assert(std::is_same<hana::tag_of_t<T&&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const&&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T volatile&&>, ExpectedDatatype>::value, "");
+ static_assert(std::is_same<hana::tag_of_t<T const volatile&&>, ExpectedDatatype>::value, "");
+};
+
+struct NestedDatatype;
+struct Nested { struct hana_tag; };
+template struct test<Nested, Nested::hana_tag>;
+
+struct NoNestedDatatype { };
+template struct test<NoNestedDatatype, NoNestedDatatype>;
+
+struct NoNestedHana { };
+template struct test<NoNestedHana, NoNestedHana>;
+
+
+struct FullySpecializedDatatype;
+struct FullySpecialized;
+namespace boost { namespace hana {
+ template <>
+ struct tag_of<FullySpecialized> {
+ using type = FullySpecializedDatatype;
+ };
+}}
+template struct test<FullySpecialized, FullySpecializedDatatype>;
+
+
+struct PartiallySpecializedDatatype;
+template <typename> struct PartiallySpecialized;
+namespace boost { namespace hana {
+ template <typename T>
+ struct tag_of<PartiallySpecialized<T>> {
+ using type = PartiallySpecializedDatatype;
+ };
+}}
+template struct test<PartiallySpecialized<struct anything>, PartiallySpecializedDatatype>;
+
+
+struct PredicatedDatatype;
+struct Predicated { static constexpr bool predicate = true; };
+namespace boost { namespace hana {
+ template <typename T>
+ struct tag_of<T, hana::when<T::predicate>> {
+ using type = PredicatedDatatype;
+ };
+}}
+template struct test<Predicated, PredicatedDatatype>;
+
+
+int main() { }
diff --git a/src/boost/libs/hana/test/core/to.cpp b/src/boost/libs/hana/test/core/to.cpp
new file mode 100644
index 000000000..f4dd54ef7
--- /dev/null
+++ b/src/boost/libs/hana/test/core/to.cpp
@@ -0,0 +1,106 @@
+// 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/core/to.hpp>
+
+#include <boost/hana/assert.hpp>
+#include <boost/hana/core/tag_of.hpp>
+
+#include <string>
+#include <type_traits>
+namespace hana = boost::hana;
+
+
+template <typename X, typename Y>
+constexpr auto operator==(X x, Y y)
+{ return x.value == y.value; }
+
+struct Datatype {
+ int value;
+ using hana_tag = Datatype;
+};
+
+struct Other {
+ int value;
+ using hana_tag = Datatype;
+};
+
+struct SpecializedFrom;
+struct specialized_from {
+ int value;
+ using hana_tag = SpecializedFrom;
+};
+
+struct SpecializedTo;
+struct specialized_to {
+ int value;
+ using hana_tag = SpecializedTo;
+};
+
+namespace boost { namespace hana {
+ template <>
+ struct to_impl<SpecializedTo, SpecializedFrom> {
+ template <typename T>
+ static constexpr auto apply(T t)
+ { return specialized_to{t.value}; }
+ };
+}}
+
+template <typename F, typename T>
+void check_convert(F f, T t) {
+ using From = hana::tag_of_t<F>;
+ using To = hana::tag_of_t<T>;
+
+ // Check From -> To conversion
+ BOOST_HANA_RUNTIME_CHECK(hana::to<To>(f) == t);
+ static_assert(std::is_same<
+ hana::tag_of_t<decltype(hana::to<To>(f))>, To
+ >{}, "");
+
+ static_assert(hana::is_convertible<From, To>{}, "");
+
+
+ // Make sure From -> From and To -> To are the identity.
+ BOOST_HANA_RUNTIME_CHECK(hana::to<From>(f) == f);
+ static_assert(std::is_same<
+ hana::tag_of_t<decltype(hana::to<From>(f))>, From
+ >{}, "");
+
+ BOOST_HANA_RUNTIME_CHECK(hana::to<To>(t) == t);
+ static_assert(std::is_same<
+ hana::tag_of_t<decltype(hana::to<To>(t))>, To
+ >{}, "");
+
+ static_assert(hana::is_convertible<From, From>{}, "");
+ static_assert(hana::is_convertible<To, To>{}, "");
+
+ static_assert(hana::is_embedded<From, From>{}, "");
+ static_assert(hana::is_embedded<To, To>{}, "");
+}
+
+template <typename X>
+void check_variable_template_in_dependent_context(X x) {
+ hana::to<int>(x);
+}
+
+int main() {
+ // Clang used to assert in the code generation when we used variable
+ // templates inside a lambda; this is to catch this.
+ check_variable_template_in_dependent_context(3);
+
+ check_convert("abcdef", std::string{"abcdef"});
+ check_convert(int{1}, double{1});
+ check_convert(double{1}, int{1});
+ check_convert(std::true_type{}, int{1});
+ check_convert(std::false_type{}, int{0});
+ check_convert(Datatype{1}, Datatype{1});
+ check_convert(Other{1}, Other{1});
+ check_convert(specialized_from{1}, specialized_to{1});
+
+ static_assert(!hana::is_convertible<void, int>{}, "");
+ static_assert(!hana::is_embedded<void, int>{}, "");
+
+ static_assert(hana::is_convertible<int, void>{}, "");
+ static_assert(!hana::is_embedded<int, void>{}, "");
+}
diff --git a/src/boost/libs/hana/test/core/when.cpp b/src/boost/libs/hana/test/core/when.cpp
new file mode 100644
index 000000000..c8fead5e0
--- /dev/null
+++ b/src/boost/libs/hana/test/core/when.cpp
@@ -0,0 +1,24 @@
+// 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/core/when.hpp>
+namespace hana = boost::hana;
+
+
+template <typename T, typename = hana::when<true>>
+struct base_template;
+
+template <typename T>
+struct base_template<T, hana::when_valid<typename T::first_type>> { };
+
+template <typename T>
+struct base_template<T, hana::when_valid<typename T::second_type>> { };
+
+struct First { struct first_type; };
+struct Second { struct second_type; };
+
+template struct base_template<First>;
+template struct base_template<Second>;
+
+int main() { }