Eric Fiselier | c52db21 | 2019-08-12 07:51:05 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Nico Weber | fa647f8 | 2019-08-21 01:59:12 +0000 | [diff] [blame^] | 10 | #ifndef BENCHMARK_UTILITIES_H |
| 11 | #define BENCHMARK_UTILITIES_H |
Eric Fiselier | c52db21 | 2019-08-12 07:51:05 +0000 | [diff] [blame] | 12 | |
| 13 | #include <cassert> |
| 14 | #include <type_traits> |
| 15 | |
| 16 | #include "benchmark/benchmark.h" |
| 17 | |
| 18 | namespace UtilitiesInternal { |
| 19 | template <class Container> |
| 20 | auto HaveDataImpl(int) -> decltype((std::declval<Container&>().data(), std::true_type{})); |
| 21 | template <class Container> |
| 22 | auto HaveDataImpl(long) -> std::false_type; |
| 23 | template <class T> |
| 24 | using HasData = decltype(HaveDataImpl<T>(0)); |
| 25 | } // namespace UtilitiesInternal |
| 26 | |
| 27 | template <class Container, std::enable_if_t<UtilitiesInternal::HasData<Container>::value>* = nullptr> |
| 28 | void DoNotOptimizeData(Container &c) { benchmark::DoNotOptimize(c.data()); } |
| 29 | template <class Container, std::enable_if_t<!UtilitiesInternal::HasData<Container>::value>* = nullptr> |
| 30 | void DoNotOptimizeData(Container &c) { benchmark::DoNotOptimize(&c); } |
| 31 | |
| 32 | |
Nico Weber | fa647f8 | 2019-08-21 01:59:12 +0000 | [diff] [blame^] | 33 | #endif // BENCHMARK_UTILITIES_H |