/* @copyright Louis Dionne 2014 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 #include using namespace boost::hana; struct Typeclass; struct NotInstance; struct Instance; namespace boost { namespace hana { template <> struct models_impl< ::Typeclass> { template static constexpr bool apply = std::is_same::value; }; }} struct an_instance { struct hana { using datatype = Instance; }; }; struct not_instance { struct hana { using datatype = NotInstance; }; }; int main() { // standard syntax BOOST_HANA_CONSTANT_CHECK(models); BOOST_HANA_CONSTANT_CHECK(!models); BOOST_HANA_CONSTANT_CHECK(!models); // alternate syntax BOOST_HANA_CONSTANT_CHECK(is_a(an_instance{})); BOOST_HANA_CONSTANT_CHECK(is_an(an_instance{})); BOOST_HANA_CONSTANT_CHECK(!is_a(not_instance{})); BOOST_HANA_CONSTANT_CHECK(!is_an(not_instance{})); BOOST_HANA_CONSTANT_CHECK(!is_a(1)); BOOST_HANA_CONSTANT_CHECK(!is_an(1)); BOOST_HANA_CONSTANT_CHECK(!is_a('2')); BOOST_HANA_CONSTANT_CHECK(!is_an('2')); BOOST_HANA_CONSTANT_CHECK(is_a(an_instance{})); BOOST_HANA_CONSTANT_CHECK(is_an(an_instance{})); BOOST_HANA_CONSTANT_CHECK(is_a(not_instance{})); // check with a couple of "real" instances BOOST_HANA_CONSTANT_CHECK(is_an(tuple(1, '2', 3))); BOOST_HANA_CONSTANT_CHECK(is_a(tuple(1, '2', 3))); BOOST_HANA_CONSTANT_CHECK(is_a(tuple(1, '2', 3))); BOOST_HANA_CONSTANT_CHECK(!is_an(just(1))); BOOST_HANA_CONSTANT_CHECK(!is_an(nothing)); BOOST_HANA_CONSTANT_CHECK(is_a(just('1'))); BOOST_HANA_CONSTANT_CHECK(is_a(nothing)); BOOST_HANA_CONSTANT_CHECK(is_a(just("abcd"))); BOOST_HANA_CONSTANT_CHECK(is_a(nothing)); BOOST_HANA_CONSTANT_CHECK(is(1)); BOOST_HANA_CONSTANT_CHECK(is_a(tuple(1, '2', 3))); BOOST_HANA_CONSTANT_CHECK(is_an(1)); }