is_range.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2017 Peter Dimov.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // https://www.boost.org/LICENSE_1_0.txt
  4. #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED
  5. #define BOOST_HASH_IS_RANGE_HPP_INCLUDED
  6. #include <boost/container_hash/detail/requires_cxx11.hpp>
  7. #include <boost/type_traits/integral_constant.hpp>
  8. #include <boost/type_traits/is_integral.hpp>
  9. #include <boost/type_traits/declval.hpp>
  10. #include <boost/type_traits/is_same.hpp>
  11. #include <boost/type_traits/remove_cv.hpp>
  12. #include <boost/config.hpp>
  13. #include <boost/config/workaround.hpp>
  14. #include <iterator>
  15. namespace boost
  16. {
  17. #if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
  18. namespace hash_detail
  19. {
  20. template<class T, class It>
  21. integral_constant< bool, !is_same<typename remove_cv<T>::type, typename std::iterator_traits<It>::value_type>::value >
  22. is_range_check( It first, It last );
  23. template<class T> decltype( is_range_check<T>( declval<T const&>().begin(), declval<T const&>().end() ) ) is_range_( int );
  24. template<class T> false_type is_range_( ... );
  25. } // namespace hash_detail
  26. namespace container_hash
  27. {
  28. template<class T> struct is_range: decltype( hash_detail::is_range_<T>( 0 ) )
  29. {
  30. };
  31. } // namespace container_hash
  32. #else
  33. namespace hash_detail
  34. {
  35. template<class T, class E = true_type> struct is_range_: false_type
  36. {
  37. };
  38. template<class T> struct is_range_< T, integral_constant< bool,
  39. is_same<typename T::value_type, typename std::iterator_traits<typename T::const_iterator>::value_type>::value &&
  40. is_integral<typename T::size_type>::value
  41. > >: true_type
  42. {
  43. };
  44. } // namespace hash_detail
  45. namespace container_hash
  46. {
  47. template<class T> struct is_range: hash_detail::is_range_<T>
  48. {
  49. };
  50. } // namespace container_hash
  51. #endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
  52. } // namespace boost
  53. #endif // #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED