|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +#include <algorithm> |
15 | 16 | #include <cstdint> |
16 | 17 | #include <memory> |
17 | 18 | #include <string> |
@@ -324,20 +325,37 @@ void BM_SizedConstructor(benchmark::State& state) { |
324 | 325 | } |
325 | 326 | } |
326 | 327 |
|
| 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 | + |
327 | 348 | void BM_MoveConstructor(benchmark::State& state) { |
328 | 349 | // For now just measure a small cheap hash table since we |
329 | 350 | // 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 |
331 | 352 | // leaking hashtable entries into /hashtablez since we |
332 | 353 | // do not destroy hash tables. |
333 | 354 | 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 | + |
338 | 356 | 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>>; |
341 | 359 |
|
342 | 360 | // We swap back and forth between two slots, exactly one of which |
343 | 361 | // holds an CheapTable at any point. |
|
0 commit comments