mirror of
https://github.com/google/benchmark.git
synced 2025-03-30 14:10:25 +08:00
Allow use of std::string in State
This commit is contained in:
parent
6fbdcfd2d9
commit
bcd0f996b2
@ -311,6 +311,17 @@ public:
|
||||
::benchmark::SetLabel(label);
|
||||
}
|
||||
|
||||
// Allow the use of std::string without actually including <string>.
|
||||
// This function does not participate in overload resolution unless StringType
|
||||
// has the nested typename `basic_string`. This typename should be provided
|
||||
// as an injected class name in the case of std::string.
|
||||
template <class StringType>
|
||||
BENCHMARK_ALWAYS_INLINE
|
||||
void SetLabel(StringType const & str,
|
||||
typename StringType::basic_string* = 0) {
|
||||
::benchmark::SetLabel(str.c_str());
|
||||
}
|
||||
|
||||
// Range arguments for this run. CHECKs if the argument has been set.
|
||||
BENCHMARK_ALWAYS_INLINE
|
||||
int range_x() const {
|
||||
|
@ -69,7 +69,9 @@ static void BM_CalculatePiRange(benchmark::State& state) {
|
||||
pi = CalculatePi(state.range_x());
|
||||
std::stringstream ss;
|
||||
ss << pi;
|
||||
// Test both overloads of SetLabel to ensure they work.
|
||||
state.SetLabel(ss.str().c_str());
|
||||
state.SetLabel(ss.str());
|
||||
}
|
||||
BENCHMARK_RANGE(BM_CalculatePiRange, 1, 1024 * 1024);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user