convert.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2012 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/any.hpp>
  11. #include <boost/type_erasure/builtin.hpp>
  12. #include <boost/type_erasure/operators.hpp>
  13. #include <ostream>
  14. namespace mpl = boost::mpl;
  15. using namespace boost::type_erasure;
  16. void convert1() {
  17. //[convert1
  18. /*`
  19. An __any can be converted to another __any
  20. as long as the conversion is an "upcast."
  21. */
  22. typedef any<
  23. mpl::vector<
  24. copy_constructible<>,
  25. typeid_<>,
  26. ostreamable<>
  27. >
  28. > any_printable;
  29. typedef any<
  30. mpl::vector<
  31. copy_constructible<>,
  32. typeid_<>
  33. >
  34. > common_any;
  35. any_printable x(10);
  36. common_any y(x);
  37. /*`
  38. This conversion is okay because the requirements of `common_any`
  39. are a subset of the requirements of `any_printable`. Conversion
  40. in the other direction is illegal.
  41. ``
  42. common_any x(10);
  43. any_printable y(x); // error
  44. ``
  45. */
  46. //]
  47. }
  48. //[convert
  49. //` (For the source of the examples in this section see
  50. //` [@boost:/libs/type_erasure/example/convert.cpp convert.cpp])
  51. //` [convert1]
  52. //]