Skip to content

Commit f124bee

Browse files
liyuying0000copybara-github
authored andcommitted
Fix compilation error related to the use of a custom allocator with absl::flat_hash_set in the BM_MoveConstructor function.
PiperOrigin-RevId: 588941578 Change-Id: I79b138d848c29e4b40ce4b68c0c7d6d929db36fe
1 parent 22a7cb2 commit f124bee

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

fleetbench/swissmap/hot_swissmap_benchmark.cc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <algorithm>
1516
#include <cstdint>
1617
#include <memory>
1718
#include <string>
@@ -324,20 +325,37 @@ void BM_SizedConstructor(benchmark::State& state) {
324325
}
325326
}
326327

328+
template <class T>
329+
class CustomAlloc : public std::allocator<T> {
330+
public:
331+
bool unused_ = true; // Force it to not look like std::allocator.
332+
333+
// Default constructor
334+
CustomAlloc() noexcept = default;
335+
336+
// Copy constructor
337+
template <class U>
338+
explicit CustomAlloc(const CustomAlloc<U>&) noexcept {}
339+
340+
// Add the rebind mechanism for the allocator to ensure the custom allocators
341+
// with the correct value type can be used
342+
template <class U>
343+
struct rebind {
344+
typedef CustomAlloc<U> other;
345+
};
346+
};
347+
327348
void BM_MoveConstructor(benchmark::State& state) {
328349
// For now just measure a small cheap hash table since we
329350
// are mostly interested in the overhead of type-erasure
330-
// in resize(). We also use a custom allocator to disble
351+
// in resize(). We also use a custom allocator to disable
331352
// leaking hashtable entries into /hashtablez since we
332353
// do not destroy hash tables.
333354
constexpr int kElements = 64;
334-
class CustomAlloc : public std::allocator<int64_t> {
335-
public:
336-
bool unused_ = true; // Force it to not look like std::allocator.
337-
};
355+
338356
using CheapTable =
339-
absl::flat_hash_set<int64_t, typename IntTable::hasher,
340-
typename IntTable::key_equal, CustomAlloc>;
357+
absl::flat_hash_set<int64_t, IntTable::hasher, IntTable::key_equal,
358+
CustomAlloc<int64_t>>;
341359

342360
// We swap back and forth between two slots, exactly one of which
343361
// holds an CheapTable at any point.

0 commit comments

Comments
 (0)