// 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 namespace hana = boost::hana; template 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 { template static constexpr auto apply(T t) { return specialized_to{t.value}; } }; }} template void check_convert(F f, T t) { using From = hana::tag_of_t; using To = hana::tag_of_t; // Check From -> To conversion BOOST_HANA_RUNTIME_CHECK(hana::to(f) == t); static_assert(std::is_same< hana::tag_of_t(f))>, To >{}, ""); static_assert(hana::is_convertible{}, ""); // Make sure From -> From and To -> To are the identity. BOOST_HANA_RUNTIME_CHECK(hana::to(f) == f); static_assert(std::is_same< hana::tag_of_t(f))>, From >{}, ""); BOOST_HANA_RUNTIME_CHECK(hana::to(t) == t); static_assert(std::is_same< hana::tag_of_t(t))>, To >{}, ""); static_assert(hana::is_convertible{}, ""); static_assert(hana::is_convertible{}, ""); static_assert(hana::is_embedded{}, ""); static_assert(hana::is_embedded{}, ""); } template void check_variable_template_in_dependent_context(X x) { hana::to(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{}, ""); static_assert(!hana::is_embedded{}, ""); static_assert(hana::is_convertible{}, ""); static_assert(!hana::is_embedded{}, ""); }