Fix std::string detection hack for SetLabel.

Previously benchmark_api.h wasn't allowed to include standard library
headers. For this reason SetLabel had a hack to accept std::string
without including <string>. The hack worked by attempting to detect
the injected class name `basic_string`. However Clang has changed
it's behavior regarding injected class names so this hack no longer
works.

This patch removes the hack and replaces it with a function that
actually names std::string. However we still cannot pass std::string
across the dylib boundary because of libstdc++'s dual C++11 ABI.
This commit is contained in:
Eric Fiselier 2017-03-10 17:52:02 -07:00
parent 9e34655602
commit 8ae6448cc7

View File

@ -203,19 +203,6 @@ class Benchmark;
class BenchmarkImp;
class BenchmarkFamilies;
template <class T>
struct Voider {
typedef void type;
};
template <class T, class = void>
struct EnableIfString {};
template <class T>
struct EnableIfString<T, typename Voider<typename T::basic_string>::type> {
typedef int type;
};
void UseCharPointer(char const volatile*);
// Take ownership of the pointer and register the benchmark. Return the
@ -432,13 +419,7 @@ class State {
// REQUIRES: a benchmark has exited its KeepRunning loop.
void SetLabel(const char* 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>
void SetLabel(StringType const& str,
typename internal::EnableIfString<StringType>::type = 1) {
void BENCHMARK_ALWAYS_INLINE SetLabel(const std::string& str) {
this->SetLabel(str.c_str());
}