/* @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 using namespace boost::hana; struct Printable { }; template struct print_impl : default_ { /* no definition; `print(x)` fails at compile-time by default */ }; auto print = [](std::ostream& os, auto const& x) -> decltype(auto) { return print_impl>::apply(os, x); }; namespace boost { namespace hana { template struct models_impl : std::integral_constant>{}> { }; }} struct Person { std::string name; }; template <> struct print_impl { static std::ostream& apply(std::ostream& os, Person const& p) { os << p.name; return os; } }; static_assert(_models{}, ""); int main() { print(std::cout, Person{"Louis"}); }