is_contiguous_range.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2017, 2018 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_CONTIGUOUS_RANGE_HPP_INCLUDED
  5. #define BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
  6. #include <boost/container_hash/is_range.hpp>
  7. #include <boost/config.hpp>
  8. #include <boost/config/workaround.hpp>
  9. #include <type_traits>
  10. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
  11. #include <iterator>
  12. namespace boost
  13. {
  14. namespace hash_detail
  15. {
  16. template<class It, class T, class S>
  17. std::integral_constant< bool, std::is_same<typename std::iterator_traits<It>::value_type, T>::value && std::is_integral<S>::value >
  18. is_contiguous_range_check( It first, It last, T const*, T const*, S );
  19. template<class T> decltype( is_contiguous_range_check( std::declval<T const&>().begin(), std::declval<T const&>().end(), std::declval<T const&>().data(), std::declval<T const&>().data() + std::declval<T const&>().size(), std::declval<T const&>().size() ) ) is_contiguous_range_( int );
  20. template<class T> std::false_type is_contiguous_range_( ... );
  21. template<class T> struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_<T>( 0 ) )
  22. {
  23. };
  24. } // namespace hash_detail
  25. namespace container_hash
  26. {
  27. template<class T> struct is_contiguous_range: std::integral_constant< bool, is_range<T>::value && hash_detail::is_contiguous_range<T>::value >
  28. {
  29. };
  30. } // namespace container_hash
  31. } // namespace boost
  32. #else // !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
  33. #include <cstddef>
  34. #include <vector>
  35. #include <string>
  36. #include <array>
  37. namespace boost
  38. {
  39. namespace container_hash
  40. {
  41. template<class T> struct is_contiguous_range: std::false_type
  42. {
  43. };
  44. template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> >: std::true_type
  45. {
  46. };
  47. template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> const >: std::true_type
  48. {
  49. };
  50. template<class T, class A> struct is_contiguous_range< std::vector<T, A> >: std::true_type
  51. {
  52. };
  53. template<class T, class A> struct is_contiguous_range< std::vector<T, A> const >: std::true_type
  54. {
  55. };
  56. template<class A> struct is_contiguous_range< std::vector<bool, A> >: std::false_type
  57. {
  58. };
  59. template<class A> struct is_contiguous_range< std::vector<bool, A> const >: std::false_type
  60. {
  61. };
  62. template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> >: std::true_type
  63. {
  64. };
  65. template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> const >: std::true_type
  66. {
  67. };
  68. } // namespace container_hash
  69. } // namespace boost
  70. #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
  71. #endif // #ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED