forked from boostorg/container_hash
Add detail/is_range.hpp
This commit is contained in:
55
include/boost/container_hash/detail/is_range.hpp
Normal file
55
include/boost/container_hash/detail/is_range.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2017 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_HASH_DETAIL_IS_RANGE_HPP_INCLUDED
|
||||
#define BOOST_HASH_DETAIL_IS_RANGE_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/declval.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <iterator>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace hash_detail
|
||||
{
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
|
||||
template<class It> true_type is_range_check( It first, It last, typename std::iterator_traits<It>::difference_type* = 0 );
|
||||
|
||||
template<class T> decltype( is_range_check( declval<T const&>().begin(), declval<T const&>().end() ) ) is_range_( int );
|
||||
template<class T> false_type is_range_( ... );
|
||||
|
||||
template<class T> struct is_range: decltype( is_range_<T>( 0 ) )
|
||||
{
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template<class T, class E = true_type> struct is_range_: false_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class T> struct is_range_< T, integral_constant< bool,
|
||||
is_same<typename T::value_type, typename std::iterator_traits<typename T::const_iterator>::value_type>::value &&
|
||||
is_integral<typename T::size_type>::value
|
||||
> >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class T> struct is_range: is_range_<T>
|
||||
{
|
||||
};
|
||||
|
||||
#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
|
||||
|
||||
} // namespace hash_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_HASH_DETAIL_IS_RANGE_HPP_INCLUDED
|
@@ -85,3 +85,5 @@ test-suite container_hash/hash_no_generic_float
|
||||
explicit container_hash/hash_no_generic_float ;
|
||||
|
||||
build-project ../examples ;
|
||||
|
||||
run detail_is_range_test.cpp ;
|
||||
|
98
test/detail_is_range_test.cpp
Normal file
98
test/detail_is_range_test.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright 2017 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/container_hash/detail/is_range.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
|
||||
# include <array>
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST)
|
||||
# include <forward_list>
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
|
||||
# include <unordered_set>
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
|
||||
# include <unordered_map>
|
||||
#endif
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::hash_detail::is_range;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<void>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<void const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<int>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<int const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<X>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<X const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<int[2]>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_range<int const[2]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range<std::string>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range<std::string const>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range<std::wstring>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range<std::wstring const>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::vector<X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::vector<X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::deque<X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::deque<X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::set<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::set<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::multiset<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::multiset<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::map<int, X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::map<int, X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::multimap<int, X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::multimap<int, X> const >));
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::array<X, 2> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::array<X, 2> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST)
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::forward_list<X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::forward_list<X> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_set<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_set<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_multiset<int> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_multiset<int> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_map<int, X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_map<int, X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_multimap<int, X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_range< std::unordered_multimap<int, X> const >));
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user