45 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: std-at-least-c++2310 11#include <flat_map>12#include <utility>13 14#include "associative_container_benchmarks.h"15#include "../../GenerateInput.h"16#include "benchmark/benchmark.h"17 18template <class K, class V>19struct support::adapt_operations<std::flat_map<K, V>> {20 using ValueType = typename std::flat_map<K, V>::value_type;21 using KeyType = typename std::flat_map<K, V>::key_type;22 static ValueType value_from_key(KeyType const& k) { return {k, Generate<V>::arbitrary()}; }23 static KeyType key_from_value(ValueType const& value) { return value.first; }24 25 using InsertionResult = std::pair<typename std::flat_map<K, V>::iterator, bool>;26 static auto get_iterator(InsertionResult const& result) { return result.first; }27 28 template <class Allocator>29 using rebind_alloc =30 std::flat_map<K,31 V,32 std::less<K>,33 std::vector<K, typename std::allocator_traits<Allocator>::template rebind_alloc<K>>,34 std::vector<V, typename std::allocator_traits<Allocator>::template rebind_alloc<V>>>;35};36 37int main(int argc, char** argv) {38 support::associative_container_benchmarks<std::flat_map<int, int>>("std::flat_map<int, int>");39 40 benchmark::Initialize(&argc, argv);41 benchmark::RunSpecifiedBenchmarks();42 benchmark::Shutdown();43 return 0;44}45