element_type_of.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_ELEMENT_TYPE_OF_HPP_JOFA_100902
  9. #define BOOST_ICL_TYPE_TRAITS_ELEMENT_TYPE_OF_HPP_JOFA_100902
  10. #include <boost/mpl/has_xxx.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/icl/type_traits/no_type.hpp>
  13. namespace boost{ namespace icl
  14. {
  15. namespace detail
  16. {
  17. BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
  18. BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
  19. BOOST_MPL_HAS_XXX_TRAIT_DEF(key_type)
  20. }
  21. //--------------------------------------------------------------------------
  22. template <class Type>
  23. struct has_element_type
  24. : mpl::bool_<detail::has_element_type<Type>::value>
  25. {};
  26. template <class Type, bool has_element_type>
  27. struct get_element_type;
  28. template <class Type>
  29. struct get_element_type<Type, false>
  30. {
  31. typedef no_type type;
  32. };
  33. template <class Type>
  34. struct get_element_type<Type, true>
  35. {
  36. typedef typename Type::element_type type;
  37. };
  38. template <class Type>
  39. struct element_type_of
  40. {
  41. typedef typename
  42. get_element_type<Type, has_element_type<Type>::value>::type type;
  43. };
  44. //--------------------------------------------------------------------------
  45. template <class Type>
  46. struct has_value_type
  47. : mpl::bool_<detail::has_value_type<Type>::value>
  48. {};
  49. template <class Type, bool has_value_type>
  50. struct get_value_type;
  51. template <class Type>
  52. struct get_value_type<Type, false>
  53. {
  54. typedef no_type type;
  55. };
  56. template <class Type>
  57. struct get_value_type<Type, true>
  58. {
  59. typedef typename Type::value_type type;
  60. };
  61. template <class Type>
  62. struct value_type_of
  63. {
  64. typedef typename
  65. get_value_type<Type, has_value_type<Type>::value>::type type;
  66. };
  67. //--------------------------------------------------------------------------
  68. template <class Type>
  69. struct has_key_type
  70. : mpl::bool_<detail::has_key_type<Type>::value>
  71. {};
  72. template <class Type, bool has_key_type>
  73. struct get_key_type;
  74. template <class Type>
  75. struct get_key_type<Type, false>
  76. {
  77. typedef no_type type;
  78. };
  79. template <class Type>
  80. struct get_key_type<Type, true>
  81. {
  82. typedef typename Type::key_type type;
  83. };
  84. template <class Type>
  85. struct key_type_of
  86. {
  87. typedef typename
  88. get_key_type<Type, has_key_type<Type>::value>::type type;
  89. };
  90. }} // namespace boost icl
  91. #endif