Skip to content

Instantly share code, notes, and snippets.

/01_compiles.c++ Secret

Created May 28, 2014 13:09
Show Gist options
  • Save anonymous/1fb8824bc81d0a51b5ff to your computer and use it in GitHub Desktop.
Save anonymous/1fb8824bc81d0a51b5ff to your computer and use it in GitHub Desktop.
// ...
inline std::vector<benchmark>& benchmark_registry() {
static std::vector<benchmark> registry;
return registry;
}
struct benchmark_registrar {
template <typename Fun>
benchmark_registrar(std::string name, Fun&& registrant) {
benchmark_registry().emplace_back(std::move(name), std::forward<Fun>(registrant));
}
};
} // namespace nonius
#define NONIUS_BENCHMARK(name, ...) \
namespace { static ::nonius::benchmark_registrar NONIUS_DETAIL_UNIQUE_NAME(benchmark_registrar) (name, __VA_ARGS__); }
// ...
inline std::vector<benchmark>& benchmark_registry() {
static std::vector<benchmark> registry;
return registry;
}
struct benchmark_registrar {
template <typename Fun>
benchmark_registrar(std::vector<benchmark>& registry, std::string name, Fun&& registrant) {
registry.emplace_back(std::move(name), std::forward<Fun>(registrant));
}
};
} // namespace nonius
#define NONIUS_BENCHMARK(name, ...) \
namespace { static ::nonius::benchmark_registrar NONIUS_DETAIL_UNIQUE_NAME(benchmark_registrar) (::nonius::benchmark_registry(), name, __VA_ARGS__); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment