rebind_any.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_REBIND_ANY_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_REBIND_ANY_HPP_INCLUDED
  12. #include <boost/mpl/if.hpp>
  13. #include <boost/type_traits/remove_cv.hpp>
  14. #include <boost/type_traits/remove_reference.hpp>
  15. #include <boost/type_erasure/is_placeholder.hpp>
  16. #include <boost/type_erasure/concept_of.hpp>
  17. namespace boost {
  18. namespace type_erasure {
  19. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  20. template<class Concept, class T>
  21. class any;
  22. #endif
  23. /**
  24. * A metafunction that changes the @ref placeholder of
  25. * an @ref any. If @c T is not a placeholder,
  26. * returns @c T unchanged. This class is intended
  27. * to be used in @ref concept_interface to deduce
  28. * the argument types from the arguments of the concept.
  29. *
  30. * @pre Any must be a specialization of @ref any or a base
  31. * class of such a specialization.
  32. *
  33. * \code
  34. * rebind_any<any<Concept>, _a>::type -> any<Concept, _a>
  35. * rebind_any<any<Concept>, _b&>::type -> any<Concept, _b&>
  36. * rebind_any<any<Concept>, _c&&>::type -> any<Concept, _c&&>
  37. * rebind_any<any<Concept>, int>::type -> int
  38. * \endcode
  39. *
  40. * @see derived, as_param
  41. */
  42. template<class Any, class T>
  43. struct rebind_any
  44. {
  45. #ifdef BOOST_TYPE_ERASURE_DOXYGEN
  46. typedef detail::unspecified type;
  47. #else
  48. typedef typename ::boost::mpl::if_<
  49. ::boost::type_erasure::is_placeholder<
  50. typename ::boost::remove_cv<
  51. typename ::boost::remove_reference<T>::type
  52. >::type
  53. >,
  54. ::boost::type_erasure::any<
  55. typename ::boost::type_erasure::concept_of<Any>::type,
  56. T
  57. >,
  58. T
  59. >::type type;
  60. #endif
  61. };
  62. #ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
  63. template<class Any, class T>
  64. using rebind_any_t = typename ::boost::type_erasure::rebind_any<Any, T>::type;
  65. #endif
  66. }
  67. }
  68. #endif