rep_type_of.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_TYPE_TRAITS_REP_TYPE_OF_HPP_JOFA_110329
  9. #define BOOST_ICL_TYPE_TRAITS_REP_TYPE_OF_HPP_JOFA_110329
  10. #include <boost/config.hpp> // For macro BOOST_STATIC_CONSTANT
  11. #include <boost/mpl/has_xxx.hpp>
  12. #include <boost/mpl/or.hpp>
  13. #include <boost/mpl/and.hpp>
  14. #include <boost/mpl/not.hpp>
  15. #include <boost/type_traits/is_same.hpp>
  16. #include <boost/icl/type_traits/no_type.hpp>
  17. namespace boost{ namespace icl
  18. {
  19. namespace detail
  20. {
  21. BOOST_MPL_HAS_XXX_TRAIT_DEF(rep)
  22. }
  23. //--------------------------------------------------------------------------
  24. template <class Type>
  25. struct has_rep_type
  26. : mpl::bool_<detail::has_rep<Type>::value>
  27. {};
  28. template <class Rep, class Type>
  29. struct represents // Rep represents Type; Type is_wrapper_of Rep
  30. : mpl::bool_<detail::has_rep<Type>::value>
  31. {
  32. typedef represents type;
  33. BOOST_STATIC_CONSTANT(bool,
  34. value = (mpl::and_< has_rep_type<Type>
  35. , boost::is_same<typename Type::rep, Rep> >::value)
  36. );
  37. };
  38. //--------------------------------------------------------------------------
  39. template <class Type, bool has_rep>
  40. struct get_rep_type;
  41. template <class Type>
  42. struct get_rep_type<Type, false>
  43. {
  44. typedef no_type type;
  45. };
  46. template <class Type>
  47. struct get_rep_type<Type, true>
  48. {
  49. typedef typename Type::rep type;
  50. };
  51. //--------------------------------------------------------------------------
  52. template<class Type>
  53. struct rep_type_of
  54. {
  55. typedef typename
  56. get_rep_type<Type, has_rep_type<Type>::value>::type type;
  57. };
  58. }} // namespace boost icl
  59. #endif