00001 #ifndef CPPUNIT_TOOLS_STRINGHELPER_H
00002 #define CPPUNIT_TOOLS_STRINGHELPER_H
00003
00004 #include <cppunit/Portability.h>
00005 #include <cppunit/portability/Stream.h>
00006 #include <string>
00007 #include <type_traits>
00008
00009
00010 CPPUNIT_NS_BEGIN
00011
00012
00015 namespace StringHelper
00016 {
00017
00018
00019
00020
00021 template<typename T>
00022 typename std::enable_if<!std::is_enum<T>::value, std::string>::type toString(const T& x)
00023 {
00024 OStringStream ost;
00025 ost << x;
00026
00027 return ost.str();
00028 }
00029
00030 template<typename T>
00031 typename std::enable_if<std::is_enum<T>::value, std::string>::type toString(const T& x)
00032 {
00033 OStringStream ost;
00034 ost << static_cast<typename std::underlying_type<T>::type>(x);
00035
00036 return ost.str();
00037 }
00038
00039 }
00040
00041
00042 CPPUNIT_NS_END
00043
00044 #endif // CPPUNIT_TOOLS_STRINGHELPER_H
00045