lundi 14 mai 2018

Value to std::string while keeping backwards compatibility

Simple utility function to convert a value to std::string while keeping backwards compatibility.
Probably a silly question, but I'm curious to hear some opinions about it or if there is any flows in doing so this way:

     template<typename T>
     std::string toString(T parm)
     {
#ifdef IFW_CXX11_AVAILABLE
         return std::to_string(parm);
#else
         std::ostringstream stream;
         stream << parm;

         return stream.str();
#endif
     }

Will it create a copy in memory if I do it so?
Thanks in advance for your answers :)

Aucun commentaire:

Enregistrer un commentaire