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
39}
40
41
43
44#endif // CPPUNIT_TOOLS_STRINGHELPER_H
45
#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