Compare commits

...

82 Commits

Author SHA1 Message Date
Peter Dimov
e62a268566 Update documentation 2023-04-05 17:34:08 +03:00
Peter Dimov
ad89c02360 Use link=static for /boost//filesystem under UBSan 2023-03-05 04:59:42 +02:00
Peter Dimov
64948e5f57 Update .drone.jsonnet 2023-03-05 04:21:10 +02:00
Peter Dimov
1958e96561 Add C++03 deprecation notice 2023-03-05 02:38:16 +02:00
Peter Dimov
4a7287d371 Update ci.yml 2023-03-02 21:12:54 +02:00
Peter Dimov
5638134081 Update notes.adoc 2023-03-02 19:45:18 +02:00
Peter Dimov
7c49f0bfb1 Document switch to mulxp1_hash 2023-02-15 20:44:10 +02:00
Peter Dimov
9ae5790657 Update ci.yml 2023-02-04 01:22:15 +02:00
Peter Dimov
8ce81c361d Fix /RTCc violations because Unordered tests with it 2023-02-03 20:57:47 +02:00
Peter Dimov
4315faf470 Update ci.yml 2023-02-02 14:54:38 +02:00
Peter Dimov
eb049e0cae Update .drone.jsonnet 2023-02-02 14:19:37 +02:00
Peter Dimov
6373656710 Avoid -Wlong-long under C++03 2023-02-02 07:29:03 +02:00
Peter Dimov
ec1503bbc8 Hardcode q*q to avoid 'integral constant overflow' warnings 2023-02-02 06:15:01 +02:00
Peter Dimov
ee064dc7f8 Avoid -Wconversion warnings 2023-02-02 06:11:47 +02:00
Peter Dimov
b505e06b3c Update 64 bit reference values to reflect the change to mulxp1_hash 2023-02-02 06:06:36 +02:00
Peter Dimov
6075f3e1f5 Change 64 bit hash_range for char[] to mulxp1_hash 2023-02-02 06:00:00 +02:00
Peter Dimov
0bfeabfd63 Hardcode q*q to avoid 'integral constant overflow' warnings 2023-02-02 05:20:06 +02:00
Peter Dimov
758596533d Temporarily update 64 bit reference values to match mulxp1_hash32 2023-02-02 04:58:15 +02:00
Peter Dimov
640bd48f51 Avoid -Wconversion warning for p[x1] 2023-02-02 04:54:10 +02:00
Peter Dimov
b25fd745ca Update 32 bit reference values to reflect the change to mulxp1_hash32 2023-02-02 04:52:42 +02:00
Peter Dimov
6fe3469a8b Replace hash_range for char[] with mulxp1_hash32 2023-02-02 04:42:42 +02:00
Peter Dimov
c07630ac60 Add read32le to detail/hash_range.hpp 2023-02-02 04:09:54 +02:00
Peter Dimov
45270ae11e Update benchmark/unordered.cpp 2022-12-12 21:08:00 +02:00
Peter Dimov
5bef4901b9 Add a pointer overload for detail::hash_range under msvc 2022-12-09 21:12:30 +02:00
Peter Dimov
d724bcd0ef Update benchmark/.gitignore 2022-12-09 20:54:04 +02:00
Peter Dimov
ceb8303601 Add mulxp1_hash32 to benchmarks 2022-12-08 17:57:00 +02:00
Peter Dimov
cf87e304f6 Remove mul31, mulxp0, mulxp2 from the unordered_flat and word_count benchmarks 2022-12-01 18:53:34 +02:00
Peter Dimov
4d9f7b8931 Add ankerl::unordered_dense::hash to benchmarks 2022-12-01 02:22:07 +02:00
Peter Dimov
2f4efbced4 Document support for nullptr and tuple-like types 2022-11-29 02:00:06 +02:00
Peter Dimov
bf7a78594e Add a test with a tuple-like described struct 2022-11-28 18:46:13 +02:00
Peter Dimov
c0c70e5b3e Add support for tuple-like types. Refs #30. 2022-11-28 16:59:35 +02:00
Peter Dimov
891a64d45d Add is_tuple_like to hash_fwd.hpp 2022-11-28 15:55:25 +02:00
Peter Dimov
08d69c31b1 Merge branch 'develop' into feature/is_tuple_like 2022-11-28 15:50:36 +02:00
Peter Dimov
6526b24900 Add hash_integral_test2.cpp 2022-11-28 14:20:44 +02:00
Peter Dimov
1a8dca4f2c Disable is_tuple_like for msvc-12.0 and earlier 2022-11-28 05:15:06 +02:00
Peter Dimov
8761157a19 Merge branch 'develop' into feature/is_tuple_like 2022-11-28 03:13:35 +02:00
Peter Dimov
f2b2ef4ebe Avoid warning 4100 under early MSVC 2022-11-28 01:59:32 +02:00
Peter Dimov
30560ada18 Disable -Wmismatched-tags under Clang 2022-11-28 00:57:19 +02:00
Peter Dimov
c61a4f691e Add boost::container_hash::is_tuple_like. Refs #30. 2022-11-27 21:20:19 +02:00
Peter Dimov
fe28cdbd1f Add boost::hash_value for std::nullptr_t. Refs #29. 2022-11-27 20:13:52 +02:00
Peter Dimov
f98b943585 Add benchmark/.gitignore 2022-11-27 19:39:38 +02:00
Peter Dimov
4aeb7b2285 Update benchmark/unordered_flat.cpp 2022-11-27 06:47:54 +02:00
Peter Dimov
e310932a9c Add mulxp3_hash32 to benchmarks 2022-11-27 02:43:20 +02:00
Peter Dimov
558d0ead17 Suppress std::complex<int> warning under clang-cl 2022-11-25 21:13:57 +02:00
Peter Dimov
d6905ab159 Add benchmark/word_count.cpp 2022-11-25 20:52:56 +02:00
Peter Dimov
251894540d Split mul31_unrolled_hash into mul31_x4_hash and mul31_x8_hash in benchmarks 2022-11-25 20:52:30 +02:00
Peter Dimov
ffadafa0c1 Remove old_boost_hash from benchmarks 2022-11-25 20:27:20 +02:00
Peter Dimov
ce166d1030 Add mulxp_hash to benchmark/unordered.cpp 2022-11-25 20:24:59 +02:00
Peter Dimov
8ab83c1cd4 Add mulxp_hash to benchmark/unordered_flat.cpp 2022-11-25 20:24:38 +02:00
Peter Dimov
16546190f6 Add benchmark/unordered_flat.cpp 2022-11-19 03:19:34 +02:00
Peter Dimov
5e26a3b807 Add absl::Hash to benchmark/unordered.cpp 2022-11-18 17:37:09 +02:00
Peter Dimov
bd5b7a359c Update ci.yml 2022-11-03 14:19:56 +02:00
Peter Dimov
f5f5476dcc <boost/unordered/hash_traits.hpp> no longer requires C++11 2022-11-01 02:35:51 +02:00
Peter Dimov
228f7db5d3 Add examples/point2.cpp 2022-10-30 17:51:31 +02:00
Peter Dimov
f50b914456 Update documentation 2022-10-30 17:23:39 +02:00
Peter Dimov
c134ca39e9 Update test/CMakeLists.txt 2022-10-30 03:05:20 +02:00
Peter Dimov
f51f68fe93 Do not use the u8string and u8string_view typedefs, because char8_t availability does not guarantee their presence 2022-10-30 03:01:05 +02:00
Peter Dimov
0865c1d230 Disable hash_is_avalanching tests when BOOST_NO_CXX11_TEMPLATE_ALIASES is defined, because hash_traits.hpp uses void_t 2022-10-30 03:54:24 +03:00
Peter Dimov
0d2266decb Specialize boost::unordered::hash_is_avalanching for hash<string> and hash<string_view> 2022-10-30 02:47:10 +03:00
Peter Dimov
3c9ba89cf2 Update .drone.jsonnet 2022-10-28 21:21:44 +03:00
Peter Dimov
20ee3b60fd Update CMakeLists.txt 2022-10-28 21:18:10 +03:00
Peter Dimov
bdd3dcf944 Disable -Wunused-private-field in described_class_test.cpp 2022-10-28 20:04:13 +03:00
Peter Dimov
018fc4e1fa Add support for described classes to hash.hpp 2022-10-28 19:35:10 +03:00
Peter Dimov
7568176bfa is_described_class should be false for unions 2022-10-28 18:42:07 +03:00
Peter Dimov
08864cd1e9 Update cmake_subdir_test/CMakeLists.txt 2022-10-28 14:56:57 +03:00
Peter Dimov
5a616b9b54 Update CMakeLists.txt 2022-10-28 07:07:48 +03:00
Peter Dimov
16fb4cc749 Add is_described_class to hash_fwd.hpp; include it in hash.hpp 2022-10-28 03:32:18 +03:00
Peter Dimov
0171246a61 Add is_described_class<T> 2022-10-28 01:47:27 +03:00
Peter Dimov
29c85559e4 Update .drone.jsonnet 2022-10-27 02:44:38 +03:00
Peter Dimov
412bd51449 Avoid -Wunused-but-set-variable under Clang 15 2022-10-27 02:12:43 +03:00
Peter Dimov
87196a503e Update .drone.jsonnet 2022-10-27 01:16:34 +03:00
Peter Dimov
df1671d593 msvc-14.0 doesn't quite have expression SFINAE. Fixes #28. 2022-10-26 19:38:53 +03:00
Peter Dimov
1996cf36c1 Update ci.yml 2022-10-26 19:32:22 +03:00
Peter Dimov
a4b2048a29 Add is_contiguous_range_test3 (refs #28) 2022-10-26 19:13:27 +03:00
Peter Dimov
85f9f8a97a Update documentation 2022-09-20 21:20:31 +03:00
Peter Dimov
e92eae9eb2 Treat char8_t and std::byte as char types in hash_range 2022-09-20 21:17:41 +03:00
Peter Dimov
8a1335458a Update Acknowledgements section 2022-09-20 21:09:17 +03:00
Peter Dimov
f7e537d1a1 Update Notes section 2022-09-20 21:06:09 +03:00
Peter Dimov
607b73f1e0 Add README.md 2022-09-20 16:08:10 +03:00
Peter Dimov
789261c68c Update 32 bit float reference values (for GCC) 2022-09-20 15:23:13 +03:00
Peter Dimov
29ee19ee7f Update 32 bit float reference values (for MSVC) 2022-09-20 15:08:21 +03:00
Peter Dimov
8bb7d43646 Simplify hash_value for floating point 2022-09-20 15:01:45 +03:00
52 changed files with 3195 additions and 445 deletions

View File

@@ -135,55 +135,230 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
),
linux_pipeline(
"Linux 20.04 GCC 9 ARM64",
"Linux 16.04 GCC 5* 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 18.04 GCC 6 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14', ADDRMD: '32,64' },
"g++-6-multilib",
),
linux_pipeline(
"Linux 18.04 GCC 7* 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 18.04 GCC 8 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
"g++-8-multilib",
),
linux_pipeline(
"Linux 20.04 GCC 9* 32/64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 20.04 GCC 9* ARM64",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 9 S390x",
"Linux 20.04 GCC 9* S390x",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="s390x",
),
linux_pipeline(
"Linux 20.04 GCC 10 32/64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32,64' },
"g++-10-multilib",
),
linux_pipeline(
"Linux 22.04 GCC 11* 32/64",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 22.04 GCC 12 32 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20', ADDRMD: '32' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 22.04 GCC 12 64 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20', ADDRMD: '64' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 22.04 Clang 14 UBSAN",
"Linux 16.04 Clang 3.5",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11' },
"clang-3.5",
),
linux_pipeline(
"Linux 16.04 Clang 3.6",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' },
"clang-3.6",
),
linux_pipeline(
"Linux 16.04 Clang 3.7",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' },
"clang-3.7",
),
linux_pipeline(
"Linux 16.04 Clang 3.8",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' },
"clang-3.8",
),
linux_pipeline(
"Linux 18.04 Clang 3.9",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '03,11,14' },
"clang-3.9",
),
linux_pipeline(
"Linux 18.04 Clang 4.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '03,11,14' },
"clang-4.0",
),
linux_pipeline(
"Linux 18.04 Clang 5.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '03,11,14,1z' },
"clang-5.0",
),
linux_pipeline(
"Linux 18.04 Clang 6.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '03,11,14,17' },
"clang-6.0",
),
linux_pipeline(
"Linux 20.04 Clang 7",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '03,11,14,17' },
"clang-7",
),
linux_pipeline(
"Linux 20.04 Clang 8",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '03,11,14,17' },
"clang-8",
),
linux_pipeline(
"Linux 20.04 Clang 9",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '03,11,14,17,2a' },
"clang-9",
),
linux_pipeline(
"Linux 20.04 Clang 10",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '03,11,14,17,2a' },
"clang-10",
),
linux_pipeline(
"Linux 20.04 Clang 11",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '03,11,14,17,2a' },
"clang-11",
),
linux_pipeline(
"Linux 20.04 Clang 12",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '03,11,14,17,2a' },
"clang-12",
),
linux_pipeline(
"Linux 22.04 Clang 13",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + ubsan,
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20,2b' },
"clang-13",
),
linux_pipeline(
"Linux 22.04 Clang 14",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20,2b' },
"clang-14",
),
linux_pipeline(
"Linux 22.04 Clang 14 ASAN",
"Linux 22.04 Clang 15 UBSAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + asan,
"clang-14",
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' } + ubsan,
"clang-15",
),
linux_pipeline(
"Linux 22.04 Clang 15 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' } + asan,
"clang-15",
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan,
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,2a' } + ubsan,
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 ASAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan,
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,2a' } + asan,
),
macos_pipeline(
"MacOS 12.4 Xcode 13.4.1 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,20,2b' } + ubsan,
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
),
macos_pipeline(
"MacOS 12.4 Xcode 13.4.1 ASAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,17,20,2b' } + asan,
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
),
windows_pipeline(
"Windows VS2015 msvc-14.0",
"cppalliance/dronevs2015",
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest' },
),
windows_pipeline(
@@ -191,4 +366,16 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
"cppalliance/dronevs2017",
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
),
windows_pipeline(
"Windows VS2019 msvc-14.2",
"cppalliance/dronevs2019",
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
),
]

View File

@@ -5,6 +5,7 @@
# https://www.boost.org/LICENSE_1_0.txt
set -ex
export PATH=~/.local/bin:/usr/local/bin:$PATH
DRONE_BUILD_DIR=$(pwd)

View File

@@ -19,27 +19,30 @@ jobs:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8-multilib
address-model: 32,64
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5-multilib
address-model: 32,64
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6-multilib
address-model: 32,64
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-7-multilib
address-model: 32,64
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-8-multilib
address-model: 32,64
- toolset: gcc-9
@@ -58,34 +61,37 @@ jobs:
install: g++-11-multilib
address-model: 32,64
- toolset: gcc-12
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12-multilib
address-model: 32,64
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
@@ -111,26 +117,45 @@ jobs:
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-15
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-11
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
os: macos-12
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python git g++
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -195,7 +220,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -231,19 +256,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -278,19 +303,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -335,19 +360,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |

View File

@@ -15,6 +15,8 @@ target_include_directories(boost_container_hash INTERFACE include)
target_link_libraries(boost_container_hash
INTERFACE
Boost::config
Boost::describe
Boost::mp11
Boost::type_traits
)

20
README.md Normal file
View File

@@ -0,0 +1,20 @@
# Boost.ContainerHash
The Boost.ContainerHash library, part of [Boost C++ Libraries](https://boost.org),
provides `boost::hash`, an enhanced implementation of the
[hash function](https://en.wikipedia.org/wiki/Hash_function) object specified
by C++11 as `std::hash`, and several support facilities (`hash_combine`,
`hash_range`, `hash_unordered_range`).
`boost::hash` supports most standard types and some user-defined types out of
the box, and is extensible; it's possible for a user-defined type `X` to make
iself hashable via `boost::hash<X>` by defining an appropriate overload of the
function `hash_value`.
See [the documentation of the library](https://www.boost.org/libs/container_hash)
for more information.
## License
Distributed under the
[Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).

4
benchmark/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
enwik8
enwik9
*.exe
*.obj

View File

@@ -3,12 +3,22 @@
// https://www.boost.org/LICENSE_1_0.txt
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX20_CISO646_REMOVED_WARNING
#include <boost/container_hash/hash.hpp>
#include <boost/unordered_set.hpp>
#include <boost/core/detail/splitmix64.hpp>
#include <boost/core/type_name.hpp>
#include <boost/config.hpp>
#ifdef HAVE_ABSEIL
# include "absl/hash/hash.h"
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
# include "ankerl/unordered_dense.h"
#endif
#ifdef HAVE_MULXP_HASH
# include "mulxp_hash.hpp"
#endif
#include <cstddef>
#include <cstdio>
#include <cstdint>
@@ -19,10 +29,8 @@
// mul31_hash
class mul31_hash
struct mul31_hash
{
public:
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
char const * p = st.data();
@@ -43,18 +51,20 @@ public:
}
};
// mul31_unrolled_hash
// mul31_x4_hash
template<int Bits> struct mul31_unrolled_hash_impl;
template<> struct mul31_unrolled_hash_impl<32>
struct mul31_x4_hash
{
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
char const * p = st.data();
std::size_t n = st.size();
#if SIZE_MAX > UINT32_MAX
std::size_t h = 0xCBF29CE484222325ull;
#else
std::size_t h = 0x811C9DC5u;
#endif
while( n >= 4 )
{
@@ -80,14 +90,20 @@ template<> struct mul31_unrolled_hash_impl<32>
}
};
template<> struct mul31_unrolled_hash_impl<64>
// mul31_x8_hash
struct mul31_x8_hash
{
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
char const * p = st.data();
std::size_t n = st.size();
std::size_t h = 0xCBF29CE484222325ull;
#if SIZE_MAX > UINT32_MAX
boost::uint64_t h = 0xCBF29CE484222325ull;
#else
boost::uint64_t h = 0x811C9DC5u;
#endif
while( n >= 8 )
{
@@ -113,12 +129,10 @@ template<> struct mul31_unrolled_hash_impl<64>
--n;
}
return h;
return static_cast<std::size_t>( h );
}
};
struct mul31_unrolled_hash: mul31_unrolled_hash_impl< std::numeric_limits<std::size_t>::digits > {};
// fnv1a_hash
template<int Bits> struct fnv1a_hash_impl;
@@ -163,28 +177,44 @@ template<> struct fnv1a_hash_impl<64>
struct fnv1a_hash: fnv1a_hash_impl< std::numeric_limits<std::size_t>::digits > {};
// old_boost_hash
// mulxp_hash
class old_boost_hash
#ifdef HAVE_MULXP_HASH
struct mulxp1_hash_
{
public:
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
char const * p = st.data();
std::size_t n = st.size();
std::size_t h = 0;
for( std::size_t i = 0; i < n; ++i )
{
h ^= static_cast<unsigned char>( p[i] ) + 0x9e3779b9 + ( h << 6 ) + ( h >> 2 );
}
return h;
return mulxp1_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp3_hash_
{
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
return mulxp3_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp1_hash32_
{
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
return mulxp1_hash32( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp3_hash32_
{
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
return mulxp3_hash32( (unsigned char const*)st.data(), st.size(), 0 );
}
};
#endif
// test_hash_speed
template<class H, class V> void test_hash_speed( int N, V const& v )
@@ -210,11 +240,11 @@ template<class H, class V> void test_hash_speed( int N, V const& v )
#if defined( _MSC_VER )
std::printf( "%25s : q=%20Iu, %lld ms\n", hash.c_str(), q, ms1 );
std::printf( "%57s : q=%20Iu, %lld ms\n", hash.c_str(), q, ms1 );
#else
std::printf( "%25s : q=%20zu, %lld ms\n", hash.c_str(), q, ms1 );
std::printf( "%57s : q=%20zu, %lld ms\n", hash.c_str(), q, ms1 );
#endif
}
@@ -235,11 +265,11 @@ template<class H, class V> void test_hash_collision( int N, V const& v, std::siz
#if defined( _MSC_VER )
std::printf( "%25s : c=%Iu\n", hash.c_str(), n - s.size() );
std::printf( "%57s : c=%Iu\n", hash.c_str(), n - s.size() );
#else
std::printf( "%25s : c=%zu\n", hash.c_str(), n - s.size() );
std::printf( "%57s : c=%zu\n", hash.c_str(), n - s.size() );
#endif
}
@@ -292,11 +322,11 @@ template<class V, class S> void test4( int N, V const& v, char const * hash, S s
#if defined( _MSC_VER )
std::printf( "%25s : n=%Iu, m=%Iu, c=%Iu, q=%Iu, %lld + %lld ms\n", hash, n, m, c, q, ms1, ms2 );
std::printf( "%57s : n=%Iu, m=%Iu, c=%Iu, q=%Iu, %4lld + %4lld = %4lld ms\n", hash, n, m, c, q, ms1, ms2, ms1 + ms2 );
#else
std::printf( "%25s : n=%zu, m=%zu, c=%zu, q=%zu, %lld + %lld ms\n", hash, n, m, c, q, ms1, ms2 );
std::printf( "%57s : n=%zu, m=%zu, c=%zu, q=%zu, %4lld + %4lld = %4lld ms\n", hash, n, m, c, q, ms1, ms2, ms1 + ms2 );
#endif
}
@@ -340,11 +370,23 @@ int main()
std::puts( "Hash speed test:\n" );
test_hash_speed<mul31_hash>( N * 16, v );
test_hash_speed<mul31_unrolled_hash>( N * 16, v );
test_hash_speed<mul31_x4_hash>( N * 16, v );
test_hash_speed<mul31_x8_hash>( N * 16, v );
test_hash_speed<fnv1a_hash>( N * 16, v );
test_hash_speed<old_boost_hash>( N * 16, v );
test_hash_speed<boost::hash<std::string> >( N * 16, v );
test_hash_speed<std::hash<std::string> >( N * 16, v );
#ifdef HAVE_ABSEIL
test_hash_speed<absl::Hash<std::string> >( N * 16, v );
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
test_hash_speed<ankerl::unordered_dense::hash<std::string> >( N * 16, v );
#endif
#ifdef HAVE_MULXP_HASH
test_hash_speed<mulxp1_hash_>( N * 16, v );
test_hash_speed<mulxp3_hash_>( N * 16, v );
test_hash_speed<mulxp1_hash32_>( N * 16, v );
test_hash_speed<mulxp3_hash32_>( N * 16, v );
#endif
std::puts( "" );
@@ -365,25 +407,55 @@ int main()
}
test_hash_collision<mul31_hash>( N * 16, v, n );
test_hash_collision<mul31_unrolled_hash>( N * 16, v, n );
test_hash_collision<mul31_x4_hash>( N * 16, v, n );
test_hash_collision<mul31_x8_hash>( N * 16, v, n );
test_hash_collision<fnv1a_hash>( N * 16, v, n );
test_hash_collision<old_boost_hash>( N * 16, v, n );
test_hash_collision<boost::hash<std::string> >( N * 16, v, n );
test_hash_collision<std::hash<std::string> >( N * 16, v, n );
#ifdef HAVE_ABSEIL
test_hash_collision<absl::Hash<std::string> >( N * 16, v, n );
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
test_hash_collision<ankerl::unordered_dense::hash<std::string> >( N * 16, v, n );
#endif
#ifdef HAVE_MULXP_HASH
test_hash_collision<mulxp1_hash_>( N * 16, v, n );
test_hash_collision<mulxp3_hash_>( N * 16, v, n );
test_hash_collision<mulxp1_hash32_>( N * 16, v, n );
test_hash_collision<mulxp3_hash32_>( N * 16, v, n );
#endif
}
std::puts( "" );
typedef std::string K;
std::puts( "Container speed test:\n" );
std::puts( "Container speed test:\n---\n" );
test_container_speed<K, mul31_hash>( N, v );
test_container_speed<K, mul31_unrolled_hash>( N, v );
test_container_speed<K, mul31_x4_hash>( N, v );
test_container_speed<K, mul31_x8_hash>( N, v );
test_container_speed<K, fnv1a_hash>( N, v );
test_container_speed<K, old_boost_hash>( N, v );
test_container_speed<K, boost::hash<std::string> >( N, v );
test_container_speed<K, std::hash<std::string> >( N, v );
#ifdef HAVE_ABSEIL
test_container_speed<K, absl::Hash<std::string> >( N, v );
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
test_container_speed<K, ankerl::unordered_dense::hash<std::string> >( N, v );
#endif
#ifdef HAVE_MULXP_HASH
test_container_speed<K, mulxp1_hash_>( N, v );
test_container_speed<K, mulxp3_hash_>( N, v );
test_container_speed<K, mulxp1_hash32_>( N, v );
test_container_speed<K, mulxp3_hash32_>( N, v );
#endif
std::puts( "" );
}
#ifdef HAVE_ABSEIL
# include "absl/hash/internal/hash.cc"
# include "absl/hash/internal/low_level_hash.cc"
# include "absl/hash/internal/city.cc"
#endif

View File

@@ -0,0 +1,386 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING
#define _SILENCE_CXX20_CISO646_REMOVED_WARNING
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/core/detail/splitmix64.hpp>
#include <boost/config.hpp>
#ifdef HAVE_ABSEIL
# include "absl/hash/hash.h"
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
# include "ankerl/unordered_dense.h"
#endif
#ifdef HAVE_MULXP_HASH
# include "mulxp_hash.hpp"
#endif
#include <vector>
#include <memory>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <chrono>
using namespace std::chrono_literals;
static void print_time( std::chrono::steady_clock::time_point & t1, char const* label, std::uint32_t s, std::size_t size )
{
auto t2 = std::chrono::steady_clock::now();
std::cout << label << ": " << ( t2 - t1 ) / 1ms << " ms (s=" << s << ", size=" << size << ")\n";
t1 = t2;
}
constexpr unsigned N = 2'000'000;
constexpr int K = 10;
static std::vector<std::string> indices1, indices2;
static std::string make_index( unsigned x )
{
char buffer[ 64 ];
std::snprintf( buffer, sizeof(buffer), "pfx_%u_sfx", x );
return buffer;
}
static std::string make_random_index( unsigned x )
{
char buffer[ 64 ];
std::snprintf( buffer, sizeof(buffer), "pfx_%0*d_%u_sfx", x % 8 + 1, 0, x );
return buffer;
}
static void init_indices()
{
indices1.reserve( N*2+1 );
indices1.push_back( make_index( 0 ) );
for( unsigned i = 1; i <= N*2; ++i )
{
indices1.push_back( make_index( i ) );
}
indices2.reserve( N*2+1 );
indices2.push_back( make_index( 0 ) );
{
boost::detail::splitmix64 rng;
for( unsigned i = 1; i <= N*2; ++i )
{
indices2.push_back( make_random_index( static_cast<std::uint32_t>( rng() ) ) );
}
}
}
template<class Map> BOOST_NOINLINE void test_insert( Map& map, std::chrono::steady_clock::time_point & t1 )
{
for( unsigned i = 1; i <= N; ++i )
{
map.insert( { indices1[ i ], i } );
}
print_time( t1, "Consecutive insert", 0, map.size() );
for( unsigned i = 1; i <= N; ++i )
{
map.insert( { indices2[ i ], i } );
}
print_time( t1, "Random insert", 0, map.size() );
std::cout << std::endl;
}
template<class Map> BOOST_NOINLINE void test_lookup( Map& map, std::chrono::steady_clock::time_point & t1 )
{
std::uint32_t s;
s = 0;
for( int j = 0; j < K; ++j )
{
for( unsigned i = 1; i <= N * 2; ++i )
{
auto it = map.find( indices1[ i ] );
if( it != map.end() ) s += it->second;
}
}
print_time( t1, "Consecutive lookup", s, map.size() );
s = 0;
for( int j = 0; j < K; ++j )
{
for( unsigned i = 1; i <= N * 2; ++i )
{
auto it = map.find( indices2[ i ] );
if( it != map.end() ) s += it->second;
}
}
print_time( t1, "Random lookup", s, map.size() );
std::cout << std::endl;
}
template<class Map> BOOST_NOINLINE void test_iteration( Map& map, std::chrono::steady_clock::time_point & t1 )
{
auto it = map.begin();
while( it != map.end() )
{
if( it->second & 1 )
{
if constexpr( std::is_void_v< decltype( map.erase( it ) ) > )
{
map.erase( it++ );
}
else
{
it = map.erase( it );
}
}
else
{
++it;
}
}
print_time( t1, "Iterate and erase odd elements", 0, map.size() );
std::cout << std::endl;
}
template<class Map> BOOST_NOINLINE void test_erase( Map& map, std::chrono::steady_clock::time_point & t1 )
{
for( unsigned i = 1; i <= N; ++i )
{
map.erase( indices1[ i ] );
}
print_time( t1, "Consecutive erase", 0, map.size() );
for( unsigned i = 1; i <= N; ++i )
{
map.erase( indices2[ i ] );
}
print_time( t1, "Random erase", 0, map.size() );
std::cout << std::endl;
}
//
struct record
{
std::string label_;
long long time_;
};
static std::vector<record> times;
template<class Hash> BOOST_NOINLINE void test( char const* label )
{
std::cout << label << ":\n\n";
boost::unordered_flat_map<std::string, std::uint32_t, Hash> map;
auto t0 = std::chrono::steady_clock::now();
auto t1 = t0;
test_insert( map, t1 );
record rec = { label, 0 };
test_lookup( map, t1 );
test_iteration( map, t1 );
test_lookup( map, t1 );
test_erase( map, t1 );
auto tN = std::chrono::steady_clock::now();
std::cout << "Total: " << ( tN - t0 ) / 1ms << " ms\n\n";
rec.time_ = ( tN - t0 ) / 1ms;
times.push_back( rec );
}
// fnv1a_hash
template<int Bits> struct fnv1a_hash_impl;
template<> struct fnv1a_hash_impl<32>
{
std::size_t operator()( std::string const& s ) const
{
std::size_t h = 0x811C9DC5u;
char const * first = s.data();
char const * last = first + s.size();
for( ; first != last; ++first )
{
h ^= static_cast<unsigned char>( *first );
h *= 0x01000193ul;
}
return h;
}
};
template<> struct fnv1a_hash_impl<64>
{
std::size_t operator()( std::string const& s ) const
{
std::size_t h = 0xCBF29CE484222325ull;
char const * first = s.data();
char const * last = first + s.size();
for( ; first != last; ++first )
{
h ^= static_cast<unsigned char>( *first );
h *= 0x00000100000001B3ull;
}
return h;
}
};
struct fnv1a_hash: fnv1a_hash_impl< std::numeric_limits<std::size_t>::digits >
{
using is_avalanching = void;
};
// std_hash
struct std_hash: std::hash<std::string>
{
using is_avalanching = void;
};
// absl_hash
#ifdef HAVE_ABSEIL
struct absl_hash: absl::Hash<std::string>
{
using is_avalanching = void;
};
#endif
// mulxp_hash
#ifdef HAVE_MULXP_HASH
struct mulxp1_hash_
{
using is_avalanching = void;
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
return mulxp1_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp3_hash_
{
using is_avalanching = void;
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
return mulxp3_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp1_hash32_
{
using is_avalanching = void;
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
std::size_t r = mulxp1_hash32( (unsigned char const*)st.data(), st.size(), 0 );
#if SIZE_MAX > UINT32_MAX
r |= r << 32;
#endif
return r;
}
};
struct mulxp3_hash32_
{
using is_avalanching = void;
std::size_t operator()( std::string const& st ) const BOOST_NOEXCEPT
{
std::size_t r = mulxp3_hash32( (unsigned char const*)st.data(), st.size(), 0 );
#if SIZE_MAX > UINT32_MAX
r |= r << 32;
#endif
return r;
}
};
#endif
//
int main()
{
init_indices();
test< boost::hash<std::string> >( "boost::hash" );
test< std_hash >( "std::hash" );
test< fnv1a_hash >( "fnv1a_hash" );
#ifdef HAVE_ABSEIL
test< absl_hash >( "absl::Hash" );
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
test< ankerl::unordered_dense::hash<std::string> >( "ankerl::unordered_dense::hash" );
#endif
#ifdef HAVE_MULXP_HASH
test< mulxp1_hash_ >( "mulxp1_hash" );
test< mulxp3_hash_ >( "mulxp3_hash" );
test< mulxp1_hash32_ >( "mulxp1_hash32" );
test< mulxp3_hash32_ >( "mulxp3_hash32" );
#endif
std::cout << "---\n\n";
for( auto const& x: times )
{
std::cout << std::setw( 32 ) << ( x.label_ + ": " ) << std::setw( 5 ) << x.time_ << " ms\n";
}
}
#ifdef HAVE_ABSEIL
# include "absl/hash/internal/hash.cc"
# include "absl/hash/internal/low_level_hash.cc"
# include "absl/hash/internal/city.cc"
#endif

319
benchmark/word_count.cpp Normal file
View File

@@ -0,0 +1,319 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING
#define _SILENCE_CXX20_CISO646_REMOVED_WARNING
#include <boost/unordered/unordered_flat_map.hpp>
#ifdef HAVE_ABSEIL
# include "absl/hash/hash.h"
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
# include "ankerl/unordered_dense.h"
#endif
#ifdef HAVE_MULXP_HASH
# include "mulxp_hash.hpp"
#endif
#include <boost/regex.hpp>
#include <vector>
#include <memory>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <fstream>
#include <string_view>
#include <string>
using namespace std::chrono_literals;
static void print_time( std::chrono::steady_clock::time_point & t1, char const* label, std::uint32_t s, std::size_t size )
{
auto t2 = std::chrono::steady_clock::now();
std::cout << label << ": " << ( t2 - t1 ) / 1ms << " ms (s=" << s << ", size=" << size << ")\n";
t1 = t2;
}
static std::vector<std::string> words;
static void init_words()
{
#if SIZE_MAX > UINT32_MAX
char const* fn = "enwik9"; // http://mattmahoney.net/dc/textdata
#else
char const* fn = "enwik8"; // ditto
#endif
auto t1 = std::chrono::steady_clock::now();
std::ifstream is( fn );
std::string in( std::istreambuf_iterator<char>( is ), std::istreambuf_iterator<char>{} );
boost::regex re( "[a-zA-Z]+");
boost::sregex_token_iterator it( in.begin(), in.end(), re, 0 ), end;
words.assign( it, end );
auto t2 = std::chrono::steady_clock::now();
std::cout << fn << ": " << words.size() << " words, " << ( t2 - t1 ) / 1ms << " ms\n\n";
}
template<class Map> BOOST_NOINLINE void test_word_count( Map& map, std::chrono::steady_clock::time_point & t1 )
{
std::size_t s = 0;
for( auto const& word: words )
{
++map[ word ];
++s;
}
print_time( t1, "Word count", s, map.size() );
std::cout << std::endl;
}
template<class Map> BOOST_NOINLINE void test_contains( Map& map, std::chrono::steady_clock::time_point & t1 )
{
std::size_t s = 0;
for( auto const& word: words )
{
std::string_view w2( word );
w2.remove_prefix( 1 );
s += map.contains( w2 );
}
print_time( t1, "Contains", s, map.size() );
std::cout << std::endl;
}
template<class Map> BOOST_NOINLINE void test_count( Map& map, std::chrono::steady_clock::time_point & t1 )
{
std::size_t s = 0;
for( auto const& word: words )
{
std::string_view w2( word );
w2.remove_prefix( 1 );
s += map.count( w2 );
}
print_time( t1, "Count", s, map.size() );
std::cout << std::endl;
}
//
struct record
{
std::string label_;
long long time_;
};
static std::vector<record> times;
template<class Hash> BOOST_NOINLINE void test( char const* label )
{
std::cout << label << ":\n\n";
boost::unordered_flat_map<std::string_view, std::size_t, Hash> map;
auto t0 = std::chrono::steady_clock::now();
auto t1 = t0;
test_word_count( map, t1 );
record rec = { label, 0 };
test_contains( map, t1 );
test_count( map, t1 );
auto tN = std::chrono::steady_clock::now();
std::cout << "Total: " << ( tN - t0 ) / 1ms << " ms\n\n";
rec.time_ = ( tN - t0 ) / 1ms;
times.push_back( rec );
}
// fnv1a_hash
template<int Bits> struct fnv1a_hash_impl;
template<> struct fnv1a_hash_impl<32>
{
std::size_t operator()( std::string_view const& s ) const
{
std::size_t h = 0x811C9DC5u;
char const * first = s.data();
char const * last = first + s.size();
for( ; first != last; ++first )
{
h ^= static_cast<unsigned char>( *first );
h *= 0x01000193ul;
}
return h;
}
};
template<> struct fnv1a_hash_impl<64>
{
std::size_t operator()( std::string_view const& s ) const
{
std::size_t h = 0xCBF29CE484222325ull;
char const * first = s.data();
char const * last = first + s.size();
for( ; first != last; ++first )
{
h ^= static_cast<unsigned char>( *first );
h *= 0x00000100000001B3ull;
}
return h;
}
};
struct fnv1a_hash: fnv1a_hash_impl< std::numeric_limits<std::size_t>::digits >
{
using is_avalanching = void;
};
// std_hash
struct std_hash: std::hash<std::string_view>
{
using is_avalanching = void;
};
// absl_hash
#ifdef HAVE_ABSEIL
struct absl_hash: absl::Hash<std::string_view>
{
using is_avalanching = void;
};
#endif
#ifdef HAVE_MULXP_HASH
struct mulxp1_hash_
{
using is_avalanching = void;
std::size_t operator()( std::string_view const& st ) const BOOST_NOEXCEPT
{
return mulxp1_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp3_hash_
{
using is_avalanching = void;
std::size_t operator()( std::string_view const& st ) const BOOST_NOEXCEPT
{
return mulxp3_hash( (unsigned char const*)st.data(), st.size(), 0 );
}
};
struct mulxp3_hash32_
{
using is_avalanching = void;
std::size_t operator()( std::string_view const& st ) const BOOST_NOEXCEPT
{
std::size_t r = mulxp3_hash32( (unsigned char const*)st.data(), st.size(), 0 );
#if SIZE_MAX > UINT32_MAX
r |= r << 32;
#endif
return r;
}
};
struct mulxp1_hash32_
{
using is_avalanching = void;
std::size_t operator()( std::string_view const& st ) const BOOST_NOEXCEPT
{
std::size_t r = mulxp1_hash32( (unsigned char const*)st.data(), st.size(), 0 );
#if SIZE_MAX > UINT32_MAX
r |= r << 32;
#endif
return r;
}
};
#endif
//
int main()
{
init_words();
test< boost::hash<std::string_view> >( "boost::hash" );
test< std_hash >( "std::hash" );
test< fnv1a_hash >( "fnv1a_hash" );
#ifdef HAVE_ABSEIL
test< absl_hash >( "absl::Hash" );
#endif
#ifdef HAVE_ANKERL_UNORDERED_DENSE
test< ankerl::unordered_dense::hash<std::string_view> >( "ankerl::unordered_dense::hash" );
#endif
#ifdef HAVE_MULXP_HASH
test< mulxp1_hash_ >( "mulxp1_hash" );
test< mulxp3_hash_ >( "mulxp3_hash" );
test< mulxp1_hash32_ >( "mulxp1_hash32" );
test< mulxp3_hash32_ >( "mulxp3_hash32" );
#endif
std::cout << "---\n\n";
for( auto const& x: times )
{
std::cout << std::setw( 32 ) << ( x.label_ + ": " ) << std::setw( 5 ) << x.time_ << " ms\n";
}
}
#ifdef HAVE_ABSEIL
# include "absl/hash/internal/hash.cc"
# include "absl/hash/internal/low_level_hash.cc"
# include "absl/hash/internal/city.cc"
#endif

View File

@@ -22,6 +22,7 @@ include::hash/recent.adoc[]
include::hash/tutorial.adoc[]
include::hash/user.adoc[]
include::hash/combine.adoc[]
include::hash/describe.adoc[]
include::hash/reference.adoc[]
include::hash/notes.adoc[]
include::hash/links.adoc[]

61
doc/hash/describe.adoc Normal file
View File

@@ -0,0 +1,61 @@
////
Copyright 2022 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////
[#describe]
= Hashing User Types with Boost.Describe
:idprefix: describe_
Let's look at our `point` class again:
[source]
----
class point
{
int x;
int y;
public:
point() : x(0), y(0) {}
point(int x, int y) : x(x), y(y) {}
};
----
If you're using {cpp}14 or above, a much easier way to add
support for `boost::hash` to `point` is by using
link:../../../describe/index.html[Boost.Describe] (and
get an automatic definition of `operator==` for free):
[source]
----
#include <boost/describe/class.hpp>
#include <boost/describe/operators.hpp>
class point
{
int x;
int y;
BOOST_DESCRIBE_CLASS(point, (), (), (), (x, y))
public:
point() : x(0), y(0) {}
point(int x, int y) : x(x), y(y) {}
};
using boost::describe::operators::operator==;
using boost::describe::operators::operator!=;
----
(Full code for this example is at
link:../../examples/point2.cpp[examples/point2.cpp].)
Since the `point` class has been annotated with `BOOST_DESCRIBE_CLASS`,
the library can enumerate its members (and base classes) and automatically
synthesize the appropriate `hash_value` overload for it, without us needing
to do so.

View File

@@ -22,16 +22,21 @@ Out of the box, `boost::hash` supports
* standard integral types (integers, character types, and `bool`);
* standard floating point types (`float`, `double`, `long double`);
* pointers (to objects and to functions, but not pointers to members);
* pointers (to objects and to functions, but not pointers to members)
and `nullptr`;
* enumeration types;
* C arrays;
* `std::complex`;
* `std::pair`, `std::tuple`;
* tuple-like types, such as `std::pair`, `std::tuple`, and user-defined
types that specialize `std::tuple_size` and provide `get<I>`;
* sequence-like types, both standard and user-defined (sequence-like types
have `begin()` and `end()` member functions returning iterators);
* unordered sequences, standard or user-defined (sequences for which the hash
value does not depend on the element order, such as `std::unordered_set` and
`std::unordered_map`);
* described structs and classes -- ones that have been annotated with the
`BOOST_DESCRIBE_STRUCT` or `BOOST_DESCRIBE_CLASS` macros from
link:../../../describe/index.html[Boost.Describe];
* `std::unique_ptr`, `std::shared_ptr`;
* `std::type_index`;
* `std::error_code`, `std::error_condition`;

View File

@@ -10,6 +10,26 @@ https://www.boost.org/LICENSE_1_0.txt
= Design and Implementation Notes
:idprefix: notes_
== Quality of the Hash Function
Many hash functions strive to have little correlation between the input and
output values. They attempt to uniformally distribute the output values for
very similar inputs. This hash function makes no such attempt. In fact, for
integers, the result of the hash function is often just the input value. So
similar but different input values will often result in similar but different
output values. This means that it is not appropriate as a general hash
function. For example, a hash table may discard bits from the hash function
resulting in likely collisions, or might have poor collision resolution when
hash values are clustered together. In such cases this hash function will
perform poorly.
But the standard has no such requirement for the hash function, it just
requires that the hashes of two different values are unlikely to collide.
Containers or algorithms designed to work with the standard hash function will
have to be implemented to work well when the hash function's output is
correlated to its input. Since they are paying that cost a higher quality hash
function would be wasteful.
== The hash_value Customization Point
The way one customizes the standard `std::hash` function object for user
@@ -35,6 +55,22 @@ to be templates constrained on e.g. `std::is_integral` or its moral
equivalent. This causes types convertible to an integral to no longer
match, avoiding the problem.
== Hash Value Stability
In general, the library does not promise that the hash values will stay
the same from release to release (otherwise improvements would be
impossible). However, historically values have been quite stable. Before
release 1.81, the previous changes have been in 1.56 (a better
`hash_combine`) and 1.78 (macOS-specific change to `hash_combine`.)
Code should generally not depend on specific hash values, but for those
willing to take the risk of occasional breaks due to hash value changes,
the library now has a test that checks hash values for a number of types
against reference values (`test/hash_reference_values.cpp`),
whose https://github.com/boostorg/container_hash/commits/develop/test/hash_reference_values.cpp[version history]
can be used as a rough guide to when hash values have changed, and for what
types.
== hash_combine
The initial implementation of the library was based on Issue 6.18 of the
@@ -154,22 +190,39 @@ With this improved `hash_combine`, `boost::hash` for strings now passes the
https://github.com/aappleby/smhasher[SMHasher test suite] by Austin Appleby
(for a 64 bit `size_t`).
== Quality of the Hash Function
== hash_range
Many hash functions strive to have little correlation between the input and
output values. They attempt to uniformally distribute the output values for
very similar inputs. This hash function makes no such attempt. In fact, for
integers, the result of the hash function is often just the input value. So
similar but different input values will often result in similar but different
output values. This means that it is not appropriate as a general hash
function. For example, a hash table may discard bits from the hash function
resulting in likely collisions, or might have poor collision resolution when
hash values are clustered together. In such cases this hash function will
perform poorly.
The traditional implementation of `hash_range(seed, first, last)` has been
But the standard has no such requirement for the hash function, it just
requires that the hashes of two different values are unlikely to collide.
Containers or algorithms designed to work with the standard hash function will
have to be implemented to work well when the hash function's output is
correlated to its input. Since they are paying that cost a higher quality hash
function would be wasteful.
[source]
----
for( ; first != last; ++first )
{
boost::hash_combine<typename std::iterator_traits<It>::value_type>( seed, *first );
}
----
(the explicit template parameter is needed to support iterators with proxy
return types such as `std::vector<bool>::iterator`.)
This is logical, consistent and straightforward. In the common case where
`typename std::iterator_traits<It>::value_type` is `char` -- which it is
in the common case of `boost::hash<std::string>` -- this however leaves a
lot of performance on the table, because processing each `char` individually
is much less efficient than processing several in bulk.
In Boost 1.81, `hash_range` was changed to process elements of type `char`,
`signed char`, `unsigned char`, `std::byte`, or `char8_t`, four of a time.
A `uint32_t` is composed from `first[0]` to `first[3]`, and that `uint32_t`
is fed to `hash_combine`.
In Boost 1.82, `hash_range` for these types was changed to use
https://github.com/pdimov/mulxp_hash[`mulxp1_hash`]. This improves both
quality and speed of string hashing.
Note that `hash_range` has also traditionally guaranteed that the same element
sequence yields the same hash value regardless of the iterator type. This
property remains valid after the changes to `char` range hashing. `hash_range`,
applied to the `char` sequence `{ 'a', 'b', 'c' }`, results in the same value
whether the sequence comes from `char[3]`, `std::string`, `std::deque<char>`,
or `std::list<char>`.

View File

@@ -8,6 +8,17 @@ https://www.boost.org/LICENSE_1_0.txt
= Recent Changes
:idprefix: recent_
== Boost 1.82.0
* Added an overload of `hash_value` for `std::nullptr_t`.
* Added `is_tuple_like` and an overload of `hash_value` for
tuple-like types.
* Changed string hashing to use
https://github.com/pdimov/mulxp_hash[`mulxp1_hash`],
improving both quality and speed. This changes the hash values
for string-like types (ranges of `char`, `signed char`,
`unsigned char`, `std::byte`, `char8_t`).
== Boost 1.81.0
Major update.
@@ -21,9 +32,21 @@ Major update.
* User-defined containers (types that have `begin()` and `end()`
member functions that return iterators) are now supported out
of the box.
* `hash_combine` has been improved.
* Described structs and classes (those annotated with
`BOOST_DESCRIBE_STRUCT` or `BOOST_DESCRIBE_CLASS`) are now
supported out of the box.
* `hash_combine` has been improved. This changes the hash values
of composite (container and tuple) types and of scalar types
bigger than `size_t`.
* The performance (and quality, as a result of the above change)
of string hashing has been improved. `boost::hash` for strings
now passes SMHasher in 64 bit mode.
* The documentation has been substantially revised to reflect
the changes.
== Boost 1.78.0
* Fixed `hash_combine` so that its behavior no longer depends
on whether `size_t` is the exact same type as `boost::uint64_t`
(which wasn't the case on macOS). This changes the hash values
of composite (container and tuple) types on macOS.

View File

@@ -29,6 +29,8 @@ namespace container_hash
template<class T> struct is_range;
template<class T> struct is_contiguous_range;
template<class T> struct is_unordered_range;
template<class T> struct is_described_class;
template<class T> struct is_tuple_like;
} // namespace container_hash
@@ -88,8 +90,9 @@ template<class T>
template<class A, class B>
std::size_t hash_value( std::pair<A, B> const& v );
template<class... T>
std::size_t hash_value( std::tuple<T...> const& v );
// Enabled only when container_hash::is_tuple_like<T>::value is true
template<class T>
std::size_t hash_value( T const& v );
// Enabled only when container_hash::is_range<T>::value is true
template<class T>
@@ -103,6 +106,10 @@ template<class T>
template<class T>
std::size_t hash_value( T const& v );
// Enabled only when container_hash::is_described_class<T>::value is true
template<class T>
std::size_t hash_value( T const& v );
template<class T>
std::size_t hash_value( std::shared_ptr<T> const& v );
@@ -225,7 +232,7 @@ Effects: ::
+
--
When `typename std::iterator_traits<It>::value_type` is not `char`, `signed char`,
`unsigned char`,
`unsigned char`, `std::byte`, or `char8_t`,
[source]
----
@@ -235,11 +242,16 @@ for( ; first != last; ++first )
}
----
Otherwise, bytes from `[first, last)` are coalesced in an unspecified manner
and then passed to `hash_combine`, more than one at a time. This is done in
order to improve performance when hashing strings.
Otherwise, bytes from `[first, last)` are coalesced and hashed in an
unspecified manner. This is done in order to improve performance when hashing
strings.
--
Remarks: ::
For chars, the current implementation uses
https://github.com/pdimov/mulxp_hash[`mulxp1_hash`] when `std::size_t` is
64 bit, and `mulxp1_hash32` when it's 32 bit.
[source]
----
template<class It> std::size_t hash_range( It first, It last );
@@ -380,8 +392,9 @@ return seed;
[source]
----
template<class... T>
std::size_t hash_value( std::tuple<T...> const& v );
// Enabled only when container_hash::is_tuple_like<T>::value is true
template<class T>
std::size_t hash_value( T const& v );
----
Effects: ::
@@ -390,15 +403,21 @@ Effects: ::
----
std::size_t seed = 0;
boost::hash_combine( seed, std::get<0>(v) );
boost::hash_combine( seed, std::get<1>(v) );
using std::get;
boost::hash_combine( seed, get<0>(v) );
boost::hash_combine( seed, get<1>(v) );
// ...
boost::hash_combine( seed, std::get<N-1>(v) );
boost::hash_combine( seed, get<N-1>(v) );
return seed;
----
+
where `N` is `sizeof...(T)`.
where `N` is `std::tuple_size<T>::value`.
Remarks: ::
This overload is only enabled when
`container_hash::is_range<T>::value` is `false`.
[source]
----
@@ -446,6 +465,34 @@ Remarks: ::
This overload handles the standard unordered containers, such as
`std::unordered_set` and `std::unordered_map`.
[source]
----
// Enabled only when container_hash::is_described_class<T>::value is true
template<class T>
std::size_t hash_value( T const& v );
----
Effects: ::
+
[source]
----
std::size_t seed = 0;
boost::hash_combine( seed, b1 );
boost::hash_combine( seed, b2 );
// ...
boost::hash_combine( seed, bM );
boost::hash_combine( seed, m1 );
boost::hash_combine( seed, m2 );
// ...
boost::hash_combine( seed, mN );
return seed;
----
+
where `bi` are the bases of `v` and `mi` are its members.
[source]
----
template<class T>
@@ -633,3 +680,75 @@ template<class T> struct is_unordered_range
Users are allowed to specialize `is_unordered_range` for their types
if the default behavior does not deduce the correct value.
== <boost/container_hash/{zwsp}is_described_class.hpp>
Defines the trait `boost::container_hash::is_described_class`.
[source]
----
namespace boost
{
namespace container_hash
{
template<class T> struct is_described_class;
} // namespace container_hash
} // namespace boost
----
=== is_described_class<T>
[source]
----
template<class T> struct is_described_class
{
static constexpr bool value = /* see below */;
};
----
`is_described_class<T>::value` is `true` when
`boost::describe::has_describe_bases<T>::value` is `true`,
`boost::describe::has_describe_members<T>::value` is `true`, and
`T` is not a union.
Users are allowed to specialize `is_described_class` for their types
if the default behavior does not deduce the correct value.
== <boost/container_hash/{zwsp}is_tuple_like.hpp>
Defines the trait `boost::container_hash::is_tuple_like`.
[source]
----
namespace boost
{
namespace container_hash
{
template<class T> struct is_tuple_like;
} // namespace container_hash
} // namespace boost
----
=== is_tuple_like<T>
[source]
----
template<class T> struct is_tuple_like
{
static constexpr bool value = /* see below */;
};
----
`is_tuple_like<T>::value` is `true` when `std::tuple_size<T>::value`
is valid.
Users are allowed to specialize `is_tuple_like` for their types
if the default behavior does not deduce the correct value.

View File

@@ -1,6 +1,13 @@
////
Copyright 2005-2008 Daniel James
Copyright 2022 Christian Mazakas
Copyright 2022 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////
[#thanks]
= Acknowledgements
:idprefix: thanks_
This library is based on the design by Peter Dimov. During the initial development Joaquín M López Muñoz made many useful suggestions and contributed fixes.
@@ -12,3 +19,5 @@ The implementation of the hash function for pointers is based on suggestions mad
Some useful improvements to the floating point hash algorithm were suggested by Daniel Krügler.
The original implementation came from Jeremy B. Maitin-Shepard's hash table library, although this is a complete rewrite.
The documentation was converted from Quickbook to AsciiDoc by Christian Mazakas.

View File

@@ -74,7 +74,7 @@ assert(books.find(knife) != books.end());
assert(books.find(dandelion) == books.end());
----
The full example can be found in:
The full example can be found in
link:../../examples/books.hpp[examples/books.hpp] and
link:../../examples/books.cpp[examples/books.cpp].

View File

@@ -7,3 +7,4 @@ run books.cpp ;
run point.cpp ;
run portable.cpp ;
run template.cpp : : : <toolset>msvc-8.0:<build>no ;
run point2.cpp ;

65
examples/point2.cpp Normal file
View File

@@ -0,0 +1,65 @@
// Copyright 2005 Daniel James.
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
// Force use of assert.
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/describe/class.hpp>
#include <boost/describe/operators.hpp>
#include <cassert>
// This example illustrates how to use Boost.Describe to obtain
// automatic boost::hash support. For full details see the hash
// tutorial.
#if defined(BOOST_DESCRIBE_CXX14)
class point
{
int x;
int y;
BOOST_DESCRIBE_CLASS(point, (), (), (), (x, y))
public:
point() : x(0), y(0) {}
point(int x, int y) : x(x), y(y) {}
};
using boost::describe::operators::operator==;
using boost::describe::operators::operator!=;
int main()
{
boost::hash<point> point_hasher;
point p1(0, 0);
point p2(1, 2);
point p3(4, 1);
point p4 = p1;
assert(point_hasher(p1) == point_hasher(p4));
// These tests could legally fail, but if they did it'd be a pretty bad
// hash function.
assert(point_hasher(p1) != point_hasher(p2));
assert(point_hasher(p1) != point_hasher(p3));
}
#else
#include <cstdio>
int main()
{
std::puts( "This example requires C++14." );
}
#endif

View File

@@ -6,13 +6,16 @@
#define BOOST_HASH_DETAIL_HASH_RANGE_HPP
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/container_hash/detail/mulx.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/cstdint.hpp>
#include <iterator>
#include <limits>
#include <cstddef>
#include <climits>
#include <iterator>
#include <cstring>
namespace boost
{
@@ -27,8 +30,18 @@ template<> struct is_char_type<char>: public boost::true_type {};
template<> struct is_char_type<signed char>: public boost::true_type {};
template<> struct is_char_type<unsigned char>: public boost::true_type {};
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
template<> struct is_char_type<char8_t>: public boost::true_type {};
#endif
#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
template<> struct is_char_type<std::byte>: public boost::true_type {};
#endif
#endif
// generic version
template<class It>
inline typename boost::enable_if_<
!is_char_type<typename std::iterator_traits<It>::value_type>::value,
@@ -43,120 +56,352 @@ std::size_t >::type
return seed;
}
template<class It>
inline typename boost::enable_if_<
is_char_type<typename std::iterator_traits<It>::value_type>::value &&
is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value,
std::size_t>::type
hash_range( std::size_t seed, It first, It last )
// specialized char[] version, 32 bit
template<class It> inline boost::uint32_t read32le( It p )
{
std::size_t n = static_cast<std::size_t>( last - first );
// clang 5+, gcc 5+ figure out this pattern and use a single mov on x86
// gcc on s390x and power BE even knows how to use load-reverse
for( ; n >= 4; first += 4, n -= 4 )
{
// clang 5+, gcc 5+ figure out this pattern and use a single mov on x86
// gcc on s390x and power BE even knows how to use load-reverse
boost::uint32_t w =
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[0] ) ) |
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[1] ) ) << 8 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[2] ) ) << 16 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[3] ) ) << 24;
boost::uint32_t w =
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[0] ) ) |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[1] ) ) << 8 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[2] ) ) << 16 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[3] ) ) << 24;
return w;
}
hash_combine( seed, w );
}
#if defined(_MSC_VER) && !defined(__clang__)
{
// add a trailing suffix byte of 0x01 because otherwise sequences of
// trailing zeroes are indistinguishable from end of string
template<class T> inline boost::uint32_t read32le( T* p )
{
boost::uint32_t w;
boost::uint32_t w = 0x01u;
std::memcpy( &w, p, 4 );
return w;
}
switch( n )
{
case 1:
#endif
w =
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[0] ) ) |
0x0100u;
break;
case 2:
w =
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[0] ) ) |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[1] ) ) << 8 |
0x010000u;
break;
case 3:
w =
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[0] ) ) |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[1] ) ) << 8 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( first[2] ) ) << 16 |
0x01000000u;
break;
}
hash_combine( seed, w );
}
return seed;
inline boost::uint64_t mul32( boost::uint32_t x, boost::uint32_t y )
{
return static_cast<boost::uint64_t>( x ) * y;
}
template<class It>
inline typename boost::enable_if_<
is_char_type<typename std::iterator_traits<It>::value_type>::value &&
!is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value,
is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value &&
std::numeric_limits<std::size_t>::digits <= 32,
std::size_t>::type
hash_range( std::size_t seed, It first, It last )
{
It p = first;
std::size_t n = static_cast<std::size_t>( last - first );
boost::uint32_t const q = 0x9e3779b9U;
boost::uint32_t const k = 0xe35e67b1U; // q * q
boost::uint64_t h = mul32( static_cast<boost::uint32_t>( seed ) + q, k );
boost::uint32_t w = static_cast<boost::uint32_t>( h & 0xFFFFFFFF );
h ^= n;
while( n >= 4 )
{
boost::uint32_t v1 = read32le( p );
w += q;
h ^= mul32( v1 + w, k );
p += 4;
n -= 4;
}
{
boost::uint32_t v1 = 0;
if( n >= 1 )
{
std::size_t const x1 = ( n - 1 ) & 2; // 1: 0, 2: 0, 3: 2
std::size_t const x2 = n >> 1; // 1: 0, 2: 1, 3: 1
v1 =
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[ static_cast<std::ptrdiff_t>( x1 ) ] ) ) << x1 * 8 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[ static_cast<std::ptrdiff_t>( x2 ) ] ) ) << x2 * 8 |
static_cast<boost::uint32_t>( static_cast<unsigned char>( p[ 0 ] ) );
}
w += q;
h ^= mul32( v1 + w, k );
}
w += q;
h ^= mul32( static_cast<boost::uint32_t>( h & 0xFFFFFFFF ) + w, static_cast<boost::uint32_t>( h >> 32 ) + w + k );
return static_cast<boost::uint32_t>( h & 0xFFFFFFFF ) ^ static_cast<boost::uint32_t>( h >> 32 );
}
template<class It>
inline typename boost::enable_if_<
is_char_type<typename std::iterator_traits<It>::value_type>::value &&
!is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value &&
std::numeric_limits<std::size_t>::digits <= 32,
std::size_t>::type
hash_range( std::size_t seed, It first, It last )
{
std::size_t n = 0;
boost::uint32_t const q = 0x9e3779b9U;
boost::uint32_t const k = 0xe35e67b1U; // q * q
boost::uint64_t h = mul32( static_cast<boost::uint32_t>( seed ) + q, k );
boost::uint32_t w = static_cast<boost::uint32_t>( h & 0xFFFFFFFF );
boost::uint32_t v1 = 0;
for( ;; )
{
boost::uint32_t w = 0;
v1 = 0;
if( first == last )
{
hash_combine( seed, w | 0x01u );
return seed;
break;
}
w |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) );
v1 |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) );
++first;
++n;
if( first == last )
{
hash_combine( seed, w | 0x0100u );
return seed;
break;
}
w |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 8;
v1 |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 8;
++first;
++n;
if( first == last )
{
hash_combine( seed, w | 0x010000u );
return seed;
break;
}
w |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 16;
v1 |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 16;
++first;
++n;
if( first == last )
{
hash_combine( seed, w | 0x01000000u );
return seed;
break;
}
w |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 24;
v1 |= static_cast<boost::uint32_t>( static_cast<unsigned char>( *first ) ) << 24;
++first;
++n;
hash_combine( seed, w );
w += q;
h ^= mul32( v1 + w, k );
}
h ^= n;
w += q;
h ^= mul32( v1 + w, k );
w += q;
h ^= mul32( static_cast<boost::uint32_t>( h & 0xFFFFFFFF ) + w, static_cast<boost::uint32_t>( h >> 32 ) + w + k );
return static_cast<boost::uint32_t>( h & 0xFFFFFFFF ) ^ static_cast<boost::uint32_t>( h >> 32 );
}
// specialized char[] version, 64 bit
template<class It> inline boost::uint64_t read64le( It p )
{
boost::uint64_t w =
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[0] ) ) |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[1] ) ) << 8 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[2] ) ) << 16 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[3] ) ) << 24 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[4] ) ) << 32 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[5] ) ) << 40 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[6] ) ) << 48 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[7] ) ) << 56;
return w;
}
#if defined(_MSC_VER) && !defined(__clang__)
template<class T> inline boost::uint64_t read64le( T* p )
{
boost::uint64_t w;
std::memcpy( &w, p, 8 );
return w;
}
#endif
template<class It>
inline typename boost::enable_if_<
is_char_type<typename std::iterator_traits<It>::value_type>::value &&
is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value &&
(std::numeric_limits<std::size_t>::digits > 32),
std::size_t>::type
hash_range( std::size_t seed, It first, It last )
{
It p = first;
std::size_t n = static_cast<std::size_t>( last - first );
boost::uint64_t const q = static_cast<boost::uint64_t>( 0x9e3779b9 ) << 32 | 0x7f4a7c15;
boost::uint64_t const k = static_cast<boost::uint64_t>( 0xdf442d22 ) << 32 | 0xce4859b9; // q * q
boost::uint64_t w = mulx( seed + q, k );
boost::uint64_t h = w ^ n;
while( n >= 8 )
{
boost::uint64_t v1 = read64le( p );
w += q;
h ^= mulx( v1 + w, k );
p += 8;
n -= 8;
}
{
boost::uint64_t v1 = 0;
if( n >= 4 )
{
v1 = static_cast<boost::uint64_t>( read32le( p + static_cast<std::ptrdiff_t>( n - 4 ) ) ) << ( n - 4 ) * 8 | read32le( p );
}
else if( n >= 1 )
{
std::size_t const x1 = ( n - 1 ) & 2; // 1: 0, 2: 0, 3: 2
std::size_t const x2 = n >> 1; // 1: 0, 2: 1, 3: 1
v1 =
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[ static_cast<std::ptrdiff_t>( x1 ) ] ) ) << x1 * 8 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[ static_cast<std::ptrdiff_t>( x2 ) ] ) ) << x2 * 8 |
static_cast<boost::uint64_t>( static_cast<unsigned char>( p[ 0 ] ) );
}
w += q;
h ^= mulx( v1 + w, k );
}
return mulx( h + w, k );
}
template<class It>
inline typename boost::enable_if_<
is_char_type<typename std::iterator_traits<It>::value_type>::value &&
!is_same<typename std::iterator_traits<It>::iterator_category, std::random_access_iterator_tag>::value &&
(std::numeric_limits<std::size_t>::digits > 32),
std::size_t>::type
hash_range( std::size_t seed, It first, It last )
{
std::size_t n = 0;
boost::uint64_t const q = static_cast<boost::uint64_t>( 0x9e3779b9 ) << 32 | 0x7f4a7c15;
boost::uint64_t const k = static_cast<boost::uint64_t>( 0xdf442d22 ) << 32 | 0xce4859b9; // q * q
boost::uint64_t w = mulx( seed + q, k );
boost::uint64_t h = w;
boost::uint64_t v1 = 0;
for( ;; )
{
v1 = 0;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) );
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 8;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 16;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 24;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 32;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 40;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 48;
++first;
++n;
if( first == last )
{
break;
}
v1 |= static_cast<boost::uint64_t>( static_cast<unsigned char>( *first ) ) << 56;
++first;
++n;
w += q;
h ^= mulx( v1 + w, k );
}
h ^= n;
w += q;
h ^= mulx( v1 + w, k );
return mulx( h + w, k );
}
} // namespace hash_detail

View File

@@ -1,133 +0,0 @@
// Copyright 2005-2009 Daniel James.
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP
#define BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/config.hpp>
#if defined(BOOST_NO_CXX11_HDR_TUPLE)
// no support
#else
#include <tuple>
namespace boost
{
namespace hash_detail
{
template <std::size_t I, typename T>
inline typename boost::enable_if_<(I == std::tuple_size<T>::value),
void>::type
hash_combine_tuple(std::size_t&, T const&)
{
}
template <std::size_t I, typename T>
inline typename boost::enable_if_<(I < std::tuple_size<T>::value),
void>::type
hash_combine_tuple(std::size_t& seed, T const& v)
{
boost::hash_combine(seed, std::get<I>(v));
boost::hash_detail::hash_combine_tuple<I + 1>(seed, v);
}
template <typename T>
inline std::size_t hash_tuple(T const& v)
{
std::size_t seed = 0;
boost::hash_detail::hash_combine_tuple<0>(seed, v);
return seed;
}
} // namespace hash_detail
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <typename... T>
inline std::size_t hash_value(std::tuple<T...> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
#else
inline std::size_t hash_value(std::tuple<> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0>
inline std::size_t hash_value(std::tuple<A0> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1>
inline std::size_t hash_value(std::tuple<A0, A1> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2>
inline std::size_t hash_value(std::tuple<A0, A1, A2> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4, A5> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4, A5, A6> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4, A5, A6, A7> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4, A5, A6, A7, A8> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
inline std::size_t hash_value(std::tuple<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9> const& v)
{
return boost::hash_detail::hash_tuple(v);
}
#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
} // namespace boost
#endif // #if defined(BOOST_NO_CXX11_HDR_TUPLE)
#endif // #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP

View File

@@ -0,0 +1,156 @@
// Copyright 2005-2009 Daniel James.
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP
#define BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/container_hash/is_tuple_like.hpp>
#include <boost/container_hash/is_range.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if defined(BOOST_NO_CXX11_HDR_TUPLE)
// no support for tuple-likes
#else
#include <tuple>
namespace boost
{
namespace hash_detail
{
template <std::size_t I, typename T>
inline
typename boost::enable_if_<(I == std::tuple_size<T>::value), void>::type
hash_combine_tuple_like( std::size_t&, T const& )
{
}
template <std::size_t I, typename T>
inline
typename boost::enable_if_<(I < std::tuple_size<T>::value), void>::type
hash_combine_tuple_like( std::size_t& seed, T const& v )
{
using std::get;
boost::hash_combine( seed, get<I>( v ) );
boost::hash_detail::hash_combine_tuple_like<I + 1>( seed, v );
}
template <typename T>
inline std::size_t hash_tuple_like( T const& v )
{
std::size_t seed = 0;
boost::hash_detail::hash_combine_tuple_like<0>( seed, v );
return seed;
}
} // namespace hash_detail
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
template <class T>
inline
typename boost::enable_if_<
container_hash::is_tuple_like<T>::value && !container_hash::is_range<T>::value,
std::size_t>::type
hash_value( T const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
#else
template <typename... T>
inline std::size_t hash_value( std::tuple<T...> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
#endif
#else
inline std::size_t hash_value( std::tuple<> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0>
inline std::size_t hash_value( std::tuple<A0> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1>
inline std::size_t hash_value( std::tuple<A0, A1> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2>
inline std::size_t hash_value( std::tuple<A0, A1, A2> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4, A5> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4, A5, A6> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4, A5, A6, A7> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4, A5, A6, A7, A8> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
template<typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
inline std::size_t hash_value( std::tuple<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9> const& v )
{
return boost::hash_detail::hash_tuple_like( v );
}
#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
} // namespace boost
#endif // #if defined(BOOST_NO_CXX11_HDR_TUPLE)
#endif // #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP

View File

@@ -0,0 +1,79 @@
// Copyright 2022, 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_HASH_DETAIL_MULX_HPP
#define BOOST_HASH_DETAIL_MULX_HPP
#include <boost/cstdint.hpp>
#if defined(_MSC_VER)
# include <intrin.h>
#endif
namespace boost
{
namespace hash_detail
{
#if defined(_MSC_VER) && defined(_M_X64) && !defined(__clang__)
__forceinline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y )
{
boost::uint64_t r2;
boost::uint64_t r = _umul128( x, y, &r2 );
return r ^ r2;
}
#elif defined(_MSC_VER) && defined(_M_ARM64) && !defined(__clang__)
__forceinline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y )
{
boost::uint64_t r = x * y;
boost::uint64_t r2 = __umulh( x, y );
return r ^ r2;
}
#elif defined(__SIZEOF_INT128__)
inline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y )
{
__uint128_t r = static_cast<__uint128_t>( x ) * y;
return static_cast<boost::uint64_t>( r ) ^ static_cast<boost::uint64_t>( r >> 64 );
}
#else
inline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y )
{
boost::uint64_t x1 = static_cast<boost::uint32_t>( x );
boost::uint64_t x2 = x >> 32;
boost::uint64_t y1 = static_cast<boost::uint32_t>( y );
boost::uint64_t y2 = y >> 32;
boost::uint64_t r3 = x2 * y2;
boost::uint64_t r2a = x1 * y2;
r3 += r2a >> 32;
boost::uint64_t r2b = x2 * y1;
r3 += r2b >> 32;
boost::uint64_t r1 = x1 * y1;
boost::uint64_t r2 = (r1 >> 32) + static_cast<boost::uint32_t>( r2a ) + static_cast<boost::uint32_t>( r2b );
r1 = (r2 << 32) + static_cast<boost::uint32_t>( r1 );
r3 += r2 >> 32;
return r1 ^ r3;
}
#endif
} // namespace hash_detail
} // namespace boost
#endif // #ifndef BOOST_HASH_DETAIL_MULX_HPP

View File

@@ -0,0 +1,22 @@
#ifndef BOOST_HASH_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
#define BOOST_HASH_DETAIL_REQUIRES_CXX11_HPP_INCLUDED
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || \
defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
defined(BOOST_NO_CXX11_DECLTYPE) || \
defined(BOOST_NO_CXX11_CONSTEXPR) || \
defined(BOOST_NO_CXX11_NOEXCEPT) || \
defined(BOOST_NO_CXX11_HDR_TUPLE)
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.ContainerHash 1.82 and will be removed in Boost.ContainerHash 1.84.")
#endif
#endif // #ifndef BOOST_HASH_DETAIL_REQUIRES_CXX11_HPP_INCLUDED

View File

@@ -11,10 +11,12 @@
#define BOOST_FUNCTIONAL_HASH_HASH_HPP
#include <boost/container_hash/hash_fwd.hpp>
#include <boost/container_hash/detail/requires_cxx11.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/container_hash/is_described_class.hpp>
#include <boost/container_hash/detail/hash_tuple_like.hpp>
#include <boost/container_hash/detail/hash_mix.hpp>
#include <boost/container_hash/detail/hash_range.hpp>
#include <boost/type_traits/is_enum.hpp>
@@ -25,7 +27,16 @@
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/type_traits/conjunction.hpp>
#include <boost/type_traits/is_union.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/describe/bases.hpp>
#include <boost/describe/members.hpp>
#include <boost/cstdint.hpp>
#if defined(BOOST_DESCRIBE_CXX14)
# include <boost/mp11/algorithm.hpp>
#endif
#include <string>
#include <iterator>
#include <complex>
@@ -54,6 +65,10 @@
#include <variant>
#endif
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
# include <string_view>
#endif
namespace boost
{
@@ -104,7 +119,7 @@ namespace boost
std::size_t seed = 0;
seed = static_cast<std::size_t>( v >> 32 ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( v ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( v & 0xFFFFFFFF ) + hash_detail::hash_mix( seed );
return seed;
}
@@ -176,12 +191,11 @@ namespace boost
{
template<class T,
std::size_t Bits = sizeof(T) * CHAR_BIT,
int Digits = std::numeric_limits<T>::digits,
std::size_t size_t_bits = sizeof(std::size_t) * CHAR_BIT>
int Digits = std::numeric_limits<T>::digits>
struct hash_float_impl;
// float
template<class T, int Digits, std::size_t size_t_bits> struct hash_float_impl<T, 32, Digits, size_t_bits>
template<class T, int Digits> struct hash_float_impl<T, 32, Digits>
{
static std::size_t fn( T v )
{
@@ -193,35 +207,19 @@ namespace boost
};
// double
template<class T, int Digits> struct hash_float_impl<T, 64, Digits, 64>
template<class T, int Digits> struct hash_float_impl<T, 64, Digits>
{
static std::size_t fn( T v )
{
boost::uint64_t w;
std::memcpy( &w, &v, sizeof( v ) );
return w;
}
};
template<class T, int Digits> struct hash_float_impl<T, 64, Digits, 32>
{
static std::size_t fn( T v )
{
boost::uint32_t w[ 2 ];
std::memcpy( &w, &v, sizeof( v ) );
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
return seed;
return hash_value( w );
}
};
// 80 bit long double in 12 bytes
template<class T> struct hash_float_impl<T, 96, 64, 64>
template<class T> struct hash_float_impl<T, 96, 64>
{
static std::size_t fn( T v )
{
@@ -230,32 +228,15 @@ namespace boost
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}
};
template<class T> struct hash_float_impl<T, 96, 64, 32>
{
static std::size_t fn( T v )
{
boost::uint32_t w[ 3 ] = {};
std::memcpy( &w, &v, 80 / CHAR_BIT );
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[2] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[0] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}
};
// 80 bit long double in 16 bytes
template<class T> struct hash_float_impl<T, 128, 64, 64>
template<class T> struct hash_float_impl<T, 128, 64>
{
static std::size_t fn( T v )
{
@@ -264,32 +245,15 @@ namespace boost
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}
};
template<class T> struct hash_float_impl<T, 128, 64, 32>
{
static std::size_t fn( T v )
{
boost::uint32_t w[ 3 ] = {};
std::memcpy( &w, &v, 80 / CHAR_BIT );
std::size_t seed = 0;
seed = static_cast<std::size_t>( w[0] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[1] ) + hash_detail::hash_mix( seed );
seed = static_cast<std::size_t>( w[2] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[0] ) + hash_detail::hash_mix( seed );
seed = hash_value( w[1] ) + hash_detail::hash_mix( seed );
return seed;
}
};
// 128 bit long double
template<class T, int Digits, std::size_t size_t_bits> struct hash_float_impl<T, 128, Digits, size_t_bits>
template<class T, int Digits> struct hash_float_impl<T, 128, Digits>
{
static std::size_t fn( T v )
{
@@ -434,6 +398,49 @@ namespace boost
return boost::hash_unordered_range( v.begin(), v.end() );
}
#endif
// described classes
#if defined(BOOST_DESCRIBE_CXX14)
#if defined(_MSC_VER) && _MSC_VER == 1900
# pragma warning(push)
# pragma warning(disable: 4100) // unreferenced formal parameter
#endif
template <typename T>
typename boost::enable_if_<container_hash::is_described_class<T>::value, std::size_t>::type
hash_value( T const& v )
{
static_assert( !boost::is_union<T>::value, "described unions are not supported" );
std::size_t r = 0;
using Bd = describe::describe_bases<T, describe::mod_any_access>;
mp11::mp_for_each<Bd>([&](auto D){
using B = typename decltype(D)::type;
boost::hash_combine( r, (B const&)v );
});
using Md = describe::describe_members<T, describe::mod_any_access>;
mp11::mp_for_each<Md>([&](auto D){
boost::hash_combine( r, v.*D.pointer );
});
return r;
}
#if defined(_MSC_VER) && _MSC_VER == 1900
# pragma warning(pop)
#endif
#endif
// std::unique_ptr, std::shared_ptr
@@ -489,6 +496,19 @@ namespace boost
return seed;
}
#endif
// std::nullptr_t
#if !defined(BOOST_NO_CXX11_NULLPTR)
template <typename T>
typename boost::enable_if_<boost::is_same<T, std::nullptr_t>::value, std::size_t>::type
hash_value( T const& /*v*/ )
{
return boost::hash_value( static_cast<void*>( nullptr ) );
}
#endif
// std::optional
@@ -628,8 +648,30 @@ namespace boost
};
#endif
}
#undef BOOST_FUNCTIONAL_HASH_ROTL32
// boost::unordered::hash_is_avalanching
namespace unordered
{
template<class T> struct hash_is_avalanching;
template<class Ch> struct hash_is_avalanching< boost::hash< std::basic_string<Ch> > >: boost::is_integral<Ch> {};
// boost::is_integral<char8_t> is false, but should be true (https://github.com/boostorg/type_traits/issues/175)
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
template<> struct hash_is_avalanching< boost::hash< std::basic_string<char8_t> > >: boost::true_type {};
#endif
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
template<class Ch> struct hash_is_avalanching< boost::hash< std::basic_string_view<Ch> > >: boost::is_integral<Ch> {};
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
template<> struct hash_is_avalanching< boost::hash< std::basic_string_view<char8_t> > >: boost::true_type {};
#endif
#endif
} // namespace unordered
} // namespace boost
#endif // #ifndef BOOST_FUNCTIONAL_HASH_HASH_HPP

View File

@@ -1,5 +1,5 @@
// Copyright 2005-2009 Daniel James.
// Copyright 2021 Peter Dimov.
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
@@ -17,6 +17,8 @@ namespace container_hash
template<class T> struct is_range;
template<class T> struct is_contiguous_range;
template<class T> struct is_unordered_range;
template<class T> struct is_described_class;
template<class T> struct is_tuple_like;
} // namespace container_hash

View File

@@ -5,12 +5,13 @@
#ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#include <boost/container_hash/detail/requires_cxx11.hpp>
#include <boost/container_hash/is_range.hpp>
#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)
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) && !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/declval.hpp>

View File

@@ -0,0 +1,38 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED
#define BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_union.hpp>
#include <boost/describe/bases.hpp>
#include <boost/describe/members.hpp>
namespace boost
{
namespace container_hash
{
#if defined(BOOST_DESCRIBE_CXX11)
template<class T> struct is_described_class: boost::integral_constant<bool,
describe::has_describe_bases<T>::value &&
describe::has_describe_members<T>::value &&
!boost::is_union<T>::value>
{
};
#else
template<class T> struct is_described_class: boost::false_type
{
};
#endif
} // namespace container_hash
} // namespace boost
#endif // #ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED

View File

@@ -5,6 +5,7 @@
#ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED
#define BOOST_HASH_IS_RANGE_HPP_INCLUDED
#include <boost/container_hash/detail/requires_cxx11.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/declval.hpp>

View File

@@ -0,0 +1,42 @@
#ifndef BOOST_HASH_IS_TUPLE_LIKE_HPP_INCLUDED
#define BOOST_HASH_IS_TUPLE_LIKE_HPP_INCLUDED
// Copyright 2017, 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 <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <utility>
namespace boost
{
namespace hash_detail
{
template<class T, class E = true_type> struct is_tuple_like_: false_type
{
};
#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
template<class T> struct is_tuple_like_<T, integral_constant<bool, std::tuple_size<T>::value == std::tuple_size<T>::value> >: true_type
{
};
#endif
} // namespace hash_detail
namespace container_hash
{
template<class T> struct is_tuple_like: hash_detail::is_tuple_like_<T>
{
};
} // namespace container_hash
} // namespace boost
#endif // #ifndef BOOST_HASH_IS_TUPLE_LIKE_HPP_INCLUDED

View File

@@ -1,4 +1,4 @@
# Copyright 2018, 2019, 2021 Peter Dimov
# Copyright 2018, 2019, 2021, 2022 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
@@ -6,6 +6,7 @@ include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(HAVE_BOOST_TEST)
boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::container_hash Boost::core Boost::utility)
boost_test_jamfile(FILE Jamfile.v2
LINK_LIBRARIES Boost::container_hash Boost::core Boost::utility Boost::unordered)
endif()

View File

@@ -77,7 +77,7 @@ run hash_string_test2.cpp ;
# for gcc-4.8
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 <toolset>msvc-8.0:<build>no ;
run hash_fs_path_test.cpp /boost//filesystem/<warnings>off : : : $(fs-path-req) <toolset>msvc-14.0,<cxxstd>latest:<build>no <toolset>msvc-8.0:<build>no <undefined-sanitizer>norecover:<link>static ;
run is_range_test2.cpp : : : $(fs-path-req) <toolset>msvc-8.0:<build>no ;
run hash_container_test.cpp ;
@@ -101,3 +101,27 @@ run hash_unordered_map_test.cpp ;
run is_range_test3.cpp ;
run is_contiguous_range_test2.cpp ;
run is_unordered_range_test2.cpp ;
run is_contiguous_range_test3.cpp ;
run is_described_class_test.cpp
: : : <warnings>extra ;
run is_described_class_test2.cpp
: : : <warnings>extra ;
run is_described_class_test3.cpp
: : : <warnings>extra ;
run described_class_test.cpp
: : : <warnings>extra ;
run hash_is_avalanching_test.cpp ;
run hash_is_avalanching_test2.cpp ;
run hash_integral_test2.cpp ;
run hash_nullptr_test.cpp ;
run is_tuple_like_test.cpp ;
run hash_tuple_like_test.cpp ;
run hash_tuple_like_test2.cpp
: : : <warnings>extra ;

View File

@@ -11,6 +11,8 @@ add_subdirectory(../.. boostorg/container_hash)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../type_traits boostorg/type_traits)
add_subdirectory(../../../static_assert boostorg/static_assert)
add_subdirectory(../../../describe boostorg/describe)
add_subdirectory(../../../mp11 boostorg/mp11)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::container_hash)

View File

@@ -0,0 +1,159 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunused-private-field"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/describe/class.hpp>
#include <boost/describe/operators.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#if !defined(BOOST_DESCRIBE_CXX14)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_DESCRIBE_CXX14 is not defined" )
int main() {}
#else
struct X1
{
int m;
explicit X1( int m_ ): m( m_ ) {}
};
BOOST_DESCRIBE_STRUCT( X1, (), (m) )
struct X2
{
int m;
explicit X2( int m_ ): m( m_ ) {}
};
BOOST_DESCRIBE_STRUCT( X2, (), (m) )
struct X3
{
int m;
explicit X3( int m_ ): m( m_ ) {}
};
BOOST_DESCRIBE_STRUCT( X3, (), (m) )
class Y: public X1, protected X2, private X3
{
public:
int m1;
protected:
int m2;
private:
int m3;
public:
Y( int x1, int x2, int x3, int m1_, int m2_, int m3_ ):
X1( x1 ), X2( x2 ), X3( x3 ), m1( m1_ ), m2( m2_ ), m3( m3_ ) {}
BOOST_DESCRIBE_CLASS( Y, (X1, X2, X3), (m1), (m2), (m3) )
};
using boost::describe::operators::operator==;
using boost::describe::operators::operator!=;
using boost::describe::operators::operator<<;
int main()
{
Y y1( 0, 0, 0, 0, 0, 0 );
BOOST_TEST_EQ( y1, y1 );
BOOST_TEST_EQ( boost::hash<Y>()(y1), boost::hash<Y>()(y1) );
Y y2( 1, 0, 0, 0, 0, 0 );
BOOST_TEST_NE( y1, y2 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y2) );
Y y3( 0, 1, 0, 0, 0, 0 );
BOOST_TEST_NE( y1, y3 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y3) );
BOOST_TEST_NE( y2, y3 );
BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y3) );
Y y4( 0, 0, 1, 0, 0, 0 );
BOOST_TEST_NE( y1, y4 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y4) );
BOOST_TEST_NE( y2, y4 );
BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y4) );
BOOST_TEST_NE( y3, y4 );
BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y4) );
Y y5( 0, 0, 0, 1, 0, 0 );
BOOST_TEST_NE( y1, y5 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y5) );
BOOST_TEST_NE( y2, y5 );
BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y5) );
BOOST_TEST_NE( y3, y5 );
BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y5) );
BOOST_TEST_NE( y4, y5 );
BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y5) );
Y y6( 0, 0, 0, 0, 1, 0 );
BOOST_TEST_NE( y1, y6 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y6) );
BOOST_TEST_NE( y2, y6 );
BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y6) );
BOOST_TEST_NE( y3, y6 );
BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y6) );
BOOST_TEST_NE( y4, y6 );
BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y6) );
BOOST_TEST_NE( y5, y6 );
BOOST_TEST_NE( boost::hash<Y>()(y5), boost::hash<Y>()(y6) );
Y y7( 0, 0, 0, 0, 0, 1 );
BOOST_TEST_NE( y1, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y7) );
BOOST_TEST_NE( y2, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y7) );
BOOST_TEST_NE( y3, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y7) );
BOOST_TEST_NE( y4, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y7) );
BOOST_TEST_NE( y5, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y5), boost::hash<Y>()(y7) );
BOOST_TEST_NE( y6, y7 );
BOOST_TEST_NE( boost::hash<Y>()(y6), boost::hash<Y>()(y7) );
return boost::report_errors();
}
#endif

View File

@@ -3,6 +3,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
#include "./config.hpp"
#if !defined(BOOST_HASH_TEST_EXTENSIONS)

View File

@@ -48,5 +48,13 @@ int main()
test<float>();
test<double>();
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
test<char8_t>();
#endif
#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
test<std::byte>();
#endif
return boost::report_errors();
}

View File

@@ -14,8 +14,8 @@
#include <boost/core/lightweight_test.hpp>
#include "./compile_time.hpp"
void void_func1() { static int x = 1; ++x; }
void void_func2() { static int x = 2; --x; }
void void_func1() { static int x = 1; ++x; (void)x; }
void void_func2() { static int x = 2; --x; (void)x; }
int int_func1(int) { return 0; }
int int_func2(int) { return 1; }

View File

@@ -7,7 +7,7 @@
#include <boost/core/lightweight_test.hpp>
#include <boost/core/type_name.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <set>
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4127) // conditional expression is constant

View File

@@ -0,0 +1,52 @@
// Copyright 2005-2009 Daniel James.
// Copyright 2021 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 <boost/core/type_name.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/static_assert.hpp>
#include <boost/config.hpp>
// This test checks that values representable in a signed
// and the corresponding unsigned type hash to the same value
template<class T>
void signed_unsigned_test()
{
BOOST_STATIC_ASSERT( boost::is_signed<T>::value );
typedef typename boost::make_unsigned<T>::type U;
T x = std::numeric_limits<T>::max();
do
{
BOOST_TEST_EQ( boost::hash<T>()( x ), boost::hash<U>()( static_cast<U>( x ) ) );
x /= 3;
}
while( x > 0 );
}
#define TEST(type) std::cerr << "Testing: " #type " (" << boost::core::type_name<type>() << ")\n"; signed_unsigned_test<type>();
int main()
{
TEST(signed char)
TEST(short)
TEST(int)
TEST(long)
#if !defined(BOOST_NO_LONG_LONG)
TEST(boost::long_long_type)
#endif
#if defined(BOOST_HAS_INT128)
TEST(boost::int128_type)
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,41 @@
// Copyright 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_trait.hpp>
#include <boost/unordered/hash_traits.hpp>
#include <boost/config.hpp>
#include <string>
enum my_char { min = 0, max = 255 };
int main()
{
using boost::unordered::hash_is_avalanching;
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::string> > ));
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::wstring> > ));
#if !defined(BOOST_NO_CXX11_CHAR16_T)
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::u16string> > ));
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T)
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::u32string> > ));
#endif
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash< std::basic_string<char8_t> > > ));
#endif
BOOST_TEST_TRAIT_FALSE(( hash_is_avalanching< boost::hash<std::basic_string<my_char> > > ));
return boost::report_errors();
}

View File

@@ -0,0 +1,52 @@
// Copyright 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_trait.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX17_HDR_STRING_VIEW is defined" )
int main() {}
#else
#include <boost/unordered/hash_traits.hpp>
#include <string_view>
enum my_char { min = 0, max = 255 };
int main()
{
using boost::unordered::hash_is_avalanching;
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::string_view> > ));
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::wstring_view> > ));
#if !defined(BOOST_NO_CXX11_CHAR16_T)
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::u16string_view> > ));
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T)
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash<std::u32string_view> > ));
#endif
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
BOOST_TEST_TRAIT_TRUE(( hash_is_avalanching< boost::hash< std::basic_string_view<char8_t> > > ));
#endif
BOOST_TEST_TRAIT_FALSE(( hash_is_avalanching< boost::hash<std::basic_string_view<my_char> > > ));
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,41 @@
// Copyright 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 <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_NULLPTR)
BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX11_NULLPTR is defined" )
int main() {}
#else
template<class T> std::size_t hv( T const& x )
{
return boost::hash<T>()( x );
}
int main()
{
{
BOOST_TEST_EQ( hv((void*)0), hv(nullptr) );
}
{
int x = 0;
BOOST_TEST_EQ( hv((int*)0), hv(nullptr) );
BOOST_TEST_NE( hv(&x), hv(nullptr) );
(void)x;
}
return boost::report_errors();
}
#endif

View File

@@ -171,16 +171,16 @@ int main()
#if SIZE_MAX == 4294967295U
BOOST_TEST_EQ( hv(1.0), 1072693248U );
BOOST_TEST_EQ( hv(-1.0), 3220176896U );
BOOST_TEST_EQ( hv(3.14), 3972386992U );
BOOST_TEST_EQ( hv(-3.14), 1824903344U );
BOOST_TEST_EQ( hv(1e-308), 2213556530U );
BOOST_TEST_EQ( hv(-1e-308), 66072882U );
BOOST_TEST_EQ( hv(1e+308), 2623678890U );
BOOST_TEST_EQ( hv(-1e+308), 476195242U );
BOOST_TEST_EQ( hv(std::numeric_limits<double>::infinity()), 2146435072U );
BOOST_TEST_EQ( hv(-std::numeric_limits<double>::infinity()), 4293918720U );
BOOST_TEST_EQ( hv(1.0), 2619008688U );
BOOST_TEST_EQ( hv(-1.0), 146497060U );
BOOST_TEST_EQ( hv(3.14), 101651732U );
BOOST_TEST_EQ( hv(-3.14), 210858151U );
BOOST_TEST_EQ( hv(1e-308), 3911789313U );
BOOST_TEST_EQ( hv(-1e-308), 1812507313U );
BOOST_TEST_EQ( hv(1e+308), 987802568U );
BOOST_TEST_EQ( hv(-1e+308), 1639042439U );
BOOST_TEST_EQ( hv(std::numeric_limits<double>::infinity()), 3227645345U );
BOOST_TEST_EQ( hv(-std::numeric_limits<double>::infinity()), 2247339177U );
#else
@@ -207,21 +207,23 @@ int main()
if( ldbits == 64 )
{
BOOST_TEST_EQ( hv(1.0L), 1072693248U );
BOOST_TEST_EQ( hv(-1.0L), 3220176896U );
BOOST_TEST_EQ( hv(3.14L), 3972386992U );
BOOST_TEST_EQ( hv(-3.14L), 1824903344U );
BOOST_TEST_EQ( hv(std::numeric_limits<long double>::infinity()), 2146435072U );
BOOST_TEST_EQ( hv(-std::numeric_limits<long double>::infinity()), 4293918720U );
BOOST_TEST_EQ( hv(1.0L), hv(1.0) );
BOOST_TEST_EQ( hv(-1.0L), hv(-1.0) );
BOOST_TEST_EQ( hv(3.14L), hv(3.14) );
BOOST_TEST_EQ( hv(-3.14L), hv(-3.14) );
BOOST_TEST_EQ( hv(std::numeric_limits<long double>::infinity()), hv(std::numeric_limits<double>::infinity()) );
BOOST_TEST_EQ( hv(-std::numeric_limits<long double>::infinity()), hv(-std::numeric_limits<double>::infinity()) );
}
else
{
BOOST_TEST_EQ( hv(1.0L), 3770520689U );
BOOST_TEST_EQ( hv(-1.0L), 3770553457U );
BOOST_TEST_EQ( hv(3.14L), 1150018772U );
BOOST_TEST_EQ( hv(-3.14L), 1150051540U );
BOOST_TEST_EQ( hv(std::numeric_limits<long double>::infinity()), 3770537073U );
BOOST_TEST_EQ( hv(-std::numeric_limits<long double>::infinity()), 3770569841U );
// ldbits == 96
BOOST_TEST_EQ( hv(1.0L), 3632050780U );
BOOST_TEST_EQ( hv(-1.0L), 3632083548U );
BOOST_TEST_EQ( hv(3.14L), 1742026549U );
BOOST_TEST_EQ( hv(-3.14L), 1742059317U );
BOOST_TEST_EQ( hv(std::numeric_limits<long double>::infinity()), 3632067164U );
BOOST_TEST_EQ( hv(-std::numeric_limits<long double>::infinity()), 3632099932U );
}
#else
@@ -246,9 +248,7 @@ int main()
}
else
{
// ldbits == 128 && std::numeric_limits<long double>::digits == 113
// under ARM64 and S390x, but the values differ presumably because of
// __FLOAT_WORD_ORDER__
// ldbits == 128 && std::numeric_limits<long double>::digits == 113
BOOST_TEST_EQ( hv(1.0L), 4611404543450677248ULL );
BOOST_TEST_EQ( hv(-1.0L), 13834776580305453056ULL );
@@ -284,19 +284,19 @@ int main()
// string
#if SIZE_MAX == 4294967295U
BOOST_TEST_EQ( hv(std::string()), 1580013426U );
BOOST_TEST_EQ( hv(std::string("abc")), 469308065U );
BOOST_TEST_EQ( hv(std::string("\0", 1)), 165258820U );
BOOST_TEST_EQ( hv(std::string("\0\0", 2)), 4017288109U );
BOOST_TEST_EQ( hv(std::string("\0\0\0", 3)), 1352445396U );
BOOST_TEST_EQ( hv(std::string()), 1868390524U );
BOOST_TEST_EQ( hv(std::string("abc")), 3674866719U );
BOOST_TEST_EQ( hv(std::string("\0", 1)), 1965885047U );
BOOST_TEST_EQ( hv(std::string("\0\0", 2)), 54340706U );
BOOST_TEST_EQ( hv(std::string("\0\0\0", 3)), 688730713U );
#else
BOOST_TEST_EQ( hv(std::string()), 2220755840493918647ULL );
BOOST_TEST_EQ( hv(std::string("abc")), 7565583854499162206ULL );
BOOST_TEST_EQ( hv(std::string("\0", 1)), 1241131678047372712ULL );
BOOST_TEST_EQ( hv(std::string("\0\0", 2)), 152341731040131640ULL );
BOOST_TEST_EQ( hv(std::string("\0\0\0", 3)), 12957252994983528908ULL );
BOOST_TEST_EQ( hv(std::string()), 2060355526954642342ULL );
BOOST_TEST_EQ( hv(std::string("abc")), 2539195663733406973ULL );
BOOST_TEST_EQ( hv(std::string("\0", 1)), 18432168439372857722ULL );
BOOST_TEST_EQ( hv(std::string("\0\0", 2)), 6494115972580589074ULL );
BOOST_TEST_EQ( hv(std::string("\0\0\0", 3)), 4419026507380069870ULL );
#endif
@@ -344,10 +344,10 @@ int main()
#if SIZE_MAX == 4294967295U
BOOST_TEST_EQ( hv(std::complex<double>(+1.0, 0.0)), 1072693248U );
BOOST_TEST_EQ( hv(std::complex<double>(-1.0, 0.0)), 3220176896U );
BOOST_TEST_EQ( hv(std::complex<double>(0.0, +1.0)), 2619008688U );
BOOST_TEST_EQ( hv(std::complex<double>(0.0, -1.0)), 146497060U );
BOOST_TEST_EQ( hv(std::complex<double>(+1.0, 0.0)), 2619008688U );
BOOST_TEST_EQ( hv(std::complex<double>(-1.0, 0.0)), 146497060U );
BOOST_TEST_EQ( hv(std::complex<double>(0.0, +1.0)), 22395692U );
BOOST_TEST_EQ( hv(std::complex<double>(0.0, -1.0)), 1449221192U );
#else
@@ -376,17 +376,17 @@ int main()
// vector<char>
#if SIZE_MAX == 4294967295U
BOOST_TEST_EQ( hv(std::vector<char>(0)), 1580013426U );
BOOST_TEST_EQ( hv(std::vector<char>(1)), 165258820U );
BOOST_TEST_EQ( hv(std::vector<char>(2)), 4017288109U );
BOOST_TEST_EQ( hv(std::vector<char>(3)), 1352445396U );
BOOST_TEST_EQ( hv(std::vector<char>(0)), 1868390524U );
BOOST_TEST_EQ( hv(std::vector<char>(1)), 1965885047U );
BOOST_TEST_EQ( hv(std::vector<char>(2)), 54340706U );
BOOST_TEST_EQ( hv(std::vector<char>(3)), 688730713U );
#else
BOOST_TEST_EQ( hv(std::vector<char>(0)), 2220755840493918647ULL );
BOOST_TEST_EQ( hv(std::vector<char>(1)), 1241131678047372712ULL );
BOOST_TEST_EQ( hv(std::vector<char>(2)), 152341731040131640ULL );
BOOST_TEST_EQ( hv(std::vector<char>(3)), 12957252994983528908ULL );
BOOST_TEST_EQ( hv(std::vector<char>(0)), 2060355526954642342ULL );
BOOST_TEST_EQ( hv(std::vector<char>(1)), 18432168439372857722ULL );
BOOST_TEST_EQ( hv(std::vector<char>(2)), 6494115972580589074ULL );
BOOST_TEST_EQ( hv(std::vector<char>(3)), 4419026507380069870ULL );
#endif
@@ -427,17 +427,17 @@ int main()
// list<char>
#if SIZE_MAX == 4294967295U
BOOST_TEST_EQ( hv(std::list<char>(0)), 1580013426U );
BOOST_TEST_EQ( hv(std::list<char>(1)), 165258820U );
BOOST_TEST_EQ( hv(std::list<char>(2)), 4017288109U );
BOOST_TEST_EQ( hv(std::list<char>(3)), 1352445396U );
BOOST_TEST_EQ( hv(std::list<char>(0)), 1868390524U );
BOOST_TEST_EQ( hv(std::list<char>(1)), 1965885047U );
BOOST_TEST_EQ( hv(std::list<char>(2)), 54340706U );
BOOST_TEST_EQ( hv(std::list<char>(3)), 688730713U );
#else
BOOST_TEST_EQ( hv(std::list<char>(0)), 2220755840493918647ULL );
BOOST_TEST_EQ( hv(std::list<char>(1)), 1241131678047372712ULL );
BOOST_TEST_EQ( hv(std::list<char>(2)), 152341731040131640ULL );
BOOST_TEST_EQ( hv(std::list<char>(3)), 12957252994983528908ULL );
BOOST_TEST_EQ( hv(std::list<char>(0)), 2060355526954642342ULL );
BOOST_TEST_EQ( hv(std::list<char>(1)), 18432168439372857722ULL );
BOOST_TEST_EQ( hv(std::list<char>(2)), 6494115972580589074ULL );
BOOST_TEST_EQ( hv(std::list<char>(3)), 4419026507380069870ULL );
#endif

View File

@@ -0,0 +1,204 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/config.hpp>
#include <utility>
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
#include <tuple>
namespace user
{
struct Y1
{
int a;
int b;
};
template<std::size_t I> int& get( Y1& v );
template<std::size_t I> int const& get( Y1 const& v );
template<> int& get<0>( Y1& v )
{
return v.a;
}
template<> int const& get<0>( Y1 const& v )
{
return v.a;
}
template<> int& get<1>( Y1& v )
{
return v.b;
}
template<> int const& get<1>( Y1 const& v )
{
return v.b;
}
struct Y2
{
int a;
int b;
template<class T> friend
typename boost::enable_if_<boost::is_same<T, Y2>::value, std::size_t>::type
hash_value( T const& v )
{
std::size_t seed = 0;
boost::hash_combine( seed, v.a );
boost::hash_combine( seed, v.b );
return seed;
}
};
} // namespace user
namespace std
{
template<> struct tuple_size<user::Y1>: std::integral_constant<std::size_t, 2>
{
};
template<> struct tuple_size<user::Y2>: std::integral_constant<std::size_t, 2>
{
};
} // namespace std
namespace boost
{
namespace container_hash
{
template<> struct is_tuple_like<user::Y2>: boost::false_type {};
} // namespace container_hash
} // namespace boost
#endif
template<class T> std::size_t hv( T const& t )
{
return boost::hash<T>()( t );
}
int main()
{
{
std::pair<int, int> tp( 1, 2 );
int const a[] = { 1, 2 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
{
std::tuple<> tp;
BOOST_TEST_EQ( hv(tp), 0u );
}
{
std::tuple<int> tp( 1 );
int const a[] = { 1 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int> tp( 1, 2 );
int const a[] = { 1, 2 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int> tp( 1, 2, 3 );
int const a[] = { 1, 2, 3 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int> tp( 1, 2, 3, 4 );
int const a[] = { 1, 2, 3, 4 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int, int> tp( 1, 2, 3, 4, 5 );
int const a[] = { 1, 2, 3, 4, 5 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int, int, int> tp( 1, 2, 3, 4, 5, 6 );
int const a[] = { 1, 2, 3, 4, 5, 6 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int, int, int, int> tp( 1, 2, 3, 4, 5, 6, 7 );
int const a[] = { 1, 2, 3, 4, 5, 6, 7 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int, int, int, int, int> tp( 1, 2, 3, 4, 5, 6, 7, 8 );
int const a[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
{
std::tuple<int, int, int, int, int, int, int, int, int> tp( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
int const a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
{
user::Y1 tp = { 1, 2 };
int const a[] = { 1, 2 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
#endif
{
user::Y2 tp = { 1, 2 };
int const a[] = { 1, 2 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,78 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
#include <boost/container_hash/hash.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/describe/class.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <utility>
#if defined(BOOST_NO_CXX11_HDR_TUPLE)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_TUPLE is defined" )
int main() {}
#elif !defined(BOOST_DESCRIBE_CXX14)
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_DESCRIBE_CXX14 is not defined" )
int main() {}
#else
namespace user
{
struct Y3
{
int a;
int b;
};
BOOST_DESCRIBE_STRUCT(Y3, (), (a, b))
} // namespace user
namespace std
{
template<> struct tuple_size<user::Y3>: std::integral_constant<std::size_t, 2>
{
};
} // namespace std
namespace boost
{
namespace container_hash
{
template<> struct is_tuple_like<user::Y3>: boost::false_type {};
} // namespace container_hash
} // namespace boost
template<class T> std::size_t hv( T const& t )
{
return boost::hash<T>()( t );
}
int main()
{
{
user::Y3 tp = { 1, 2 };
int const a[] = { 1, 2 };
BOOST_TEST_EQ( hv(tp), hv(a) );
}
return boost::report_errors();
}
#endif

View File

@@ -51,7 +51,7 @@ int main()
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<std::wstring const>));
// std::vector doesn't have data() in C++03
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) && !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector<X> >));
BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector<X> const >));
#endif

View File

@@ -50,7 +50,7 @@ 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)
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) && !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_TEST_TRAIT_TRUE((is_contiguous_range<X1>));

View File

@@ -0,0 +1,25 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/container_hash/is_contiguous_range.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <cstddef>
struct X1
{
char const* begin() const;
char const* end() const;
std::size_t size() const;
char data[16];
};
int main()
{
using boost::container_hash::is_contiguous_range;
BOOST_TEST_TRAIT_FALSE((is_contiguous_range<X1>));
return boost::report_errors();
}

View File

@@ -0,0 +1,56 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/container_hash/is_described_class.hpp>
#include <boost/describe/class.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <string>
struct X1
{
};
struct X2
{
int m;
};
struct Y1
{
};
BOOST_DESCRIBE_STRUCT( Y1, (), () )
struct Y2: Y1
{
int m;
};
BOOST_DESCRIBE_STRUCT( Y2, (Y1), (m) )
int main()
{
using boost::container_hash::is_described_class;
BOOST_TEST_TRAIT_FALSE((is_described_class<void>));
BOOST_TEST_TRAIT_FALSE((is_described_class<int>));
BOOST_TEST_TRAIT_FALSE((is_described_class<X1>));
BOOST_TEST_TRAIT_FALSE((is_described_class<X2>));
BOOST_TEST_TRAIT_FALSE((is_described_class<int[2]>));
BOOST_TEST_TRAIT_FALSE((is_described_class<std::string>));
#if defined(BOOST_DESCRIBE_CXX14)
BOOST_TEST_TRAIT_TRUE((is_described_class<Y1>));
BOOST_TEST_TRAIT_TRUE((is_described_class<Y2>));
#else
BOOST_TEST_TRAIT_FALSE((is_described_class<Y1>));
BOOST_TEST_TRAIT_FALSE((is_described_class<Y2>));
#endif
return boost::report_errors();
}

View File

@@ -0,0 +1,35 @@
// 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 <boost/describe/class.hpp>
struct X
{
};
BOOST_DESCRIBE_STRUCT( X, (), () )
namespace boost
{
namespace container_hash
{
template<class T> struct is_described_class;
template<> struct is_described_class<X>: boost::false_type {};
} // namespace container_hash
} // namespace boost
#include <boost/container_hash/is_described_class.hpp>
#include <boost/core/lightweight_test_trait.hpp>
int main()
{
using boost::container_hash::is_described_class;
BOOST_TEST_TRAIT_FALSE((is_described_class<X>));
return boost::report_errors();
}

View File

@@ -0,0 +1,31 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/container_hash/is_described_class.hpp>
#include <boost/describe/class.hpp>
#include <boost/core/lightweight_test_trait.hpp>
union Y1
{
};
BOOST_DESCRIBE_STRUCT( Y1, (), () )
union Y2
{
int m1;
float m2;
};
BOOST_DESCRIBE_STRUCT( Y2, (), (m1, m2) )
int main()
{
using boost::container_hash::is_described_class;
BOOST_TEST_TRAIT_FALSE((is_described_class<Y1>));
BOOST_TEST_TRAIT_FALSE((is_described_class<Y2>));
return boost::report_errors();
}

View File

@@ -0,0 +1,91 @@
// Copyright 2017, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
#include <boost/container_hash/is_tuple_like.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <utility>
struct X
{
};
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
#include <tuple>
namespace user
{
struct Y
{
int a;
int b;
};
template<std::size_t I> int& get( Y& v );
template<std::size_t I> int const& get( Y const& v );
template<> int& get<0>( Y& v )
{
return v.a;
}
template<> int const& get<0>( Y const& v )
{
return v.a;
}
template<> int& get<1>( Y& v )
{
return v.b;
}
template<> int const& get<1>( Y const& v )
{
return v.b;
}
} // namespace user
namespace std
{
template<> struct tuple_size<user::Y>: std::integral_constant<std::size_t, 2>
{
};
} // namespace std
#endif // #if !defined(BOOST_NO_CXX11_HDR_TUPLE)
int main()
{
using boost::container_hash::is_tuple_like;
BOOST_TEST_TRAIT_FALSE((is_tuple_like<void>));
BOOST_TEST_TRAIT_FALSE((is_tuple_like<int>));
BOOST_TEST_TRAIT_FALSE((is_tuple_like<X>));
BOOST_TEST_TRAIT_FALSE((is_tuple_like<int[2]>));
#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
BOOST_TEST_TRAIT_TRUE((is_tuple_like< std::pair<int, X> >));
BOOST_TEST_TRAIT_TRUE((is_tuple_like< std::tuple<> >));
BOOST_TEST_TRAIT_TRUE((is_tuple_like< std::tuple<X> >));
BOOST_TEST_TRAIT_TRUE((is_tuple_like< std::tuple<X, X> >));
BOOST_TEST_TRAIT_TRUE((is_tuple_like< std::tuple<X, X, X> >));
BOOST_TEST_TRAIT_TRUE((is_tuple_like<user::Y>));
#endif
return boost::report_errors();
}