Add detail/is_unordered_range.hpp

This commit is contained in:
Peter Dimov
2021-10-16 21:01:07 +03:00
parent 00c837d523
commit d308495a67
3 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
// 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_UNORDERED_RANGE_HPP_INCLUDED
#define BOOST_HASH_DETAIL_IS_UNORDERED_RANGE_HPP_INCLUDED
#include <boost/container_hash/detail/is_range.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost
{
namespace hash_detail
{
template<class T, class E = true_type> struct has_hasher_: false_type
{
};
template<class T> struct has_hasher_< T, integral_constant< bool,
is_same<typename T::hasher, typename T::hasher>::value
> >: true_type
{
};
template<class T> struct is_unordered_range: integral_constant< bool, is_range<T>::value && has_hasher_<T>::value >
{
};
} // namespace hash_detail
} // namespace boost
#endif // #ifndef BOOST_HASH_DETAIL_IS_UNORDERED_RANGE_HPP_INCLUDED

View File

@@ -88,3 +88,4 @@ build-project ../examples ;
run detail_is_range_test.cpp ;
run detail_is_contiguous_range_test.cpp ;
run detail_is_unordered_range_test.cpp ;

View 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_unordered_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_unordered_range;
BOOST_TEST_TRAIT_FALSE((is_unordered_range<void>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<void const>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<int>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<int const>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<X>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<X const>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<int[2]>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<int const[2]>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<std::string>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<std::string const>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<std::wstring>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<std::wstring const>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::vector<X> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::vector<X> const >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::deque<X> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::deque<X> const >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::set<int> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::set<int> const >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::multiset<int> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::multiset<int> const >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::map<int, X> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::map<int, X> const >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::multimap<int, X> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::multimap<int, X> const >));
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::array<X, 2> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::array<X, 2> const >));
#endif
#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST)
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::forward_list<X> >));
BOOST_TEST_TRAIT_FALSE((is_unordered_range< std::forward_list<X> const >));
#endif
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_set<int> >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_set<int> const >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_multiset<int> >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_multiset<int> const >));
#endif
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_map<int, X> >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_map<int, X> const >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_multimap<int, X> >));
BOOST_TEST_TRAIT_TRUE((is_unordered_range< std::unordered_multimap<int, X> const >));
#endif
return boost::report_errors();
}