From 00c837d5237a23c973bdec030a56d0c09ea04d63 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 16 Oct 2021 20:54:51 +0300 Subject: [PATCH] Add detail/is_contiguous_range.hpp --- .../detail/is_contiguous_range.hpp | 89 +++++++++++++++++ test/Jamfile.v2 | 1 + test/detail_is_contiguous_range_test.cpp | 98 +++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 include/boost/container_hash/detail/is_contiguous_range.hpp create mode 100644 test/detail_is_contiguous_range_test.cpp diff --git a/include/boost/container_hash/detail/is_contiguous_range.hpp b/include/boost/container_hash/detail/is_contiguous_range.hpp new file mode 100644 index 0000000..1f3731e --- /dev/null +++ b/include/boost/container_hash/detail/is_contiguous_range.hpp @@ -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 +#include +#include + +#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) + +#include +#include +#include +#include + +namespace boost +{ +namespace hash_detail +{ + +template + integral_constant< bool, is_same::value_type, T>::value && is_integral::value > + is_contiguous_range_check( It first, It last, T const*, T const*, S ); + +template decltype( is_contiguous_range_check( declval().begin(), declval().end(), declval().data(), declval().data() + declval().size(), declval().size() ) ) is_contiguous_range_( int ); +template false_type is_contiguous_range_( ... ); + +template struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_( 0 ) ) +{ +}; + +} // namespace hash_detail +} // namespace boost + +#else // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) + +#include +#include +#include +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) +#include +#endif + +namespace boost +{ +namespace hash_detail +{ + +template struct is_contiguous_range: false_type +{ +}; + +template struct is_contiguous_range< std::vector >: true_type +{ +}; + +template struct is_contiguous_range< std::vector const >: true_type +{ +}; + +template struct is_contiguous_range< std::basic_string >: true_type +{ +}; + +template struct is_contiguous_range< std::basic_string const >: true_type +{ +}; + +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) + +template struct is_contiguous_range< std::array >: true_type +{ +}; + +template struct is_contiguous_range< std::array 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 diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e930fa4..c6d2ac8 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ; diff --git a/test/detail_is_contiguous_range_test.cpp b/test/detail_is_contiguous_range_test.cpp new file mode 100644 index 0000000..9b495cd --- /dev/null +++ b/test/detail_is_contiguous_range_test.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) +# include +#endif +#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) +# include +#endif +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) +# include +#endif +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP) +# include +#endif + +struct X +{ +}; + +int main() +{ + using boost::hash_detail::is_contiguous_range; + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range)); + + BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); + BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); + + BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); + BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); + + BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector >)); + BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::set >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::set const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multiset >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multiset const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::map >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::map const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multimap >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::multimap const >)); + +#if !defined(BOOST_NO_CXX11_HDR_ARRAY) + BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::array >)); + BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::array const >)); +#endif + +#if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::forward_list >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::forward_list const >)); +#endif + +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_set >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_set const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multiset >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multiset const >)); +#endif + +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP) + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_map >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_map const >)); + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multimap >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::unordered_multimap const >)); +#endif + + return boost::report_errors(); +}