I'm not going to guess why overloading is not part of the standard library, but here is a simple solution that you can use. Instead of std::to_string use boost::lexical_cast .
template <typename T> int read(T nameOrIndex) { if (!present(nameOrIndex)) { throw std::invalid_argument { "Missing row: " + boost::lexical_cast<std::string>(nameOrIndex) }; }
If you don't need a Boost dependency, you can easily collapse your own function for this.
template <typename T> std::string to_string(const T& obj) { std::ostringstream oss {}; oss << obj; return oss.str(); }
Obviously, it is not optimized, but may be good enough for your case.
source share