@@ -31,21 +31,6 @@ struct TestType { enum type {
3131}; };
3232// clang-format on
3333
34- template <class Iterator >
35- using SortFuncPtr = void (*)(Iterator, Iterator);
36-
37- template <class Iterator >
38- static std::unordered_map<SortFunc::type, SortFuncPtr<Iterator>> func_map = {
39- {SortFunc::bubble_sort, alg::bubble_sort },
40- {SortFunc::insertion_sort, alg::insertion_sort},
41- {SortFunc::selection_sort, alg::selection_sort},
42- {SortFunc::heap_sort, alg::heap_sort },
43- {SortFunc::merge_sort, alg::merge_sort },
44- {SortFunc::quick_sort, alg::quick_sort },
45- {SortFunc::std_stable_sort, std::stable_sort },
46- {SortFunc::std_sort, std::sort },
47- };
48-
4934template <class Int >
5035static std::vector<Int> random_int_vector (std::size_t size, Int max = std::numeric_limits<Int>::max()) {
5136 static std::mt19937 gen (std::chrono::high_resolution_clock::now ().time_since_epoch ().count ());
@@ -105,6 +90,20 @@ inline std::vector<std::string> random_vector<std::string>(std::size_t size) {
10590
10691template <class T >
10792static void bm_sort_vector (benchmark::State& state) {
93+ using iterator = typename std::vector<T>::iterator;
94+ using sort_func_ptr = void (*)(iterator, iterator);
95+
96+ static const std::unordered_map<SortFunc::type, sort_func_ptr> func_map = {
97+ {SortFunc::bubble_sort, alg::bubble_sort },
98+ {SortFunc::insertion_sort, alg::insertion_sort},
99+ {SortFunc::selection_sort, alg::selection_sort},
100+ {SortFunc::heap_sort, alg::heap_sort },
101+ {SortFunc::merge_sort, alg::merge_sort },
102+ {SortFunc::quick_sort, alg::quick_sort },
103+ {SortFunc::std_stable_sort, std::stable_sort },
104+ {SortFunc::std_sort, std::sort },
105+ };
106+
108107 static auto vec = random_vector<T>(10000U );
109108 static auto last_test = TestType::shuffled;
110109
@@ -127,7 +126,7 @@ static void bm_sort_vector(benchmark::State& state) {
127126 state.PauseTiming ();
128127 auto tmp = vec;
129128 auto func_as_enum = static_cast <SortFunc::type>(state.range (1 ));
130- auto sort_func = func_map< typename std::vector<T>::iterator>[ func_as_enum] ;
129+ auto sort_func = func_map. find ( func_as_enum)-> second ;
131130 state.ResumeTiming ();
132131
133132 sort_func (tmp.begin (), tmp.end ());
0 commit comments