Compare commits

..

12 Commits

Author SHA1 Message Date
Peter Dimov
e387d14d36 Add hash_multimap_test 2022-09-15 16:50:39 +03:00
Peter Dimov
1fb41a72ef Add hash_multiset_test 2022-09-15 16:48:18 +03:00
Peter Dimov
c399cf6a38 Add traits to hash_fwd.hpp 2022-09-13 20:10:35 +03:00
Peter Dimov
30c32bb3df Move traits headers from container_hash/detail/ to container_hash/ 2022-09-13 19:45:45 +03:00
Peter Dimov
d1b2640dff Move type classification traits from namespace hash_detail to namespace container_hash 2022-09-13 19:37:15 +03:00
Peter Dimov
f722383d1d Change macos-10.15 to macos-11 in ci.yml 2022-08-31 18:17:01 +03:00
Peter Dimov
21530840e1 Add hash_string_test4.cpp 2022-08-31 15:09:29 +03:00
Peter Dimov
d0c1e36fc1 Add hash_string_test3.cpp 2022-08-31 14:51:47 +03:00
Peter Dimov
e00f53a69c Remove msvc-14.2 from appveyor.yml 2022-07-16 14:10:28 +03:00
Peter Dimov
b0c9904414 Test _MSVC_STL_VERSION instead of BOOST_MSVC because clang-cl 2022-07-16 13:37:15 +03:00
Peter Dimov
2d557a746d Add hash_vector_test2.cpp 2022-07-16 11:16:06 +03:00
Peter Dimov
417180dd03 Update appveyor.yml 2022-07-14 20:16:19 +03:00
18 changed files with 326 additions and 78 deletions

View File

@@ -25,10 +25,10 @@ environment:
TOOLSET: msvc-14.1
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: msvc-14.2
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: clang-win
ADDRMD: 64
CXXSTD: 14,17,latest
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: clang-win
CXXSTD: 14,17,latest

View File

@@ -121,7 +121,7 @@ jobs:
install: clang-14
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
os: macos-11
runs-on: ${{matrix.os}}
@@ -234,7 +234,7 @@ jobs:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
- os: macos-11
runs-on: ${{matrix.os}}
@@ -281,7 +281,7 @@ jobs:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
- os: macos-11
runs-on: ${{matrix.os}}
@@ -338,7 +338,7 @@ jobs:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
- os: macos-11
runs-on: ${{matrix.os}}

View File

@@ -3,8 +3,6 @@
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
if(NOT DEFINED IDF_TARGET)
cmake_minimum_required(VERSION 3.5...3.20)
project(boost_container_hash VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
@@ -25,21 +23,3 @@ if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
else()
FILE(GLOB_RECURSE headers include/*.h include/*.hpp)
idf_component_register(
SRCS
${headers}
INCLUDE_DIRS
include
REQUIRES
boost_config
boost_type_traits
)
endif()

View File

@@ -17,9 +17,9 @@
#define BOOST_FUNCTIONAL_HASH_HASH_HPP
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/container_hash/detail/is_range.hpp>
#include <boost/container_hash/detail/is_contiguous_range.hpp>
#include <boost/container_hash/detail/is_unordered_range.hpp>
#include <boost/container_hash/is_range.hpp>
#include <boost/container_hash/is_contiguous_range.hpp>
#include <boost/container_hash/is_unordered_range.hpp>
#include <boost/container_hash/detail/hash_tuple.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_integral.hpp>
@@ -393,7 +393,7 @@ namespace boost
// ranges (list, set, deque...)
template <typename T>
typename boost::enable_if_<hash_detail::is_range<T>::value && !hash_detail::is_contiguous_range<T>::value && !hash_detail::is_unordered_range<T>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_range<T>::value && !container_hash::is_contiguous_range<T>::value && !container_hash::is_unordered_range<T>::value, std::size_t>::type
hash_value( T const& v )
{
return boost::hash_range( v.begin(), v.end() );
@@ -402,7 +402,7 @@ namespace boost
// contiguous ranges (string, vector, array)
template <typename T>
typename boost::enable_if_<hash_detail::is_contiguous_range<T>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_contiguous_range<T>::value, std::size_t>::type
hash_value( T const& v )
{
return boost::hash_range( v.data(), v.data() + v.size() );
@@ -411,18 +411,18 @@ namespace boost
// unordered ranges (unordered_set, unordered_map)
template <typename T>
typename boost::enable_if_<hash_detail::is_unordered_range<T>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_unordered_range<T>::value, std::size_t>::type
hash_value( T const& v )
{
return boost::hash_unordered_range( v.begin(), v.end() );
}
#if defined(BOOST_MSVC) && BOOST_MSVC >= 1910 && BOOST_MSVC < 1920 && BOOST_CXX_VERSION >= 201700L
#if defined(_MSVC_STL_VERSION) && _MSVC_STL_VERSION == 141 && BOOST_CXX_VERSION >= 201700L
// resolve ambiguity with unconstrained stdext::hash_value in <xhash> :-/
template<template<class...> class L, class... T>
typename boost::enable_if_<hash_detail::is_range<L<T...>>::value && !hash_detail::is_contiguous_range<L<T...>>::value && !hash_detail::is_unordered_range<L<T...>>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_range<L<T...>>::value && !container_hash::is_contiguous_range<L<T...>>::value && !container_hash::is_unordered_range<L<T...>>::value, std::size_t>::type
hash_value( L<T...> const& v )
{
return boost::hash_range( v.begin(), v.end() );
@@ -431,14 +431,14 @@ namespace boost
// contiguous ranges (string, vector, array)
template<template<class...> class L, class... T>
typename boost::enable_if_<hash_detail::is_contiguous_range<L<T...>>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_contiguous_range<L<T...>>::value, std::size_t>::type
hash_value( L<T...> const& v )
{
return boost::hash_range( v.data(), v.data() + v.size() );
}
template<template<class, std::size_t> class L, class T, std::size_t N>
typename boost::enable_if_<hash_detail::is_contiguous_range<L<T, N>>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_contiguous_range<L<T, N>>::value, std::size_t>::type
hash_value( L<T, N> const& v )
{
return boost::hash_range( v.data(), v.data() + v.size() );
@@ -447,7 +447,7 @@ namespace boost
// unordered ranges (unordered_set, unordered_map)
template<template<class...> class L, class... T>
typename boost::enable_if_<hash_detail::is_unordered_range<L<T...>>::value, std::size_t>::type
typename boost::enable_if_<container_hash::is_unordered_range<L<T...>>::value, std::size_t>::type
hash_value( L<T...> const& v )
{
return boost::hash_unordered_range( v.begin(), v.end() );
@@ -670,7 +670,7 @@ namespace boost
}
};
#if defined(BOOST_MSVC) && BOOST_MSVC >= 1910 && BOOST_MSVC < 1920 && BOOST_CXX_VERSION >= 201700L
#if defined(_MSVC_STL_VERSION) && _MSVC_STL_VERSION == 141 && BOOST_CXX_VERSION >= 201700L
// msvc-14.1 has stdext::hash_value for basic_string in <xhash> :-/

View File

@@ -10,15 +10,26 @@
namespace boost
{
template <class T> struct hash;
template <class T> void hash_combine(std::size_t& seed, T const& v);
namespace container_hash
{
template <class It> std::size_t hash_range(It, It);
template <class It> void hash_range(std::size_t&, It, It);
template<class T> struct is_range;
template<class T> struct is_contiguous_range;
template<class T> struct is_unordered_range;
template <class It> std::size_t hash_unordered_range(It, It);
template <class It> void hash_unordered_range(std::size_t&, It, It);
}
} // namespace container_hash
template<class T> struct hash;
template<class T> void hash_combine( std::size_t& seed, T const& v );
template<class It> std::size_t hash_range( It, It );
template<class It> void hash_range( std::size_t&, It, It );
template<class It> std::size_t hash_unordered_range( It, It );
template<class It> void hash_unordered_range( std::size_t&, It, It );
} // namespace boost
#endif // #ifndef BOOST_FUNCTIONAL_HASH_FWD_HPP

View File

@@ -2,8 +2,8 @@
// 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
#ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
#include <boost/config.hpp>
@@ -28,11 +28,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_( ... );
} // namespace hash_detail
namespace container_hash
{
template<class T> struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_<T>( 0 ) )
{
};
} // namespace hash_detail
} // namespace container_hash
} // namespace boost
#else // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
@@ -46,7 +51,7 @@ template<class T> struct is_contiguous_range: decltype( hash_detail::is_contiguo
namespace boost
{
namespace hash_detail
namespace container_hash
{
template<class T> struct is_contiguous_range: false_type
@@ -73,9 +78,9 @@ template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> co
#endif
} // namespace hash_detail
} // namespace container_hash
} // namespace boost
#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)
#endif // #ifndef BOOST_HASH_DETAIL_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#endif // #ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED

View File

@@ -2,8 +2,8 @@
// 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
#ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_RANGE_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_integral.hpp>
@@ -16,11 +16,11 @@
namespace boost
{
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
namespace hash_detail
{
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
template<class T, class It>
integral_constant< bool, !is_same<typename remove_cv<T>::type, typename std::iterator_traits<It>::value_type>::value >
is_range_check( It first, It last );
@@ -28,12 +28,22 @@ template<class T, class It>
template<class T> decltype( is_range_check<T>( 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 ) )
} // namespace hash_detail
namespace container_hash
{
template<class T> struct is_range: decltype( hash_detail::is_range_<T>( 0 ) )
{
};
} // namespace container_hash
#else
namespace hash_detail
{
template<class T, class E = true_type> struct is_range_: false_type
{
};
@@ -45,13 +55,19 @@ template<class T> struct is_range_< T, integral_constant< bool,
{
};
template<class T> struct is_range: is_range_<T>
} // namespace hash_detail
namespace container_hash
{
template<class T> struct is_range: hash_detail::is_range_<T>
{
};
} // namespace container_hash
#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
#endif // #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED

View File

@@ -2,10 +2,10 @@
// 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
#ifndef BOOST_HASH_IS_UNORDERED_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_UNORDERED_RANGE_HPP_INCLUDED
#include <boost/container_hash/detail/is_range.hpp>
#include <boost/container_hash/is_range.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_same.hpp>
@@ -24,11 +24,16 @@ template<class T> struct has_hasher_< T, integral_constant< bool,
{
};
template<class T> struct is_unordered_range: integral_constant< bool, is_range<T>::value && has_hasher_<T>::value >
} // namespace hash_detail
namespace container_hash
{
template<class T> struct is_unordered_range: integral_constant< bool, is_range<T>::value && hash_detail::has_hasher_<T>::value >
{
};
} // namespace hash_detail
} // namespace container_hash
} // namespace boost
#endif // #ifndef BOOST_HASH_DETAIL_IS_UNORDERED_RANGE_HPP_INCLUDED
#endif // #ifndef BOOST_HASH_IS_UNORDERED_RANGE_HPP_INCLUDED

View File

@@ -62,9 +62,9 @@ build-project ../examples ;
run hash_reference_values.cpp ;
run detail_is_range_test.cpp ;
run detail_is_contiguous_range_test.cpp ;
run detail_is_unordered_range_test.cpp ;
run is_range_test.cpp ;
run is_contiguous_range_test.cpp ;
run is_unordered_range_test.cpp ;
run hash_forward_list_test.cpp ;
@@ -78,6 +78,14 @@ run hash_string_test2.cpp ;
local fs-path-req = "-<toolset>gcc:<cxxflags>-Wshadow" "-<toolset>gcc:<cxxflags>-Wconversion" ;
run hash_fs_path_test.cpp /boost//filesystem/<warnings>off : : : $(fs-path-req) <toolset>msvc-14.0,<cxxstd>latest:<build>no ;
run detail_is_range_test2.cpp : : : $(fs-path-req) ;
run is_range_test2.cpp : : : $(fs-path-req) ;
run hash_container_test.cpp ;
run hash_vector_test2.cpp ;
run hash_string_test3.cpp ;
run hash_string_test4.cpp ;
run hash_multiset_test.cpp ;
run hash_multimap_test.cpp ;

View File

@@ -0,0 +1,46 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 8
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <map>
template<class T> void test()
{
typedef std::multimap<T, T> map;
typedef boost::hash<map> hash;
int const N = 32;
std::size_t h[ N ];
map v;
for( int i = 0; i < N; ++i )
{
h[ i ] = hash()( v );
BOOST_TEST_EQ( h[ i ], hash()( v ) );
for( int j = 0; j < i; ++j )
{
BOOST_TEST_NE( h[ j ], h[ i ] );
}
v.insert( std::pair<T const, T>() );
}
}
int main()
{
test<int>();
test<float>();
test<double>();
return boost::report_errors();
}

View File

@@ -0,0 +1,46 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 8
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <set>
template<class T> void test()
{
typedef std::multiset<T> set;
typedef boost::hash<set> hash;
int const N = 32;
std::size_t h[ N ];
set v;
for( int i = 0; i < N; ++i )
{
h[ i ] = hash()( v );
BOOST_TEST_EQ( h[ i ], hash()( v ) );
for( int j = 0; j < i; ++j )
{
BOOST_TEST_NE( h[ j ], h[ i ] );
}
v.insert( T() );
}
}
int main()
{
test<int>();
test<float>();
test<double>();
return boost::report_errors();
}

View File

@@ -0,0 +1,42 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
void test( unsigned char ch )
{
typedef boost::hash<std::string> hash;
int const N = 32;
std::size_t h[ N ];
std::string v;
for( int i = 0; i < N; ++i )
{
h[ i ] = hash()( v );
BOOST_TEST_EQ( h[ i ], hash()( v ) );
for( int j = 0; j < i; ++j )
{
BOOST_TEST_NE( h[ j ], h[ i ] );
}
v.push_back( static_cast<char>( ch ) );
}
}
int main()
{
for( unsigned ch = 0; ch < 256; ++ch )
{
test( static_cast<unsigned char>( ch ) );
}
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
#include <cstddef>
void test( std::size_t n, unsigned char ch )
{
typedef boost::hash<std::string> hash;
std::string const v( n, static_cast<char>( ch ) );
for( std::size_t i = 0; i < n * 8; ++i )
{
std::string w( v );
unsigned char ch2 = static_cast<unsigned char>( w[ i / 8 ] );
ch2 = static_cast<unsigned char>( ch2 ^ ( 1 << ( i % 8 ) ) );
w[ i / 8 ] = static_cast<char>( ch2 );
BOOST_TEST_NE( hash()( v ), hash()( w ) );
}
}
int main()
{
for( unsigned ch = 0; ch < 256; ++ch )
{
for( std::size_t n = 1; n < 32; ++n )
{
test( n, static_cast<unsigned char>( ch ) );
}
}
return boost::report_errors();
}

View File

@@ -0,0 +1,48 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__GNUC__) && __GNUC__ == 8
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <vector>
#include <functional> // to catch msvc-14.1 conflicts
template<class T> void test()
{
typedef std::vector<T> list;
typedef boost::hash<list> hash;
int const N = 32;
std::size_t h[ N ];
list v;
for( int i = 0; i < N; ++i )
{
h[ i ] = hash()( v );
BOOST_TEST_EQ( h[ i ], hash()( v ) );
for( int j = 0; j < i; ++j )
{
BOOST_TEST_NE( h[ j ], h[ i ] );
}
v.push_back( T() );
}
}
int main()
{
test<int>();
test<float>();
test<double>();
test< std::vector<int> >();
return boost::report_errors();
}

View File

@@ -2,7 +2,7 @@
// 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/container_hash/is_contiguous_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <string>
@@ -30,7 +30,7 @@ struct X
int main()
{
using boost::hash_detail::is_contiguous_range;
using boost::container_hash::is_contiguous_range;
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<void>));
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<void const>));

View File

@@ -2,7 +2,7 @@
// 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/container_hash/is_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <string>
@@ -30,7 +30,7 @@ struct X
int main()
{
using boost::hash_detail::is_range;
using boost::container_hash::is_range;
BOOST_TEST_TRAIT_FALSE((is_range<void>));
BOOST_TEST_TRAIT_FALSE((is_range<void const>));

View File

@@ -10,7 +10,7 @@
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/container_hash/detail/is_range.hpp>
#include <boost/container_hash/is_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <boost/filesystem/path.hpp>
@@ -21,7 +21,7 @@
int main()
{
using boost::hash_detail::is_range;
using boost::container_hash::is_range;
BOOST_TEST_TRAIT_FALSE((is_range< boost::filesystem::path >));
BOOST_TEST_TRAIT_FALSE((is_range< boost::filesystem::path const >));

View File

@@ -2,7 +2,7 @@
// 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/container_hash/is_unordered_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <string>
@@ -30,7 +30,7 @@ struct X
int main()
{
using boost::hash_detail::is_unordered_range;
using boost::container_hash::is_unordered_range;
BOOST_TEST_TRAIT_FALSE((is_unordered_range<void>));
BOOST_TEST_TRAIT_FALSE((is_unordered_range<void const>));