From 858688b845b86dc43a7e23f8ec0f94a8e63bfe20 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 21 Feb 2018 00:54:19 -0700 Subject: [PATCH] Ensure std::iterator_traits instantiates. Due to ADL lookup performed on the begin and end functions of `for (auto _ : State)`, std::iterator_traits may get incidentally instantiated. This patch ensures the library can tolerate that. --- include/benchmark/benchmark.h | 1 + test/basic_test.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 5fed767d..1eeaef64 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -669,6 +669,7 @@ struct State::StateIterator { typedef Value value_type; typedef Value reference; typedef Value pointer; + typedef std::ptrdiff_t difference_type; private: friend class State; diff --git a/test/basic_test.cc b/test/basic_test.cc index 12579c09..100f6898 100644 --- a/test/basic_test.cc +++ b/test/basic_test.cc @@ -126,4 +126,10 @@ void BM_RangedFor(benchmark::State& state) { } BENCHMARK(BM_RangedFor); +// Ensure that StateIterator provides all the necessary typedefs required to +// instantiate std::iterator_traits. +static_assert(std::is_same< + typename std::iterator_traits::value_type, + typename benchmark::State::StateIterator::value_type>::value, ""); + BENCHMARK_MAIN();