Ensure std::iterator_traits<StateIterator> 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.
This commit is contained in:
Eric Fiselier 2018-02-21 00:54:19 -07:00
parent 6ecf8a8e80
commit 858688b845
2 changed files with 7 additions and 0 deletions

View File

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

View File

@ -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<benchmark::State::StateIterator>::value_type,
typename benchmark::State::StateIterator::value_type>::value, "");
BENCHMARK_MAIN();