has_member_size.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014.
  4. //
  5. // Use, modification and distribution are subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt).
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. #ifndef BOOST_RANGE_DETAIL_HAS_MEMBER_SIZE_HPP
  12. #define BOOST_RANGE_DETAIL_HAS_MEMBER_SIZE_HPP
  13. #include <boost/type_traits/is_class.hpp>
  14. #include <boost/type_traits/is_member_function_pointer.hpp>
  15. #include <boost/mpl/and.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/cstdint.hpp>
  18. namespace boost
  19. {
  20. namespace range_detail
  21. {
  22. template<class T>
  23. class has_member_size_impl
  24. {
  25. private:
  26. template<class U, U>
  27. class check
  28. {
  29. };
  30. template<class C>
  31. static boost::uint8_t f(check<std::size_t(C::*)(void) const, &C::size>*);
  32. template<class C>
  33. static boost::uint16_t f(...);
  34. public:
  35. static const bool value =
  36. (sizeof(f<T>(0)) == sizeof(boost::uint8_t));
  37. typedef typename mpl::if_c<
  38. (sizeof(f<T>(0)) == sizeof(boost::uint8_t)),
  39. mpl::true_,
  40. mpl::false_
  41. >::type type;
  42. };
  43. template<class T>
  44. struct has_member_size
  45. {
  46. typedef typename mpl::and_<
  47. typename is_class<T>::type,
  48. typename has_member_size_impl<const T>::type
  49. >::type type;
  50. static const bool value =
  51. is_class<T>::value && has_member_size_impl<const T>::value;
  52. };
  53. } // namespace range_detail
  54. }// namespace boost
  55. #endif // include guard