placeholder.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef BOOST_TYPE_ERASURE_PLACEHOLDERS_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_PLACEHOLDERS_HPP_INCLUDED
  12. namespace boost {
  13. namespace type_erasure {
  14. /**
  15. * Placeholders are used heavily throughout the library.
  16. * Every placeholder must derive from @ref placeholder.
  17. * The library provides a number of placeholders,
  18. * out of the box, but you are welcome to define your own,
  19. * if you want more descriptive names. The placeholder
  20. * @ref _self is special in that it is used as the default
  21. * wherever possible.
  22. *
  23. * What exactly is a placeholder? Placeholders act as
  24. * a substitute for template parameters in concepts.
  25. * The library automatically replaces all the placeholders
  26. * used in a concept with the actual types involved when
  27. * it stores an object in an @ref any.
  28. *
  29. * For example, in the following,
  30. *
  31. * @code
  32. * any<copy_constructible<_a>, _a> x(1);
  33. * @endcode
  34. *
  35. * The library sees that we're constructing an @ref any
  36. * that uses the @ref _a placeholder with an @c int.
  37. * Thus it binds @ref _a to int and instantiates
  38. * @ref copy_constructible "copy_constructible<int>".
  39. *
  40. * When there are multiple placeholders involved, you
  41. * will have to use @ref tuple, or pass the bindings
  42. * explicitly, but the substitution still works the
  43. * same way.
  44. */
  45. struct placeholder {
  46. /// INTERNAL ONLY
  47. typedef void _boost_type_erasure_is_placeholder;
  48. };
  49. struct _a : placeholder {};
  50. struct _b : placeholder {};
  51. struct _c : placeholder {};
  52. struct _d : placeholder {};
  53. struct _e : placeholder {};
  54. struct _f : placeholder {};
  55. struct _g : placeholder {};
  56. /**
  57. * \brief The default placeholder
  58. *
  59. * @ref _self is the default @ref placeholder used
  60. * by @ref any. It should be used as a default
  61. * by most concepts, so using concepts with no
  62. * explicit arguments will "just work" as much as
  63. * possible.
  64. */
  65. struct _self : placeholder {};
  66. }
  67. }
  68. #endif