Skip to content

Commit 809b7a3

Browse files
committed
Also test std::hash with bitsets having equal underlying vectors
This makes sure the size of the bitset is taken into account in the calculation of the hash value.
1 parent caee95b commit 809b7a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/test_std_hash.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (C) 2019 James E. King III
3+
// Copyright (C) 2025 Gennaro Prota
34
//
45
// Distributed under the Boost Software License, Version 1.0. (See
56
// accompanying file LICENSE_1_0.txt or copy at
@@ -17,16 +18,23 @@ main( int, char *[] )
1718
const std::string long_string =
1819
"01001110101110110101011010000000000011110101101111111111";
1920

21+
// Some bitsets with the same size but different underlying vectors.
2022
const bitset_type zeroes( long_string.size(), 0 );
2123
const bitset_type stuff( long_string );
2224
const bitset_type one( long_string.size(), 1 );
2325

26+
// Some bitsets with different sizes but equal underlying vectors.
27+
const bitset_type zeroes2( 2, 0 );
28+
const bitset_type zeroes3( 3, 0 );
29+
2430
std::unordered_set< bitset_type > bitsets;
2531
bitsets.insert( zeroes );
2632
bitsets.insert( stuff );
2733
bitsets.insert( one );
34+
bitsets.insert( zeroes2 );
35+
bitsets.insert( zeroes3 );
2836

29-
BOOST_TEST_EQ( bitsets.size(), 3 );
37+
BOOST_TEST_EQ( bitsets.size(), 5 );
3038

3139
return boost::report_errors();
3240
}

0 commit comments

Comments
 (0)