Changeset 73e948 for src/CodePatterns/toString.hpp
- Timestamp:
- May 6, 2013, 9:33:06 PM (12 years ago)
- Children:
- d3f9ad
- Parents:
- a2917f
- File:
-
- 1 edited
-
src/CodePatterns/toString.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodePatterns/toString.hpp
ra2917f r73e948 23 23 #include <set> 24 24 #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 _object30 */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 class39 * 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 type42 */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 };52 25 53 26 … … 141 114 } 142 115 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 */ 121 template <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 */ 133 template <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 }; 143 142 144 143 #endif /* TOSTRING_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.
