mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
catch_tostring: tostring for enum class types
This commit is contained in:
parent
142f8f4b1e
commit
cd2a5aa688
@ -22,6 +22,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
// Why we're here.
|
||||||
|
template<typename T>
|
||||||
|
std::string toString( T const& value );
|
||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
|
|
||||||
// SFINAE is currently disabled by default for all compilers.
|
// SFINAE is currently disabled by default for all compilers.
|
||||||
@ -64,10 +69,38 @@ namespace Detail {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CATCH_CPP11_OR_GREATER)
|
||||||
|
template<typename T,
|
||||||
|
bool IsEmum = std::is_enum<T>::value
|
||||||
|
>
|
||||||
|
struct EnumStringMaker
|
||||||
|
{
|
||||||
|
static std::string convert( T const& ) { return "{?}"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct EnumStringMaker<T,true>
|
||||||
|
{
|
||||||
|
static std::string convert( T const& v )
|
||||||
|
{
|
||||||
|
return ::Catch::toString(
|
||||||
|
static_cast<typename std::underlying_type<T>::type>(v)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
template<bool C>
|
template<bool C>
|
||||||
struct StringMakerBase {
|
struct StringMakerBase {
|
||||||
|
#if defined(CATCH_CPP11_OR_GREATER)
|
||||||
|
template<typename T>
|
||||||
|
static std::string convert( T const& v )
|
||||||
|
{
|
||||||
|
return EnumStringMaker<T>::convert( v );
|
||||||
|
}
|
||||||
|
#else
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static std::string convert( T const& ) { return "{?}"; }
|
static std::string convert( T const& ) { return "{?}"; }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
@ -89,9 +122,6 @@ namespace Detail {
|
|||||||
|
|
||||||
} // end namespace Detail
|
} // end namespace Detail
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
std::string toString( T const& value );
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct StringMaker :
|
struct StringMaker :
|
||||||
Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
|
Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
|
||||||
|
Loading…
Reference in New Issue
Block a user