mirror of https://github.com/google/benchmark.git
Expand documentation for unpacking arbitrary arguments. (#1324)
Fixes #1123
This commit is contained in:
parent
6cf20f1e02
commit
00e2211052
|
@ -436,13 +436,22 @@ The `test_case_name` is appended to the name of the benchmark and
|
|||
should describe the values passed.
|
||||
|
||||
```c++
|
||||
template <class ...ExtraArgs>
|
||||
void BM_takes_args(benchmark::State& state, ExtraArgs&&... extra_args) {
|
||||
[...]
|
||||
template <class ...Args>
|
||||
void BM_takes_args(benchmark::State& state, Args&&... args) {
|
||||
auto args_tuple = std::make_tuple(std::move(args)...);
|
||||
for (auto _ : state) {
|
||||
std::cout << std::get<0>(args_tuple) << ": " << std::get<1>(args_tuple)
|
||||
<< '\n';
|
||||
[...]
|
||||
}
|
||||
}
|
||||
// Registers a benchmark named "BM_takes_args/int_string_test" that passes
|
||||
// the specified values to `extra_args`.
|
||||
// the specified values to `args`.
|
||||
BENCHMARK_CAPTURE(BM_takes_args, int_string_test, 42, std::string("abc"));
|
||||
|
||||
// Registers the same benchmark "BM_takes_args/int_test" that passes
|
||||
// the specified values to `args`.
|
||||
BENCHMARK_CAPTURE(BM_takes_args, int_test, 42, 43);
|
||||
```
|
||||
|
||||
Note that elements of `...args` may refer to global variables. Users should
|
||||
|
|
Loading…
Reference in New Issue