mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Move back to static StringMaker<T>::convert
This avoids some breakage from the modernization
This commit is contained in:
parent
31f5e2ed81
commit
67914d8b86
@ -25,7 +25,7 @@ If you don't want to provide an ```operator <<``` overload, or you want to conve
|
||||
namespace Catch {
|
||||
template<>
|
||||
struct StringMaker<T> {
|
||||
std::string operator()( T const& value ) {
|
||||
static std::string convert( T const& value ) {
|
||||
return convertMyTypeToString( value );
|
||||
}
|
||||
};
|
||||
|
@ -128,7 +128,7 @@ namespace Detail {
|
||||
|
||||
template<>
|
||||
struct StringMaker<Catch::Detail::Approx> {
|
||||
std::string operator()(Catch::Detail::Approx const& value) {
|
||||
static std::string convert(Catch::Detail::Approx const& value) {
|
||||
return value.toString();
|
||||
}
|
||||
};
|
||||
|
@ -61,16 +61,18 @@ namespace Catch {
|
||||
template <typename T>
|
||||
struct StringMaker {
|
||||
template <typename Fake = T>
|
||||
static
|
||||
typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
|
||||
operator()(const Fake& t) {
|
||||
convert(const Fake& t) {
|
||||
std::stringstream sstr;
|
||||
sstr << t;
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
template <typename Fake = T>
|
||||
static
|
||||
typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
|
||||
operator()(const Fake&) {
|
||||
convert(const Fake&) {
|
||||
return "{?}";
|
||||
}
|
||||
};
|
||||
@ -83,7 +85,7 @@ namespace Catch {
|
||||
// Should be preferably called fully qualified, like ::Catch::Detail::stringify
|
||||
template <typename T>
|
||||
std::string stringify(const T& e) {
|
||||
return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>{}(e);
|
||||
return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
|
||||
}
|
||||
|
||||
} // namespace Detail
|
||||
@ -93,110 +95,110 @@ namespace Catch {
|
||||
|
||||
template<>
|
||||
struct StringMaker<std::string> {
|
||||
std::string operator()(const std::string& str);
|
||||
static std::string convert(const std::string& str);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<std::wstring> {
|
||||
std::string operator()(const std::wstring& wstr);
|
||||
static std::string convert(const std::wstring& wstr);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<char const *> {
|
||||
std::string operator()(char const * str);
|
||||
static std::string convert(char const * str);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<char *> {
|
||||
std::string operator()(char * str);
|
||||
static std::string convert(char * str);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<wchar_t const *> {
|
||||
std::string operator()(wchar_t const * str);
|
||||
static std::string convert(wchar_t const * str);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<wchar_t *> {
|
||||
std::string operator()(wchar_t * str);
|
||||
static std::string convert(wchar_t * str);
|
||||
};
|
||||
|
||||
template<int SZ>
|
||||
struct StringMaker<char[SZ]> {
|
||||
std::string operator()(const char* str) {
|
||||
static std::string convert(const char* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
struct StringMaker<signed char[SZ]> {
|
||||
std::string operator()(const char* str) {
|
||||
static std::string convert(const char* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
struct StringMaker<unsigned char[SZ]> {
|
||||
std::string operator()(const char* str) {
|
||||
static std::string convert(const char* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<int> {
|
||||
std::string operator()(int value);
|
||||
static std::string convert(int value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<long> {
|
||||
std::string operator()(long value);
|
||||
static std::string convert(long value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<long long> {
|
||||
std::string operator()(long long value);
|
||||
static std::string convert(long long value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<unsigned int> {
|
||||
std::string operator()(unsigned int value);
|
||||
static std::string convert(unsigned int value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<unsigned long> {
|
||||
std::string operator()(unsigned long value);
|
||||
static std::string convert(unsigned long value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<unsigned long long> {
|
||||
std::string operator()(unsigned long long value);
|
||||
static std::string convert(unsigned long long value);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<bool> {
|
||||
std::string operator()(bool b);
|
||||
static std::string convert(bool b);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<char> {
|
||||
std::string operator()(char c);
|
||||
static std::string convert(char c);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<signed char> {
|
||||
std::string operator()(signed char c);
|
||||
static std::string convert(signed char c);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<unsigned char> {
|
||||
std::string operator()(unsigned char c);
|
||||
static std::string convert(unsigned char c);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<std::nullptr_t> {
|
||||
std::string operator()(std::nullptr_t);
|
||||
static std::string convert(std::nullptr_t);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct StringMaker<float> {
|
||||
std::string operator()(float value);
|
||||
static std::string convert(float value);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<double> {
|
||||
std::string operator()(double value);
|
||||
static std::string convert(double value);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct StringMaker<T*> {
|
||||
template <typename U>
|
||||
std::string operator()(U* p) {
|
||||
static std::string convert(U* p) {
|
||||
if (p) {
|
||||
return ::Catch::Detail::rawMemoryToString(p);
|
||||
} else {
|
||||
@ -207,7 +209,7 @@ namespace Catch {
|
||||
|
||||
template <typename R, typename C>
|
||||
struct StringMaker<R C::*> {
|
||||
std::string operator()(R C::* p) {
|
||||
static std::string convert(R C::* p) {
|
||||
if (p) {
|
||||
return ::Catch::Detail::rawMemoryToString(p);
|
||||
} else {
|
||||
@ -233,7 +235,7 @@ namespace Catch {
|
||||
|
||||
template<typename T, typename Allocator>
|
||||
struct StringMaker<std::vector<T, Allocator> > {
|
||||
std::string operator()( std::vector<T,Allocator> const& v ) {
|
||||
static std::string convert( std::vector<T,Allocator> const& v ) {
|
||||
return ::Catch::Detail::rangeToString( v.begin(), v.end() );
|
||||
}
|
||||
};
|
||||
@ -241,7 +243,7 @@ namespace Catch {
|
||||
// === Pair ===
|
||||
template<typename T1, typename T2>
|
||||
struct StringMaker<std::pair<T1, T2> > {
|
||||
std::string operator()(const std::pair<T1, T2>& pair) {
|
||||
static std::string convert(const std::pair<T1, T2>& pair) {
|
||||
std::ostringstream oss;
|
||||
oss << "{ "
|
||||
<< ::Catch::Detail::stringify(pair.first)
|
||||
@ -281,7 +283,7 @@ namespace Catch {
|
||||
|
||||
template<typename ...Types>
|
||||
struct StringMaker<std::tuple<Types...>> {
|
||||
std::string operator()(const std::tuple<Types...>& tuple) {
|
||||
static std::string convert(const std::tuple<Types...>& tuple) {
|
||||
std::ostringstream os;
|
||||
os << '{';
|
||||
Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, os);
|
||||
@ -293,7 +295,7 @@ namespace Catch {
|
||||
|
||||
template<typename T>
|
||||
struct EnumStringMaker {
|
||||
std::string operator()(const T& t) {
|
||||
static std::string convert(const T& t) {
|
||||
return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<T>::type>(t));
|
||||
}
|
||||
};
|
||||
@ -301,15 +303,15 @@ namespace Catch {
|
||||
#ifdef __OBJC__
|
||||
template<>
|
||||
struct StringMaker<NSString const *> {
|
||||
std::string operator()(NSString const* const& nsstring);
|
||||
static std::string convert(NSString const* const& nsstring);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<NSString * CATCH_ARC_STRONG> {
|
||||
std::string operator()(NSString * CATCH_ARC_STRONG const& nsstring);
|
||||
static std::string convert(NSString * CATCH_ARC_STRONG const& nsstring);
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<NSObject *> {
|
||||
std::string operator()(NSObject* const& nsObject);
|
||||
static std::string convert(NSObject* const& nsObject);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -76,7 +76,7 @@ std::string fpToString( T value, int precision ) {
|
||||
//
|
||||
//// ======================================================= ////
|
||||
|
||||
std::string StringMaker<std::string>::operator()(const std::string& str) {
|
||||
std::string StringMaker<std::string>::convert(const std::string& str) {
|
||||
if (!getCurrentContext().getConfig()->showInvisibles()) {
|
||||
return '"' + str + '"';
|
||||
}
|
||||
@ -99,7 +99,7 @@ std::string StringMaker<std::string>::operator()(const std::string& str) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string StringMaker<std::wstring>::operator()(const std::wstring& wstr) {
|
||||
std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
|
||||
std::string s;
|
||||
s.reserve(wstr.size());
|
||||
for (auto c : wstr) {
|
||||
@ -108,28 +108,28 @@ std::string StringMaker<std::wstring>::operator()(const std::wstring& wstr) {
|
||||
return ::Catch::Detail::stringify(s);
|
||||
}
|
||||
|
||||
std::string StringMaker<char const*>::operator()(char const* str) {
|
||||
std::string StringMaker<char const*>::convert(char const* str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
} else {
|
||||
return{ "{null string}" };
|
||||
}
|
||||
}
|
||||
std::string StringMaker<char*>::operator()(char* str) {
|
||||
std::string StringMaker<char*>::convert(char* str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
} else {
|
||||
return{ "{null string}" };
|
||||
}
|
||||
}
|
||||
std::string StringMaker<wchar_t const*>::operator()(wchar_t const * str) {
|
||||
std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::wstring{ str });
|
||||
} else {
|
||||
return{ "{null string}" };
|
||||
}
|
||||
}
|
||||
std::string StringMaker<wchar_t *>::operator()(wchar_t * str) {
|
||||
std::string StringMaker<wchar_t *>::convert(wchar_t * str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::wstring{ str });
|
||||
} else {
|
||||
@ -138,13 +138,13 @@ std::string StringMaker<wchar_t *>::operator()(wchar_t * str) {
|
||||
}
|
||||
|
||||
|
||||
std::string StringMaker<int>::operator()(int value) {
|
||||
std::string StringMaker<int>::convert(int value) {
|
||||
return ::Catch::Detail::stringify(static_cast<long long>(value));
|
||||
}
|
||||
std::string StringMaker<long>::operator()(long value) {
|
||||
std::string StringMaker<long>::convert(long value) {
|
||||
return ::Catch::Detail::stringify(static_cast<long long>(value));
|
||||
}
|
||||
std::string StringMaker<long long>::operator()(long long value) {
|
||||
std::string StringMaker<long long>::convert(long long value) {
|
||||
std::ostringstream oss;
|
||||
oss << value;
|
||||
if (value > Detail::hexThreshold) {
|
||||
@ -153,13 +153,13 @@ std::string StringMaker<long long>::operator()(long long value) {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string StringMaker<unsigned int>::operator()(unsigned int value) {
|
||||
std::string StringMaker<unsigned int>::convert(unsigned int value) {
|
||||
return ::Catch::Detail::stringify(static_cast<unsigned long long>(value));
|
||||
}
|
||||
std::string StringMaker<unsigned long>::operator()(unsigned long value) {
|
||||
std::string StringMaker<unsigned long>::convert(unsigned long value) {
|
||||
return ::Catch::Detail::stringify(static_cast<unsigned long long>(value));
|
||||
}
|
||||
std::string StringMaker<unsigned long long>::operator()(unsigned long long value) {
|
||||
std::string StringMaker<unsigned long long>::convert(unsigned long long value) {
|
||||
std::ostringstream oss;
|
||||
oss << value;
|
||||
if (value > Detail::hexThreshold) {
|
||||
@ -169,11 +169,11 @@ std::string StringMaker<unsigned long long>::operator()(unsigned long long value
|
||||
}
|
||||
|
||||
|
||||
std::string StringMaker<bool>::operator()(bool b) {
|
||||
std::string StringMaker<bool>::convert(bool b) {
|
||||
return b ? "true" : "false";
|
||||
}
|
||||
|
||||
std::string StringMaker<char>::operator()(char value) {
|
||||
std::string StringMaker<char>::convert(char value) {
|
||||
if (value == '\r') {
|
||||
return "'\\r'";
|
||||
} else if (value == '\f') {
|
||||
@ -190,37 +190,37 @@ std::string StringMaker<char>::operator()(char value) {
|
||||
return chstr;
|
||||
}
|
||||
}
|
||||
std::string StringMaker<signed char>::operator()(signed char c) {
|
||||
std::string StringMaker<signed char>::convert(signed char c) {
|
||||
return ::Catch::Detail::stringify(static_cast<char>(c));
|
||||
}
|
||||
std::string StringMaker<unsigned char>::operator()(unsigned char c) {
|
||||
std::string StringMaker<unsigned char>::convert(unsigned char c) {
|
||||
return ::Catch::Detail::stringify(static_cast<char>(c));
|
||||
}
|
||||
|
||||
std::string StringMaker<std::nullptr_t>::operator()(std::nullptr_t) {
|
||||
std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) {
|
||||
return "nullptr";
|
||||
}
|
||||
|
||||
std::string StringMaker<float>::operator()(float value) {
|
||||
std::string StringMaker<float>::convert(float value) {
|
||||
return fpToString(value, 5) + 'f';
|
||||
}
|
||||
std::string StringMaker<double>::operator()(double value) {
|
||||
std::string StringMaker<double>::convert(double value) {
|
||||
return fpToString(value, 10);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __OBJC__
|
||||
std::string StringMaker<NSString const *>::operator()(NSString const * const& nsstring) {
|
||||
std::string StringMaker<NSString const *>::convert(NSString const * const& nsstring) {
|
||||
if (!nsstring)
|
||||
return "nil";
|
||||
return "@" + toString([nsstring UTF8String]);
|
||||
}
|
||||
std::string StringMaker<NSString * CATCH_ARC_STRONG>::operator()(NSString * CATCH_ARC_STRONG const& nsstring) {
|
||||
std::string StringMaker<NSString * CATCH_ARC_STRONG>::convert(NSString * CATCH_ARC_STRONG const& nsstring) {
|
||||
if (!nsstring)
|
||||
return "nil";
|
||||
return "@" + toString([nsstring UTF8String]);
|
||||
}
|
||||
std::string StringMaker<NSObject *>::operator()(NSObject * const& nsObject) {
|
||||
std::string StringMaker<NSObject *>::convert(NSObject * const& nsObject) {
|
||||
return ::Catch::Detail::stringify([nsObject description]);
|
||||
}
|
||||
#endif
|
||||
|
@ -22,13 +22,13 @@ std::ostream& operator<<(std::ostream& os, const has_maker_and_operator&) {
|
||||
namespace Catch {
|
||||
template<>
|
||||
struct StringMaker<has_maker> {
|
||||
std::string operator()( const has_maker& ) {
|
||||
static std::string convert( const has_maker& ) {
|
||||
return "StringMaker<has_maker>";
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<has_maker_and_operator> {
|
||||
std::string operator()( const has_maker_and_operator& ) {
|
||||
static std::string convert( const has_maker_and_operator& ) {
|
||||
return "StringMaker<has_maker_and_operator>";
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user