| 1 | // Boost.TypeErasure library |
| 2 | // |
| 3 | // Copyright 2011 Steven Watanabe |
| 4 | // |
| 5 | // Distributed under the Boost Software License Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // $Id$ |
| 10 | |
| 11 | #include <boost/type_erasure/operators.hpp> |
| 12 | #include <typeinfo> |
| 13 | |
| 14 | namespace mpl = boost::mpl; |
| 15 | using namespace boost::type_erasure; |
| 16 | |
| 17 | //[concept_map1 |
| 18 | /*` |
| 19 | Sometimes it is useful to non-intrusively adapt a |
| 20 | type to model a concept. For example, suppose that |
| 21 | we want to make `std::type_info` model __less_than_comparable. |
| 22 | To do this, we simply specialize the concept definition. |
| 23 | */ |
| 24 | namespace boost { |
| 25 | namespace type_erasure { |
| 26 | |
| 27 | template<> |
| 28 | struct less_than_comparable<std::type_info> |
| 29 | { |
| 30 | static bool apply(const std::type_info& lhs, const std::type_info& rhs) |
| 31 | { return lhs.before(arg: rhs) != 0; } |
| 32 | }; |
| 33 | |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /*` |
| 38 | [note Most, but not all of the builtin concepts can be specialized. |
| 39 | Constructors, destructors, and RTTI need special treatment from the |
| 40 | library and cannot be specialized. Only primitive concepts can |
| 41 | be specialized, so the iterator concepts are also out.] |
| 42 | */ |
| 43 | |
| 44 | //] |
| 45 | |
| 46 | //[concept_map |
| 47 | //` (For the source of the examples in this section see |
| 48 | //` [@boost:/libs/type_erasure/example/concept_map.cpp concept_map.cpp]) |
| 49 | //` [concept_map1] |
| 50 | //] |
| 51 | |