forked from boostorg/container_hash
Add detail/is_contiguous_range.hpp
This commit is contained in:
89
include/boost/container_hash/detail/is_contiguous_range.hpp
Normal file
89
include/boost/container_hash/detail/is_contiguous_range.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// Copyright 2017, 2018 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_HASH_DETAIL_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
|
||||
#define BOOST_HASH_DETAIL_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/declval.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <iterator>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace hash_detail
|
||||
{
|
||||
|
||||
template<class It, class T, class S>
|
||||
integral_constant< bool, is_same<typename std::iterator_traits<It>::value_type, T>::value && is_integral<S>::value >
|
||||
is_contiguous_range_check( It first, It last, T const*, T const*, S );
|
||||
|
||||
template<class T> decltype( is_contiguous_range_check( declval<T const&>().begin(), declval<T const&>().end(), declval<T const&>().data(), declval<T const&>().data() + declval<T const&>().size(), declval<T const&>().size() ) ) is_contiguous_range_( int );
|
||||
template<class T> false_type is_contiguous_range_( ... );
|
||||
|
||||
template<class T> struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_<T>( 0 ) )
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace hash_detail
|
||||
} // namespace boost
|
||||
|
||||
#else // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace hash_detail
|
||||
{
|
||||
|
||||
template<class T> struct is_contiguous_range: false_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, class A> struct is_contiguous_range< std::vector<T, A> >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, class A> struct is_contiguous_range< std::vector<T, A> const >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> const >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
|
||||
|
||||
template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> const >: true_type
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace hash_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
|
||||
|
||||
#endif // #ifndef BOOST_HASH_DETAIL_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
|
@@ -87,3 +87,4 @@ explicit container_hash/hash_no_generic_float ;
|
||||
build-project ../examples ;
|
||||
|
||||
run detail_is_range_test.cpp ;
|
||||
run detail_is_contiguous_range_test.cpp ;
|
||||
|
98
test/detail_is_contiguous_range_test.cpp
Normal file
98
test/detail_is_contiguous_range_test.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright 2017, 2018 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_contiguous_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_contiguous_range;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<void>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<void const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<int>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<int const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<X>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<X const>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<int[2]>));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<int const[2]>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<std::string>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<std::string const>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<std::wstring>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<std::wstring const>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector<X> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector<X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque<X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque<X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::set<int> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::set<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multiset<int> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multiset<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::map<int, X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::map<int, X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multimap<int, X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multimap<int, X> const >));
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::array<X, 2> >));
|
||||
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::array<X, 2> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST)
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::forward_list<X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::forward_list<X> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_set<int> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_set<int> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multiset<int> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multiset<int> const >));
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_map<int, X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_map<int, X> const >));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multimap<int, X> >));
|
||||
BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multimap<int, X> const >));
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user