]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
4 | ||
5 | #include <boost/hana/core/default.hpp> | |
6 | #include <boost/hana/core/tag_of.hpp> | |
7 | ||
8 | #include <string> | |
9 | #include <type_traits> | |
10 | namespace hana = boost::hana; | |
11 | ||
12 | ||
13 | namespace with_special_base_class { | |
14 | //! [special_base_class] | |
15 | struct special_base_class { }; | |
16 | ||
17 | template <typename T> | |
18 | struct print_impl : special_base_class { | |
19 | template <typename ...Args> | |
20 | static constexpr auto apply(Args&& ...) = delete; | |
21 | }; | |
22 | ||
23 | template <typename T> | |
24 | struct Printable { | |
25 | using Tag = hana::tag_of_t<T>; | |
26 | static constexpr bool value = !std::is_base_of<special_base_class, print_impl<Tag>>::value; | |
27 | }; | |
28 | //! [special_base_class] | |
29 | ||
30 | //! [special_base_class_customize] | |
31 | struct Person { std::string name; }; | |
32 | ||
33 | template <> | |
34 | struct print_impl<Person> /* don't inherit from special_base_class */ { | |
35 | // ... implementation ... | |
36 | }; | |
37 | ||
38 | static_assert(Printable<Person>::value, ""); | |
39 | static_assert(!Printable<void>::value, ""); | |
40 | //! [special_base_class_customize] | |
41 | } | |
42 | ||
43 | namespace actual { | |
44 | //! [actual] | |
45 | template <typename T> | |
46 | struct print_impl : hana::default_ { | |
47 | template <typename ...Args> | |
48 | static constexpr auto apply(Args&& ...) = delete; | |
49 | }; | |
50 | ||
51 | template <typename T> | |
52 | struct Printable { | |
53 | using Tag = hana::tag_of_t<T>; | |
54 | static constexpr bool value = !hana::is_default<print_impl<Tag>>::value; | |
55 | }; | |
56 | //! [actual] | |
57 | ||
58 | static_assert(!Printable<void>::value, ""); | |
59 | } | |
60 | ||
61 | int main() { } |