Ignore:
Timestamp:
May 6, 2013, 9:33:06 PM (12 years ago)
Author:
Frederik Heber <heber@…>
Children:
d3f9ad
Parents:
a2917f
Message:

FIX: clang wants operator<<(.., std::vector<T> ..) to appear before toString() definition that might use it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodePatterns/toString.hpp

    ra2917f r73e948  
    2323#include <set>
    2424#include <vector>
    25 
    26 /** Converter for any class to string.
    27  * We use default conversion via stringstream as suggested by [Stroustrup].
    28  * \param _&_object reference to object to convert to string.
    29  * \return string converted \a _object
    30  */
    31 template <class T> std::string toString(T const &_object)
    32 {
    33   std::stringstream s;
    34   s << _object;
    35   return s.str();
    36 }
    37 
    38 /** Converter for a string to any class
    39  * We use default conversion via stringstream as suggested by [Stroustrup].
    40  * \param _&_object reference to object to convert.
    41  * \return converted \a _object of templated type
    42  */
    43 template <class T> struct ConvertTo {
    44   T operator()(const std::string &_object) {
    45     std::stringstream s;
    46     T object;
    47     s << _object;
    48     s >> object;
    49     return object;
    50   }
    51 };
    5225
    5326
     
    141114}
    142115
     116/** Converter for any class to string.
     117 * We use default conversion via stringstream as suggested by [Stroustrup].
     118 * \param _&_object reference to object to convert to string.
     119 * \return string converted \a _object
     120 */
     121template <class T> std::string toString(T const &_object)
     122{
     123  std::stringstream s;
     124  s << _object;
     125  return s.str();
     126}
     127
     128/** Converter for a string to any class
     129 * We use default conversion via stringstream as suggested by [Stroustrup].
     130 * \param _&_object reference to object to convert.
     131 * \return converted \a _object of templated type
     132 */
     133template <class T> struct ConvertTo {
     134  T operator()(const std::string &_object) {
     135    std::stringstream s;
     136    T object;
     137    s << _object;
     138    s >> object;
     139    return object;
     140  }
     141};
    143142
    144143#endif /* TOSTRING_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.