Simplify benchmark_base::set_printer API.

Forcing the caller to use `std::ref` is gross.
This commit is contained in:
Allison Vacanti
2021-06-23 17:01:13 -04:00
parent 5fab2536e5
commit e84e13ed51
2 changed files with 10 additions and 7 deletions

View File

@@ -23,7 +23,7 @@
#include <nvbench/device_manager.cuh>
#include <nvbench/state.cuh>
#include <functional> // reference_wrapper
#include <functional> // reference_wrapper, ref
#include <memory>
#include <optional>
#include <vector>
@@ -153,9 +153,14 @@ struct benchmark_base
void run() { this->do_run(); }
void set_printer(optional_ref<nvbench::printer_base> printer)
void set_printer(nvbench::printer_base& printer)
{
m_printer = printer;
m_printer = std::ref(printer);
}
void clear_printer()
{
m_printer = std::nullopt;
}
[[nodiscard]] optional_ref<nvbench::printer_base> get_printer() const

View File

@@ -24,9 +24,7 @@
#include <nvbench/option_parser.cuh>
#include <nvbench/printer_base.cuh>
#include <functional> // std::ref
#include <iostream>
#include <optional> // std::nullopt
#define NVBENCH_MAIN \
int main(int argc, char const *const *argv) \
@@ -59,9 +57,9 @@
auto &benchmarks = parser.get_benchmarks(); \
for (auto &bench_ptr : benchmarks) \
{ \
bench_ptr->set_printer(std::ref(printer)); \
bench_ptr->set_printer(printer); \
bench_ptr->run(); \
bench_ptr->set_printer(std::nullopt); \
bench_ptr->clear_printer(); \
} \
printer.print_log_epilogue(); \
printer.print_benchmark_results(benchmarks); \