From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/hana/test/type/adl.cpp | 24 +++ src/boost/libs/hana/test/type/alignof.cpp | 32 ++++ src/boost/libs/hana/test/type/decltype.cpp | 182 ++++++++++++++++++ src/boost/libs/hana/test/type/equal.cpp | 35 ++++ src/boost/libs/hana/test/type/hash.cpp | 24 +++ .../libs/hana/test/type/inherit_basic_type.cpp | 17 ++ src/boost/libs/hana/test/type/integral.cpp | 83 +++++++++ src/boost/libs/hana/test/type/is_valid.cpp | 206 +++++++++++++++++++++ src/boost/libs/hana/test/type/laws.cpp | 28 +++ src/boost/libs/hana/test/type/make.cpp | 41 ++++ src/boost/libs/hana/test/type/metafunction.cpp | 72 +++++++ .../libs/hana/test/type/metafunction_class.cpp | 73 ++++++++ src/boost/libs/hana/test/type/nested_type.cpp | 18 ++ src/boost/libs/hana/test/type/sizeof.cpp | 32 ++++ src/boost/libs/hana/test/type/template.cpp | 61 ++++++ src/boost/libs/hana/test/type/traits.cpp | 154 +++++++++++++++ src/boost/libs/hana/test/type/typeid.cpp | 182 ++++++++++++++++++ src/boost/libs/hana/test/type/unary_plus.cpp | 39 ++++ 18 files changed, 1303 insertions(+) create mode 100644 src/boost/libs/hana/test/type/adl.cpp create mode 100644 src/boost/libs/hana/test/type/alignof.cpp create mode 100644 src/boost/libs/hana/test/type/decltype.cpp create mode 100644 src/boost/libs/hana/test/type/equal.cpp create mode 100644 src/boost/libs/hana/test/type/hash.cpp create mode 100644 src/boost/libs/hana/test/type/inherit_basic_type.cpp create mode 100644 src/boost/libs/hana/test/type/integral.cpp create mode 100644 src/boost/libs/hana/test/type/is_valid.cpp create mode 100644 src/boost/libs/hana/test/type/laws.cpp create mode 100644 src/boost/libs/hana/test/type/make.cpp create mode 100644 src/boost/libs/hana/test/type/metafunction.cpp create mode 100644 src/boost/libs/hana/test/type/metafunction_class.cpp create mode 100644 src/boost/libs/hana/test/type/nested_type.cpp create mode 100644 src/boost/libs/hana/test/type/sizeof.cpp create mode 100644 src/boost/libs/hana/test/type/template.cpp create mode 100644 src/boost/libs/hana/test/type/traits.cpp create mode 100644 src/boost/libs/hana/test/type/typeid.cpp create mode 100644 src/boost/libs/hana/test/type/unary_plus.cpp (limited to 'src/boost/libs/hana/test/type') diff --git a/src/boost/libs/hana/test/type/adl.cpp b/src/boost/libs/hana/test/type/adl.cpp new file mode 100644 index 000000000..35a75c20c --- /dev/null +++ b/src/boost/libs/hana/test/type/adl.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 +namespace hana = boost::hana; + + +template +struct invalid { static_assert(b, "invalid must not be instantiated"); }; + +template void adl(T) { } +template void adl_pattern(hana::basic_type) { } + + +int main() { + // ADL kicks in but `invalid<>` must not instantiated + adl(hana::type_c>); + adl_pattern(hana::type_c>); + + // ADL instantiates the types recursively, make sure that works too + adl(hana::typeid_(hana::type_c>)); + adl_pattern(hana::typeid_(hana::type_c>)); +} diff --git a/src/boost/libs/hana/test/type/alignof.cpp b/src/boost/libs/hana/test/type/alignof.cpp new file mode 100644 index 000000000..6b8203b21 --- /dev/null +++ b/src/boost/libs/hana/test/type/alignof.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 +#include +#include +#include +namespace hana = boost::hana; + + +struct T { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::alignof_(T{}), + hana::size_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::alignof_(hana::type_c), + hana::size_c + )); + + // make sure we don't read from non-constexpr variables + { + auto t = hana::type_c; + auto x = 1; + constexpr auto r1 = hana::alignof_(t); (void)r1; + constexpr auto r2 = hana::alignof_(x); (void)r2; + } +} diff --git a/src/boost/libs/hana/test/type/decltype.cpp b/src/boost/libs/hana/test/type/decltype.cpp new file mode 100644 index 000000000..b956c324e --- /dev/null +++ b/src/boost/libs/hana/test/type/decltype.cpp @@ -0,0 +1,182 @@ +// 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 +#include +#include +namespace hana = boost::hana; + + +using Function = void(); +void function() { } + +int main() { + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(T{}), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(t), + hana::type_c + )); + } + + // [cv-qualified] reference types + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + } + + // [cv-qualified] rvalue reference types + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(static_cast(t)), + hana::type_c + )); + } + + // decltype_(type_c) is the identity function + { + struct T; + auto const type_const = hana::type_c; + auto const& type_const_ref = hana::type_c; + auto& type_ref = hana::type_c; + auto&& type_ref_ref = static_cast(type_ref); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(hana::type_c), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(type_const), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(type_const_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(type_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(type_ref_ref), + hana::type_c + )); + } + + // make sure we don't read from non-constexpr variables + { + struct T; + auto t = hana::type_c; + auto x = 1; + constexpr auto r1 = hana::decltype_(t); (void)r1; + constexpr auto r2 = hana::decltype_(x); (void)r2; + } + + // decltype_ with builtin arrays, function pointers and other weirdos + { + struct T { }; + using A = T[3]; + A a; + A& a_ref = a; + A const& a_const_ref = a; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(a), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(a_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(a_const_ref), + hana::type_c + )); + } + { + using Fptr = int(*)(); + Fptr f; + Fptr& f_ref = f; + Fptr const& f_const_ref = f; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(f), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(f_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(f_const_ref), + hana::type_c + )); + } + { + Function& function_ref = function; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(function), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::decltype_(function_ref), + hana::type_c + )); + } +} diff --git a/src/boost/libs/hana/test/type/equal.cpp b/src/boost/libs/hana/test/type/equal.cpp new file mode 100644 index 000000000..4d5a18a84 --- /dev/null +++ b/src/boost/libs/hana/test/type/equal.cpp @@ -0,0 +1,35 @@ +// 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 +#include +#include +#include // for operator != +#include +namespace hana = boost::hana; + + +struct T; +struct U; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::type_c, hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::type_c, hana::type_c))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::type_c, hana::type_c))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::type_c, hana::type_c))); + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::type_c, hana::type_c)); + + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::type_c, hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::type_c, hana::type_c))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(hana::type_c, hana::type_c))); + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::type_c, hana::type_c)); + + // make sure we don't read from a non-constexpr variable in hana::equal + auto t = hana::type_c; + static_assert(hana::equal(t, hana::type_c), ""); + + // check operators + BOOST_HANA_CONSTANT_CHECK(hana::type_c == hana::type_c); + BOOST_HANA_CONSTANT_CHECK(hana::type_c != hana::type_c); +} diff --git a/src/boost/libs/hana/test/type/hash.cpp b/src/boost/libs/hana/test/type/hash.cpp new file mode 100644 index 000000000..88bcf3352 --- /dev/null +++ b/src/boost/libs/hana/test/type/hash.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 +#include +#include +#include +namespace hana = boost::hana; + + +struct T; + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::type_c), + hana::type_c +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_type{}), + hana::type_c +)); + +int main() { } diff --git a/src/boost/libs/hana/test/type/inherit_basic_type.cpp b/src/boost/libs/hana/test/type/inherit_basic_type.cpp new file mode 100644 index 000000000..e42e82801 --- /dev/null +++ b/src/boost/libs/hana/test/type/inherit_basic_type.cpp @@ -0,0 +1,17 @@ +// 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 + +#include +namespace hana = boost::hana; + + +// `hana::type` should inherit `hana::basic_type`. + +struct T; +static_assert(std::is_base_of, decltype(hana::type_c)>{}, ""); +static_assert(std::is_base_of, hana::type>{}, ""); + +int main() { } diff --git a/src/boost/libs/hana/test/type/integral.cpp b/src/boost/libs/hana/test/type/integral.cpp new file mode 100644 index 000000000..e3159bbc3 --- /dev/null +++ b/src/boost/libs/hana/test/type/integral.cpp @@ -0,0 +1,83 @@ +// 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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct x1; struct x2; struct x3; +struct y1 { }; struct y2 { }; struct y3 { }; + +template struct mf { struct type { }; }; +struct mfc { template struct apply { struct type { }; }; }; +template struct tpl { }; + +// make sure `integral(f)(...)` returns the right type +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction)()), + mf<>::type +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction)(hana::type_c)), + mf::type +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction)(hana::type_c, hana::type_c)), + mf::type +>{}, ""); + +static_assert(std::is_same< + decltype(hana::integral(hana::template_)()), + tpl<> +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::template_)(hana::type_c)), + tpl +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::template_)(hana::type_c, hana::type_c)), + tpl +>{}, ""); + +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction_class)()), + mfc::apply<>::type +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction_class)(hana::type_c)), + mfc::apply::type +>{}, ""); +static_assert(std::is_same< + decltype(hana::integral(hana::metafunction_class)(hana::type_c, hana::type_c)), + mfc::apply::type +>{}, ""); + +// Make sure integral is SFINAE-friendly +struct invalid_hana_metafunction { + template struct apply { /* missing type alias */ }; +}; +auto invalid_integral = hana::integral(invalid_hana_metafunction{}); +BOOST_HANA_CONSTANT_CHECK(hana::not_( + hana::is_valid(invalid_integral)(hana::type_c, hana::type_c) +)); + + +int main() { + // Make sure we can perform the call; we already made sure the return type was correct + constexpr auto a = hana::integral(hana::metafunction)(); (void)a; + constexpr auto b = hana::integral(hana::metafunction)(hana::type_c); (void)b; + constexpr auto c = hana::integral(hana::metafunction)(hana::type_c, hana::type_c); (void)c; + constexpr auto d = hana::integral(hana::metafunction)(hana::type_c, hana::type_c, hana::type_c); (void)d; + + // Make sure we don't read from a non-constexpr variable + auto t = hana::type_c; + constexpr auto r = hana::integral(hana::metafunction)(t); + (void)r; +} diff --git a/src/boost/libs/hana/test/type/is_valid.cpp b/src/boost/libs/hana/test/type/is_valid.cpp new file mode 100644 index 000000000..2f2abcd35 --- /dev/null +++ b/src/boost/libs/hana/test/type/is_valid.cpp @@ -0,0 +1,206 @@ +// 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 +#include +#include +#include +#include + +#include + +#include +namespace hana = boost::hana; + + +struct undefined { }; + +struct static_nested_member { static const int member = 1; }; +struct static_nested_member_array { static int member[3]; }; +struct nested_template_struct { template struct nested; }; +struct nested_template_alias { template using nested = void; }; + +int main() { + // Check for a non-static member + { + struct yes { int member; }; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype( + hana::traits::declval(t).member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype( + t.member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + // Check for a non-static member function + { + struct yes { int member() const; }; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype( + hana::traits::declval(t).member() + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype( + t.member() + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + // Check for a static member + { + using yes = static_nested_member; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype( + decltype(t)::type::member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype( + std::remove_reference_t::member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + // Check for a nested type + { + struct yes { using nested = void; }; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype(hana::type_c< + typename decltype(t)::type::nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype(hana::type_c< + typename std::remove_reference_t::nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + // Check for a nested template + { + { // template struct + using yes = nested_template_struct; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype(hana::template_< + decltype(t)::type::template nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype(hana::template_< + std::remove_reference_t::template nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + { // template alias + using yes = nested_template_alias; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype(hana::template_< + decltype(t)::type::template nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype(hana::template_< + std::remove_reference_t::template nested + >) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + } + + // Make sure that checking for a nested static or non-static member + // works even when the type of that member is an array type or + // something that can't be returned from a function. + { + { // non-static member + struct yes { int member[3]; }; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype( + (void)hana::traits::declval(t).member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype( + (void)t.member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + + { // static member + using yes = static_nested_member_array; + struct no { }; + + auto from_type = hana::is_valid([](auto t) -> decltype( + (void)decltype(t)::type::member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_type(hana::type_c)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_type(hana::type_c))); + + auto from_object = hana::is_valid([](auto&& t) -> decltype( + (void)std::remove_reference_t::member + ) { }); + BOOST_HANA_CONSTANT_CHECK(from_object(yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(from_object(no{}))); + } + } + + // Make sure the result of a `is_valid` function is constexpr + // even when called on non-constexpr arguments. + { + int i; + auto f = hana::is_valid([](auto) { }); + constexpr auto result = f(i); + (void)result; + } + + // Make sure `is_valid` works with non-PODs. + { + hana::is_valid(undefined{})(Tracked{1}); + hana::is_valid([t = Tracked{1}](auto) { return 1; })(Tracked{1}); + } + + // Check `is_valid` with a nullary function. + { + auto f = [](auto ...x) { (void)sizeof...(x); /* -Wunused-param */ }; + auto g = [](auto ...x) -> char(*)[sizeof...(x)] { }; + BOOST_HANA_CONSTANT_CHECK(hana::is_valid(f)()); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_valid(g)())); + } + + // Call `is_valid` in the non-curried form. + { + struct yes { int member; }; + struct no { }; + + auto f = [](auto&& t) -> decltype(t.member) { }; + + BOOST_HANA_CONSTANT_CHECK(hana::is_valid(f, yes{})); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_valid(f, no{}))); + } +} diff --git a/src/boost/libs/hana/test/type/laws.cpp b/src/boost/libs/hana/test/type/laws.cpp new file mode 100644 index 000000000..622840f9b --- /dev/null +++ b/src/boost/libs/hana/test/type/laws.cpp @@ -0,0 +1,28 @@ +// 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 +#include + +#include +#include +namespace hana = boost::hana; + + +struct T; + +int main() { + auto types = hana::make_tuple( + hana::type_c, + hana::type_c, + hana::type_c, + hana::type_c, + hana::type_c, + hana::type_c, + hana::type_c + ); + + hana::test::TestComparable{types}; + hana::test::TestHashable{types}; +} diff --git a/src/boost/libs/hana/test/type/make.cpp b/src/boost/libs/hana/test/type/make.cpp new file mode 100644 index 000000000..68a6a9839 --- /dev/null +++ b/src/boost/libs/hana/test/type/make.cpp @@ -0,0 +1,41 @@ +// 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 +#include +#include +namespace hana = boost::hana; + + +struct T { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(T{}), + hana::decltype_(T{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::type_c), + hana::decltype_(hana::type_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_type(T{}), + hana::make(T{}) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_type(hana::type_c), + hana::make(hana::type_c) + )); + + // make sure we don't read from non-constexpr variables + { + auto t = hana::type_c; + auto x = 1; + constexpr auto r1 = hana::make(t); (void)r1; + constexpr auto r2 = hana::make(x); (void)r2; + } +} diff --git a/src/boost/libs/hana/test/type/metafunction.cpp b/src/boost/libs/hana/test/type/metafunction.cpp new file mode 100644 index 000000000..aa52c1f38 --- /dev/null +++ b/src/boost/libs/hana/test/type/metafunction.cpp @@ -0,0 +1,72 @@ +// 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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct x1; struct x2; struct x3; +struct y1 { }; struct y2 { }; struct y3 { }; +template struct f { struct type; }; + +template +constexpr auto valid_call(F f, T ...t) -> decltype(((void)f(t...)), true) +{ return true; } +constexpr auto valid_call(...) +{ return false; } + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction(), + hana::type_c::type> +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction(hana::type_c), + hana::type_c::type> +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction(hana::type_c, hana::type_c), + hana::type_c::type> +)); + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction(hana::type_c, hana::type_c, hana::type_c), + hana::type_c::type> +)); + +using F = decltype(hana::metafunction); +static_assert(std::is_same, f<>>::value, ""); +static_assert(std::is_same, f>::value, ""); +static_assert(std::is_same, f>::value, ""); +static_assert(std::is_same, f>::value, ""); + +// Make sure we're SFINAE-friendly +template struct no_type { }; +static_assert(!valid_call(hana::metafunction), ""); +static_assert(!valid_call(hana::metafunction, hana::type_c), ""); + +// Make sure we model the Metafunction concept +static_assert(hana::Metafunction)>::value, ""); +static_assert(hana::Metafunction)&>::value, ""); + +// Make sure metafunction is SFINAE-friendly +template struct not_a_metafunction { }; +BOOST_HANA_CONSTANT_CHECK(hana::not_( + hana::is_valid(hana::metafunction)(hana::type_c) +)); + + +// Make sure we don't read from a non-constexpr variable +int main() { + auto t = hana::type_c; + constexpr auto r = hana::metafunction(t); + (void)r; +} diff --git a/src/boost/libs/hana/test/type/metafunction_class.cpp b/src/boost/libs/hana/test/type/metafunction_class.cpp new file mode 100644 index 000000000..b0123708b --- /dev/null +++ b/src/boost/libs/hana/test/type/metafunction_class.cpp @@ -0,0 +1,73 @@ +// 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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct x1; struct x2; struct x3; +struct y1 { }; struct y2 { }; struct y3 { }; +struct f { template struct apply { struct type; }; }; + +template +constexpr auto valid_call(F f, T ...t) -> decltype(((void)f(t...)), true) +{ return true; } +constexpr auto valid_call(...) +{ return false; } + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction_class(), + hana::type_c::type> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction_class(hana::type_c), + hana::type_c::type> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction_class(hana::type_c, hana::type_c), + hana::type_c::type> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::metafunction_class(hana::type_c, hana::type_c, hana::type_c), + hana::type_c::type> +)); + +using F = decltype(hana::metafunction_class); +static_assert(std::is_same, f::apply<>>{}, ""); +static_assert(std::is_same, f::apply>{}, ""); +static_assert(std::is_same, f::apply>{}, ""); +static_assert(std::is_same, f::apply>{}, ""); + +// Make sure we're SFINAE-friendly +struct no_type { template struct apply { }; }; +static_assert(!valid_call(hana::metafunction_class), ""); +static_assert(!valid_call(hana::metafunction_class, hana::type_c), ""); + +// Make sure we model the Metafunction concept +static_assert(hana::Metafunction)>::value, ""); +static_assert(hana::Metafunction)&>::value, ""); + +// Make sure metafunction_class is SFINAE-friendly +struct not_a_mfc1 { template struct apply { }; }; +struct not_a_mfc2 { }; +BOOST_HANA_CONSTANT_CHECK(hana::not_( + hana::is_valid(hana::metafunction_class)(hana::type_c) +)); +BOOST_HANA_CONSTANT_CHECK(hana::not_( + hana::is_valid(hana::metafunction_class)(hana::type_c) +)); + + +// Make sure we don't read from a non-constexpr variable +int main() { + auto t = hana::type_c; + constexpr auto r = hana::metafunction_class(t); + (void)r; +} diff --git a/src/boost/libs/hana/test/type/nested_type.cpp b/src/boost/libs/hana/test/type/nested_type.cpp new file mode 100644 index 000000000..6e0410dff --- /dev/null +++ b/src/boost/libs/hana/test/type/nested_type.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 + +#include +namespace hana = boost::hana; + + +// Makes sure that `hana::type`s have a nested ::type alias + +struct T; + +static_assert(std::is_same)::type, T>{}, ""); +static_assert(std::is_same::type, T>{}, ""); + +int main() { } diff --git a/src/boost/libs/hana/test/type/sizeof.cpp b/src/boost/libs/hana/test/type/sizeof.cpp new file mode 100644 index 000000000..85110d295 --- /dev/null +++ b/src/boost/libs/hana/test/type/sizeof.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 +#include +#include +#include +namespace hana = boost::hana; + + +struct T { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sizeof_(T{}), + hana::size_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::sizeof_(hana::type_c), + hana::size_c + )); + + // make sure we don't read from non-constexpr variables + { + auto t = hana::type_c; + auto x = 1; + constexpr auto r1 = hana::sizeof_(t); (void)r1; + constexpr auto r2 = hana::sizeof_(x); (void)r2; + } +} diff --git a/src/boost/libs/hana/test/type/template.cpp b/src/boost/libs/hana/test/type/template.cpp new file mode 100644 index 000000000..6b35d35e7 --- /dev/null +++ b/src/boost/libs/hana/test/type/template.cpp @@ -0,0 +1,61 @@ +// 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 +#include +#include +#include +#include + +#include +namespace hana = boost::hana; + + +struct x1; struct x2; struct x3; +struct y1 { }; struct y2 { }; struct y3 { }; +template struct f; + +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::template_(), + hana::type_c> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::template_(hana::type_c), + hana::type_c> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::template_(hana::type_c, hana::type_c), + hana::type_c> +)); +BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::template_(hana::type_c, hana::type_c, hana::type_c), + hana::type_c> +)); + +using F = decltype(hana::template_); +static_assert(std::is_same::type, f<>>{}, ""); +static_assert(std::is_same::type, f>{}, ""); +static_assert(std::is_same::type, f>{}, ""); +static_assert(std::is_same::type, f>{}, ""); + +// Make sure we model the Metafunction concept +static_assert(hana::Metafunction)>::value, ""); +static_assert(hana::Metafunction)&>::value, ""); + +// Make sure we can use aliases +template using alias = T; +static_assert(hana::template_(hana::type_c) == hana::type_c, ""); + +// Make sure template_ is SFINAE-friendly +template struct unary; +BOOST_HANA_CONSTANT_CHECK(hana::not_( + hana::is_valid(hana::template_)(hana::type_c, hana::type_c) +)); + +// Make sure we don't read from a non-constexpr variable +int main() { + auto t = hana::type_c; + constexpr auto r = hana::template_(t); + (void)r; +} diff --git a/src/boost/libs/hana/test/type/traits.cpp b/src/boost/libs/hana/test/type/traits.cpp new file mode 100644 index 000000000..dd2e3d7e0 --- /dev/null +++ b/src/boost/libs/hana/test/type/traits.cpp @@ -0,0 +1,154 @@ +// 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 + +#include +#include +#include +namespace hana = boost::hana; + + +enum Enumeration { }; +struct Structure { }; +constexpr auto e = hana::type_c; +constexpr auto s = hana::type_c; + +int main() { + // We just make sure that they compile. If the forwarding to `std::` is + // well done, it is the job of `std::` to return the right thing. + + /////////////////////// + // Type properties + /////////////////////// + // Primary type categories + static_assert(!hana::traits::is_void(s), "the traits should be compile-time checkable"); + hana::traits::is_null_pointer(s); + hana::traits::is_integral(s); + hana::traits::is_floating_point(s); + hana::traits::is_array(s); + hana::traits::is_enum(s); + hana::traits::is_union(s); + hana::traits::is_class(s); + hana::traits::is_function(s); + hana::traits::is_pointer(s); + hana::traits::is_lvalue_reference(s); + hana::traits::is_rvalue_reference(s); + hana::traits::is_member_object_pointer(s); + hana::traits::is_member_function_pointer(s); + + // Composite type categories + hana::traits::is_fundamental(s); + hana::traits::is_arithmetic(s); + hana::traits::is_scalar(s); + hana::traits::is_object(s); + hana::traits::is_compound(s); + hana::traits::is_reference(s); + hana::traits::is_member_pointer(s); + + // Type properties + hana::traits::is_const(s); + hana::traits::is_volatile(s); + hana::traits::is_trivial(s); + hana::traits::is_trivially_copyable(s); + hana::traits::is_standard_layout(s); + hana::traits::is_pod(s); + hana::traits::is_literal_type(s); + hana::traits::is_empty(s); + hana::traits::is_polymorphic(s); + hana::traits::is_abstract(s); + hana::traits::is_signed(s); + hana::traits::is_unsigned(s); + + // Supported operations + hana::traits::is_constructible(s, s); + hana::traits::is_trivially_constructible(s, s); + hana::traits::is_nothrow_constructible(s, s); + + hana::traits::is_default_constructible(s); + hana::traits::is_trivially_default_constructible(s); + hana::traits::is_nothrow_default_constructible(s); + + hana::traits::is_copy_constructible(s); + hana::traits::is_trivially_copy_constructible(s); + hana::traits::is_nothrow_copy_constructible(s); + + hana::traits::is_move_constructible(s); + hana::traits::is_trivially_move_constructible(s); + hana::traits::is_nothrow_move_constructible(s); + + hana::traits::is_assignable(s, s); + hana::traits::is_trivially_assignable(s, s); + hana::traits::is_nothrow_assignable(s, s); + + hana::traits::is_copy_assignable(s); + hana::traits::is_trivially_copy_assignable(s); + hana::traits::is_nothrow_copy_assignable(s); + + hana::traits::is_move_assignable(s); + hana::traits::is_trivially_move_assignable(s); + hana::traits::is_nothrow_move_assignable(s); + + hana::traits::is_destructible(s); + hana::traits::is_trivially_destructible(s); + hana::traits::is_nothrow_destructible(s); + + hana::traits::has_virtual_destructor(s); + + // Property queries + hana::traits::alignment_of(s); + hana::traits::rank(s); + hana::traits::extent(s); + hana::traits::extent(hana::type_c, hana::uint_c<1>); + + // Type relationships + hana::traits::is_same(s, s); + hana::traits::is_base_of(s, s); + hana::traits::is_convertible(s, s); + + /////////////////////// + // Type modifications + /////////////////////// + // Const-volatility specifiers + hana::traits::remove_cv(s); + hana::traits::remove_const(s); + hana::traits::remove_volatile(s); + + hana::traits::add_cv(s); + hana::traits::add_const(s); + hana::traits::add_volatile(s); + + // References + hana::traits::remove_reference(s); + hana::traits::add_lvalue_reference(s); + hana::traits::add_rvalue_reference(s); + + // Pointers + hana::traits::remove_pointer(s); + hana::traits::add_pointer(s); + + // Sign modifiers + hana::traits::make_signed(hana::type_c); + hana::traits::make_unsigned(hana::type_c); + + // Arrays + hana::traits::remove_extent(s); + hana::traits::remove_all_extents(s); + + // Miscellaneous transformations + hana::traits::aligned_storage(hana::size_c<1>); + hana::traits::aligned_storage(hana::size_c<1>, hana::size_c<1>); + hana::traits::aligned_union(hana::size_c<0>, s); + hana::traits::decay(s); + + hana::traits::common_type(s, s); + hana::traits::underlying_type(e); + using FunctionPointer = void(*)(); + hana::traits::result_of(hana::type_c); + + /////////////////////// + // Utilities + /////////////////////// + using Z = decltype(hana::traits::declval(hana::type_c)); +} diff --git a/src/boost/libs/hana/test/type/typeid.cpp b/src/boost/libs/hana/test/type/typeid.cpp new file mode 100644 index 000000000..44b7c3a49 --- /dev/null +++ b/src/boost/libs/hana/test/type/typeid.cpp @@ -0,0 +1,182 @@ +// 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 +#include +#include +namespace hana = boost::hana; + + +using Function = void(); +void function() { } + +int main() { + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(T{}), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(t), + hana::type_c + )); + } + + // [cv-qualified] reference types + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + } + + // [cv-qualified] rvalue reference types + { + struct T { }; + T t; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(static_cast(t)), + hana::type_c + )); + } + + // typeid_(type_c) is the identity function + { + struct T; + auto const type_const = hana::type_c; + auto const& type_const_ref = hana::type_c; + auto& type_ref = hana::type_c; + auto&& type_ref_ref = static_cast(type_ref); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(hana::type_c), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(type_const), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(type_const_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(type_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(type_ref_ref), + hana::type_c + )); + } + + // make sure we don't read from non-constexpr variables + { + struct T; + auto t = hana::type_c; + auto x = 1; + constexpr auto r1 = hana::typeid_(t); (void)r1; + constexpr auto r2 = hana::typeid_(x); (void)r2; + } + + // typeid_ with builtin arrays, function pointers and other weirdos + { + struct T { }; + using A = T[3]; + A a; + A& a_ref = a; + A const& a_const_ref = a; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(a), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(a_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(a_const_ref), + hana::type_c + )); + } + { + using Fptr = int(*)(); + Fptr f; + Fptr& f_ref = f; + Fptr const& f_const_ref = f; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(f), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(f_ref), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(f_const_ref), + hana::type_c + )); + } + { + Function& function_ref = function; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(function), + hana::type_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::typeid_(function_ref), + hana::type_c + )); + } +} diff --git a/src/boost/libs/hana/test/type/unary_plus.cpp b/src/boost/libs/hana/test/type/unary_plus.cpp new file mode 100644 index 000000000..b9aa8feba --- /dev/null +++ b/src/boost/libs/hana/test/type/unary_plus.cpp @@ -0,0 +1,39 @@ +// 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 +#include +#include + +#include +namespace hana = boost::hana; + + +// This test checks that the unary + operator on types works as expected. +// The unary + operator is supposed to turn a reference to a hana::type +// object into an equivalent prvalue. + +struct T; + +int main() { + auto& ref = hana::type_c; + auto const& cref = hana::type_c; + auto&& rref = hana::type_c; + auto val = hana::type_c; + + BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +val)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +ref)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +cref)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +rref)); + + static_assert(!std::is_reference{}, ""); + static_assert(!std::is_reference{}, ""); + static_assert(!std::is_reference{}, ""); + static_assert(!std::is_reference{}, ""); + + using T1 = decltype(+val)::type; + using T2 = decltype(+ref)::type; + using T3 = decltype(+cref)::type; + using T4 = decltype(+rref)::type; +} -- cgit v1.2.3