CppUnit project page FAQ

StringHelper.h
Go to the documentation of this file.
1#ifndef CPPUNIT_TOOLS_STRINGHELPER_H
2#define CPPUNIT_TOOLS_STRINGHELPER_H
3
6#include <string>
7#include <type_traits>
8
9
11
12
15namespace StringHelper
16{
17
18// work around to handle C++11 enum class correctly. We need an own conversion to std::string
19// as there is no implicit coversion to int for enum class.
20
21template<typename T>
22typename std::enable_if<!std::is_enum<T>::value, std::string>::type toString(const T& x)
23{
24 OStringStream ost;
25 ost << x;
26
27 return ost.str();
28}
29
30template<typename T>
31typename std::enable_if<std::is_enum<T>::value, std::string>::type toString(const T& x)
32{
33 OStringStream ost;
34 ost << static_cast<typename std::underlying_type<T>::type>(x);
35
36 return ost.str();
37}
38
39template<> inline std::string toString(const signed char& x)
40{
41 return toString(static_cast<int>(x));
42}
43
44template<> inline std::string toString(const unsigned char& x)
45{
46 return toString(static_cast<unsigned int>(x));
47}
48
49}
50
51
53
54#endif // CPPUNIT_TOOLS_STRINGHELPER_H
55
#define CPPUNIT_NS_END
Definition Portability.h:106
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
Methods for converting values to strings. Replaces CPPUNIT_NS::StringTools::toString.
Definition StringHelper.h:16
std::enable_if<!std::is_enum< T >::value, std::string >::type toString(const T &x)
Definition StringHelper.h:22

Send comments to:
CppUnit Developers