Add is_contiguous_range_test2

This commit is contained in:
Peter Dimov
2022-09-18 14:26:30 +03:00
parent 6757bd4f00
commit 79fff9e1ea
3 changed files with 70 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
#ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#include <boost/container_hash/is_range.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
@@ -28,12 +29,16 @@ template<class It, class T, class 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 container_hash
{
template<class T> struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_<T>( 0 ) )
template<class T> struct is_contiguous_range: integral_constant< bool, is_range<T>::value && hash_detail::is_contiguous_range<T>::value >
{
};

View File

@@ -99,3 +99,4 @@ run hash_unordered_set_test.cpp ;
run hash_unordered_map_test.cpp ;
run is_range_test3.cpp ;
run is_contiguous_range_test2.cpp ;

View File

@@ -0,0 +1,63 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/type_traits/integral_constant.hpp>
#include <cstddef>
struct X1
{
char const* begin() const;
char const* end() const;
char const* data() const;
std::size_t size() const;
};
struct X2
{
char const* begin() const;
char const* end() const;
char const* data() const;
std::size_t size() const;
};
struct X3
{
char const* begin() const;
char const* end() const;
char const* data() const;
std::size_t size() const;
};
namespace boost
{
namespace container_hash
{
template<class T> struct is_contiguous_range;
template<> struct is_contiguous_range<X2>: boost::false_type {};
template<class T> struct is_range;
template<> struct is_range<X3>: boost::false_type {};
} // namespace container_hash
} // namespace boost
#include <boost/container_hash/is_contiguous_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
int main()
{
using boost::container_hash::is_contiguous_range;
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<X1>));
#endif
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<X2>));
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<X3>));
return boost::report_errors();
}