| 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 | |
| 5 | #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED |
| 6 | #define BOOST_HASH_IS_RANGE_HPP_INCLUDED |
| 7 | |
| 8 | #include <boost/container_hash/detail/requires_cxx11.hpp> |
| 9 | #include <boost/type_traits/integral_constant.hpp> |
| 10 | #include <boost/type_traits/is_integral.hpp> |
| 11 | #include <boost/type_traits/declval.hpp> |
| 12 | #include <boost/type_traits/is_same.hpp> |
| 13 | #include <boost/type_traits/remove_cv.hpp> |
| 14 | #include <boost/config.hpp> |
| 15 | #include <boost/config/workaround.hpp> |
| 16 | #include <iterator> |
| 17 | |
| 18 | namespace boost |
| 19 | { |
| 20 | #if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) |
| 21 | |
| 22 | namespace hash_detail |
| 23 | { |
| 24 | |
| 25 | template<class T, class It> |
| 26 | integral_constant< bool, !is_same<typename remove_cv<T>::type, typename std::iterator_traits<It>::value_type>::value > |
| 27 | is_range_check( It first, It last ); |
| 28 | |
| 29 | template<class T> decltype( is_range_check<T>( declval<T const&>().begin(), declval<T const&>().end() ) ) is_range_( int ); |
| 30 | template<class T> false_type is_range_( ... ); |
| 31 | |
| 32 | } // namespace hash_detail |
| 33 | |
| 34 | namespace container_hash |
| 35 | { |
| 36 | |
| 37 | template<class T> struct is_range: decltype( hash_detail::is_range_<T>( 0 ) ) |
| 38 | { |
| 39 | }; |
| 40 | |
| 41 | } // namespace container_hash |
| 42 | |
| 43 | #else |
| 44 | |
| 45 | namespace hash_detail |
| 46 | { |
| 47 | |
| 48 | template<class T, class E = true_type> struct is_range_: false_type |
| 49 | { |
| 50 | }; |
| 51 | |
| 52 | template<class T> struct is_range_< T, integral_constant< bool, |
| 53 | is_same<typename T::value_type, typename std::iterator_traits<typename T::const_iterator>::value_type>::value && |
| 54 | is_integral<typename T::size_type>::value |
| 55 | > >: true_type |
| 56 | { |
| 57 | }; |
| 58 | |
| 59 | } // namespace hash_detail |
| 60 | |
| 61 | namespace container_hash |
| 62 | { |
| 63 | |
| 64 | template<class T> struct is_range: hash_detail::is_range_<T> |
| 65 | { |
| 66 | }; |
| 67 | |
| 68 | } // namespace container_hash |
| 69 | |
| 70 | #endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) |
| 71 | |
| 72 | } // namespace boost |
| 73 | |
| 74 | #endif // #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED |
| 75 | |