// // std_string_ext.hpp // AwesomeAttract0r // // Created by Joshua Moerman on 1/2/12. // Copyright (c) 2012 Vadovas. All rights reserved. // #ifndef AwesomeAttract0r_std_string_ext_hpp #define AwesomeAttract0r_std_string_ext_hpp namespace std { template std::string to_string(T const & x){ std::stringstream ss; ss << x; return ss.str(); } namespace { template struct from_string_struct { T operator()(string const & s){ stringstream ss(s); T t; ss >> t; return t; } }; #define from_string_fund(x, y) \ template <> \ struct from_string_struct { \ x operator()(string const & s){ return y(s); } \ }; from_string_fund(float, stof) from_string_fund(double, stod) from_string_fund(long double, stold) from_string_fund(int, stoi) from_string_fund(long int, stol) from_string_fund(long unsigned int, stoul) from_string_fund(long long int, stoll) from_string_fund(long long unsigned int, stoull) from_string_fund(string, ) #undef from_string_fund } // namespace template T from_string(string const & s){ return from_string_struct()(s); } } #endif