quick-bench-front-end icon indicating copy to clipboard operation
quick-bench-front-end copied to clipboard

Allow templated functions in BENCHMARK macro

Open DarkoVeberic opened this issue 3 years ago • 0 comments

Because of the ## magic that you use in the BENCKMARK macro, for the example below I had to introduce two temporary variables TestList and TestDeque to pass them into the macro:

#include <list>
#include <deque>

template<class Container>
static
void
Test(benchmark::State& state)
{
  Container x;
  for (auto _ : state) {
    x.push_back(i);
    x.push_front(i);
    x.pop_back();
    x.pop_front();
  }
}

const auto TestList = Test<std::list<int>>;
const auto TestDeque = Test<std::deque<int>>;

BENCHMARK(TestList);
BENCHMARK(TestDeque);

It would be nice if I could simply write:

BENCHMARK(Test<std::list<int>>);
BENCHMARK(Test<std::deque<int>>);

DarkoVeberic avatar Mar 26 '21 11:03 DarkoVeberic