Add a generic to_string() function.

This commit is contained in:
Niclas Antti
2019-04-18 20:02:54 +03:00
parent 8b7b7b4d3f
commit e331b7f432

View File

@ -28,6 +28,20 @@
*/
const char* mxb_strerror(int error);
/**
* Generate std::string to_string(const T&) for any type T for which there is a
* function std::ostream& operator<<(std::ostream&, const T&) declared.
*/
template<class T,
typename std::remove_reference<decltype(operator<<(*(std::ostream*)(0), *(T*)(0)))>::type* =
nullptr>
std::string to_string(const T& t)
{
std::ostringstream os;
os << t;
return os.str();
}
namespace maxbase
{