mirror of
https://github.com/google/benchmark.git
synced 2025-02-05 16:50:34 +08:00
* Fix #444 - Use BENCHMARK_HAS_CXX11 over __cplusplus. MSVC incorrectly defines __cplusplus to report C++03, despite the compiler actually providing C++11 or greater. Therefore we have to detect C++11 differently for MSVC. This patch uses `_MSVC_LANG` which has been defined since Visual Studio 2015 Update 3; which should be sufficient for detecting C++11. Secondly this patch changes over most usages of __cplusplus >= 201103L to check BENCHMARK_HAS_CXX11 instead. * remove redunant comment
This commit is contained in:
parent
2a05f248be
commit
6d8339dd97
@ -185,7 +185,7 @@ BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10);
|
||||
Three macros are provided for adding benchmark templates.
|
||||
|
||||
```c++
|
||||
#if __cplusplus >= 201103L // C++11 and greater.
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
#define BENCHMARK_TEMPLATE(func, ...) // Takes any number of parameters.
|
||||
#else // C++ < C++11
|
||||
#define BENCHMARK_TEMPLATE(func, arg1)
|
||||
|
@ -164,7 +164,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
|
||||
#define BENCHMARK_BENCHMARK_H_
|
||||
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
// The _MSVC_LANG check should detect Visual Studio 2015 Update 3 and newer.
|
||||
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
|
||||
#define BENCHMARK_HAS_CXX11
|
||||
#endif
|
||||
|
||||
@ -921,7 +922,7 @@ class Fixture : public internal::Benchmark {
|
||||
#define BENCHMARK_RANGE2(n, l1, h1, l2, h2) \
|
||||
BENCHMARK(n)->RangePair({{(l1), (h1)}, {(l2), (h2)}})
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
|
||||
// Register a benchmark which invokes the function specified by `func`
|
||||
// with the additional arguments specified by `...`.
|
||||
@ -941,7 +942,7 @@ class Fixture : public internal::Benchmark {
|
||||
#func "/" #test_case_name, \
|
||||
[](::benchmark::State& st) { func(st, __VA_ARGS__); })))
|
||||
|
||||
#endif // __cplusplus >= 11
|
||||
#endif // BENCHMARK_HAS_CXX11
|
||||
|
||||
// This will register a benchmark for a templatized function. For example:
|
||||
//
|
||||
@ -962,7 +963,7 @@ class Fixture : public internal::Benchmark {
|
||||
new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", \
|
||||
n<a, b>)))
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
#define BENCHMARK_TEMPLATE(n, ...) \
|
||||
BENCHMARK_PRIVATE_DECLARE(n) = \
|
||||
(::benchmark::internal::RegisterBenchmarkInternal( \
|
||||
|
@ -109,7 +109,7 @@ BENCHMARK_TEMPLATE2(BM_Sequential, std::vector<int>, int)
|
||||
->Range(1 << 0, 1 << 10);
|
||||
BENCHMARK_TEMPLATE(BM_Sequential, std::list<int>)->Range(1 << 0, 1 << 10);
|
||||
// Test the variadic version of BENCHMARK_TEMPLATE in C++11 and beyond.
|
||||
#if __cplusplus >= 201103L
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
BENCHMARK_TEMPLATE(BM_Sequential, std::vector<int>, int)->Arg(512);
|
||||
#endif
|
||||
|
||||
@ -197,7 +197,7 @@ static void BM_ManualTiming(benchmark::State& state) {
|
||||
BENCHMARK(BM_ManualTiming)->Range(1, 1 << 14)->UseRealTime();
|
||||
BENCHMARK(BM_ManualTiming)->Range(1, 1 << 14)->UseManualTime();
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
|
||||
template <class... Args>
|
||||
void BM_with_args(benchmark::State& state, Args&&...) {
|
||||
@ -213,7 +213,7 @@ void BM_non_template_args(benchmark::State& state, int, double) {
|
||||
}
|
||||
BENCHMARK_CAPTURE(BM_non_template_args, basic_test, 0, 0);
|
||||
|
||||
#endif // __cplusplus >= 201103L
|
||||
#endif // BENCHMARK_HAS_CXX11
|
||||
|
||||
static void BM_DenseThreadRanges(benchmark::State& st) {
|
||||
switch (st.range(0)) {
|
||||
|
@ -8,6 +8,10 @@
|
||||
#error C++11 or greater detected. Should be C++03.
|
||||
#endif
|
||||
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
#error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
|
||||
#endif
|
||||
|
||||
void BM_empty(benchmark::State& state) {
|
||||
while (state.KeepRunning()) {
|
||||
volatile std::size_t x = state.iterations();
|
||||
|
Loading…
Reference in New Issue
Block a user