]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/core/default.cpp
1 // Copyright Louis Dionne 2013-2016
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/core/default.hpp>
7 #include <boost/hana/core/tag_of.hpp>
13 namespace hana
= boost::hana
;
16 // In the header defining the concept of a Printable
18 struct print_impl
: hana::default_
{
19 template <typename Stream
, typename X
>
20 static void apply(Stream
& out
, X
const& x
)
24 auto print
= [](auto& stream
, auto const& x
) {
25 return print_impl
<hana::tag_of_t
<decltype(x
)>>::apply(stream
, x
);
28 // In some other header
30 struct print_impl
<std::vector
<T
>> {
31 template <typename Stream
>
32 static void apply(Stream
& out
, std::vector
<T
> const& xs
) {
34 std::copy(begin(xs
), end(xs
), std::ostream_iterator
<T
>{out
, ", "});
39 static_assert(hana::is_default
<print_impl
<int>>{}, "");
40 static_assert(!hana::is_default
<print_impl
<std::vector
<int>>>{}, "");
45 print(s
, std::vector
<int>{1, 2, 3});
46 BOOST_HANA_RUNTIME_CHECK(s
.str() == "[1, 2, 3, ]");
52 BOOST_HANA_RUNTIME_CHECK(s
.str() == "abcd");