Expand documentation for unpacking arbitrary arguments. (#1324)

Fixes #1123
This commit is contained in:
Dominic Hamon 2022-01-17 13:54:56 +00:00 committed by GitHub
parent 6cf20f1e02
commit 00e2211052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -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