concept_map.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <boost/type_erasure/operators.hpp>
  11. #include <typeinfo>
  12. namespace mpl = boost::mpl;
  13. using namespace boost::type_erasure;
  14. //[concept_map1
  15. /*`
  16. Sometimes it is useful to non-intrusively adapt a
  17. type to model a concept. For example, suppose that
  18. we want to make `std::type_info` model __less_than_comparable.
  19. To do this, we simply specialize the concept definition.
  20. */
  21. namespace boost {
  22. namespace type_erasure {
  23. template<>
  24. struct less_than_comparable<std::type_info>
  25. {
  26. static bool apply(const std::type_info& lhs, const std::type_info& rhs)
  27. { return lhs.before(rhs) != 0; }
  28. };
  29. }
  30. }
  31. /*`
  32. [note Most, but not all of the builtin concepts can be specialized.
  33. Constructors, destructors, and RTTI need special treatment from the
  34. library and cannot be specialized. Only primitive concepts can
  35. be specialized, so the iterator concepts are also out.]
  36. */
  37. //]
  38. //[concept_map
  39. //` (For the source of the examples in this section see
  40. //` [@boost:/libs/type_erasure/example/concept_map.cpp concept_map.cpp])
  41. //` [concept_map1]
  42. //]