/* @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 namespace hana = boost::hana; struct Showable { BOOST_HANA_TYPECLASS(Showable); struct mcd { }; }; BOOST_HANA_CONSTEXPR_LAMBDA auto show = [](auto x) { return Showable::instance>::show_impl(x); }; namespace boost { namespace hana { template <> struct default_instance : Showable::mcd { template static std::string show_impl(X) { return ""; } }; }} template <> struct Showable::instance : Showable::mcd { static auto show_impl(int i) { return (std::ostringstream{} << i).str(); } }; struct unshowable { }; int main() { assert(show(1) == "1"); assert(show(unshowable{}) == ""); }