size_type_of.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_SIZE_TYPE_OF_HPP_JOFA_080911
  9. #define BOOST_ICL_TYPE_TRAITS_SIZE_TYPE_OF_HPP_JOFA_080911
  10. #include <boost/mpl/has_xxx.hpp>
  11. #include <boost/icl/type_traits/difference_type_of.hpp>
  12. namespace boost{ namespace icl
  13. {
  14. namespace detail
  15. {
  16. BOOST_MPL_HAS_XXX_TRAIT_DEF(size_type)
  17. }
  18. //--------------------------------------------------------------------------
  19. template <class Type>
  20. struct has_size_type
  21. : mpl::bool_<detail::has_size_type<Type>::value>
  22. {};
  23. //--------------------------------------------------------------------------
  24. template <class Type, bool has_size, bool has_diff, bool has_rep>
  25. struct get_size_type;
  26. template <class Type>
  27. struct get_size_type<Type, false, false, false>
  28. {
  29. typedef std::size_t type;
  30. };
  31. template <class Type, bool has_diff, bool has_rep>
  32. struct get_size_type<Type, true, has_diff, has_rep>
  33. {
  34. typedef typename Type::size_type type;
  35. };
  36. template <class Type, bool has_rep>
  37. struct get_size_type<Type, false, true, has_rep>
  38. {
  39. typedef typename Type::difference_type type;
  40. };
  41. template <class Type>
  42. struct get_size_type<Type, false, false, true>
  43. {
  44. typedef Type type;
  45. };
  46. //--------------------------------------------------------------------------
  47. template<class Type>
  48. struct size_type_of
  49. {
  50. typedef typename
  51. get_size_type< Type
  52. , has_size_type<Type>::value
  53. , has_difference_type<Type>::value
  54. , has_rep_type<Type>::value
  55. >::type type;
  56. };
  57. }} // namespace boost icl
  58. #endif