/* @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 namespace hana = boost::hana; ////////////////////////////////////////////////////////////////////////////// // Type class ////////////////////////////////////////////////////////////////////////////// template struct Typeclass; namespace boost { namespace hana { template <> struct instance { template struct with { static constexpr bool has_complimentary = false; static constexpr bool has_defaults = false; static constexpr bool has_explicit_instance = false; }; }; template <> struct defaults { template struct with : defaults<> { static constexpr bool has_complimentary = false; static constexpr bool has_defaults = true; static constexpr bool has_explicit_instance = false; }; }; }} template struct Typeclass : hana::instance::template with { }; ////////////////////////////////////////////////////////////////////////////// // Complimentary instance ////////////////////////////////////////////////////////////////////////////// template struct predicate : std::false_type { }; namespace boost { namespace hana { template struct instance::with{}>> : defaults::template with { static constexpr bool has_complimentary = true; }; }} ////////////////////////////////////////////////////////////////////////////// // Data types ////////////////////////////////////////////////////////////////////////////// struct AugmentedComplimentary; struct Complimentary; struct NoComplimentary; struct SomethingElse; template <> struct predicate : std::true_type { }; template <> struct predicate : std::true_type { }; template <> struct Typeclass : hana::instance::with { static constexpr bool has_explicit_instance = true; }; template <> struct Typeclass : hana::defaults::with { static constexpr bool has_explicit_instance = true; }; int main() { static_assert(Typeclass::has_explicit_instance, ""); static_assert(Typeclass::has_complimentary, ""); static_assert(Typeclass::has_defaults, ""); static_assert(!Typeclass::has_explicit_instance, ""); static_assert(Typeclass::has_complimentary, ""); static_assert(Typeclass::has_defaults, ""); static_assert(Typeclass::has_explicit_instance, ""); static_assert(!Typeclass::has_complimentary, ""); static_assert(Typeclass::has_defaults, ""); static_assert(!Typeclass::has_explicit_instance, ""); static_assert(!Typeclass::has_complimentary, ""); static_assert(!Typeclass::has_defaults, ""); }