/* @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 using namespace boost::hana; //! [default_] // In the header defining the concept of a Printable template struct print_impl : default_ { template static void apply(Stream& out, X const& x) { out << x; } }; auto print = [](auto& stream, auto const& x) { return print_impl>::apply(stream, x); }; // In some other header template struct print_impl> { template static void apply(Stream& out, std::vector const& xs) { out << '['; std::copy(begin(xs), end(xs), std::ostream_iterator{out, ", "}); out << ']'; } }; static_assert(is_default>{}, ""); static_assert(!is_default>>{}, ""); //! [default_] int main() { { std::stringstream s; print(s, std::vector{1, 2, 3}); BOOST_HANA_RUNTIME_CHECK(s.str() == "[1, 2, 3, ]"); } { std::stringstream s; print(s, "abcd"); BOOST_HANA_RUNTIME_CHECK(s.str() == "abcd"); } }