/* @copyright Louis Dionne 2015 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 #include using namespace boost::hana; namespace ns1 { //! [comparable] struct T; struct U; BOOST_HANA_CONSTANT_CHECK(type == type); BOOST_HANA_CONSTANT_CHECK(type != type); //! [comparable] } namespace ns3 { //! [decltype_] struct X { }; BOOST_HANA_CONSTANT_CHECK(decltype_(X{}) == type); BOOST_HANA_CONSTANT_CHECK(decltype_(type) == type); BOOST_HANA_CONSTANT_CHECK(decltype_(1) == type); static int const& i = 1; BOOST_HANA_CONSTANT_CHECK(decltype_(i) == type); //! [decltype_] } namespace ns4 { //! [sizeof_] struct X { }; static_assert(sizeof_(type) == sizeof(X), ""); static_assert(sizeof_(1) == sizeof(1), ""); static_assert(sizeof_(type) == sizeof(int), ""); //! [sizeof_] } namespace ns44 { //! [alignof_] struct X { }; static_assert(alignof_(type) == alignof(X), ""); static_assert(alignof_(1) == alignof(decltype(1)), ""); static_assert(alignof_(type) == alignof(int), ""); //! [alignof_] } namespace ns5 { //! [template] template struct f; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(template_() == type>); BOOST_HANA_CONSTANT_CHECK(template_(type) == type>); BOOST_HANA_CONSTANT_CHECK(template_(type, type) == type>); // calling `template_` on non-Types BOOST_HANA_CONSTANT_CHECK(template_(1) == type>); static_assert(std::is_same< decltype(template_)::apply::type, f >::value, ""); //! [template] } namespace ns6 { //! [metafunction] template struct f { struct type; }; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(metafunction() == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction(type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction(type, type) == type::type>); // calling `metafunction` on non-Types BOOST_HANA_CONSTANT_CHECK(metafunction(1) == type::type>); static_assert(std::is_same< decltype(metafunction)::apply::type, f::type >::value, ""); //! [metafunction] } namespace ns66 { //! [metafunction_class] struct f { template struct apply { struct type; }; }; struct x; struct y; BOOST_HANA_CONSTANT_CHECK(metafunction_class() == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction_class(type) == type::type>); BOOST_HANA_CONSTANT_CHECK(metafunction_class(type, type) == type::type>); // calling `metafunction_class` on non-Types BOOST_HANA_CONSTANT_CHECK(metafunction_class(1) == type::type>); static_assert(std::is_same< decltype(metafunction_class)::apply::type, f::apply::type >::value, ""); //! [metafunction_class] } namespace ns7 { //! [integral] BOOST_HANA_CONSTANT_CHECK(integral(metafunction)(type)); BOOST_HANA_CONSTANT_CHECK(not_(integral(metafunction)(type))); //! [integral] } namespace ns8 { using boost::hana::size_t; //! [non_liftable_metafunction] BOOST_HANA_CONSTEXPR_LAMBDA auto extent = [](auto t, auto n) { return std::extent{}; }; BOOST_HANA_CONSTANT_CHECK(extent(type, int_<1>) == size_t<0>); BOOST_HANA_CONSTANT_CHECK(extent(type, int_<1>) == size_t<2>); //! [non_liftable_metafunction] } namespace ns9 { //! [make] struct X { }; BOOST_HANA_CONSTANT_CHECK(make(X{}) == decltype_(X{})); BOOST_HANA_CONSTANT_CHECK(make(type) == decltype_(type)); //! [make] } namespace ns10 { //! [trait] BOOST_HANA_CONSTANT_CHECK(trait(type)); BOOST_HANA_CONSTANT_CHECK(not_(trait(type))); //! [trait] } int main() { { //! [is_valid] struct Person { std::string name; }; auto has_name = is_valid([](auto p) -> decltype(p.name) { }); Person joe{"Joe"}; static_assert(has_name(joe), ""); static_assert(!has_name(1), ""); static_assert(has_name(type), ""); static_assert(!has_name(type), ""); //! [is_valid] } }