typeid_of.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_TYPEID_OF_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_TYPEID_OF_HPP_INCLUDED
  12. #include <boost/type_traits/remove_cv.hpp>
  13. #include <boost/type_traits/remove_reference.hpp>
  14. #include <boost/type_erasure/detail/access.hpp>
  15. #include <boost/type_erasure/any.hpp>
  16. #include <boost/type_erasure/binding.hpp>
  17. namespace boost {
  18. namespace type_erasure {
  19. /**
  20. * The first form returns the type currently stored in an @ref any.
  21. *
  22. * The second form returns the type corresponding to a
  23. * placeholder in @c binding.
  24. *
  25. * \pre @c Concept includes @ref typeid_ "typeid_<T>".
  26. * \pre @c T is a non-reference, CV-unqualified @ref placeholder.
  27. */
  28. template<class Concept, class T>
  29. const std::type_info& typeid_of(const any<Concept, T>& arg)
  30. {
  31. return ::boost::type_erasure::detail::access::table(arg).template find<
  32. ::boost::type_erasure::typeid_<
  33. typename ::boost::remove_cv<
  34. typename ::boost::remove_reference<T>::type
  35. >::type
  36. >
  37. >()();
  38. }
  39. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  40. template<class Concept, class T>
  41. const std::type_info& typeid_of(const param<Concept, T>& arg)
  42. {
  43. return ::boost::type_erasure::detail::access::table(arg).template find<
  44. ::boost::type_erasure::typeid_<
  45. typename ::boost::remove_cv<
  46. typename ::boost::remove_reference<T>::type
  47. >::type
  48. >
  49. >()();
  50. }
  51. #endif
  52. /**
  53. * \overload
  54. */
  55. template<class T, class Concept>
  56. const std::type_info& typeid_of(const binding<Concept>& binding_arg)
  57. {
  58. return binding_arg.template find< ::boost::type_erasure::typeid_<T> >()();
  59. }
  60. }
  61. }
  62. #endif