ADUL
Collection of reusable C++ utilities
Loading...
Searching...
No Matches
smallUtils.hpp
Go to the documentation of this file.
1#ifndef ADUL_SMALLUTILS_HPP
2#define ADUL_SMALLUTILS_HPP
3
4#include <string>
5#include <sstream>
6#include <stdexcept>
7
8namespace adul {
9
15 namespace utils {
23 template<typename T> T convert_string(const std::string& str) {
24 T result;
25 std::istringstream iss(str);
26 iss >> result;
27 if (iss.fail() || !iss.eof()) {
28 throw std::invalid_argument("Conversion failed: '" + str + "' to type " + typeid(T).name());
29 }
30 return result;
31 }
32
33 template<> inline std::string convert_string<std::string>(const std::string& str) {
34 return str;
35 }
36 }
37}
38
39#endif // !SMALLUTILS_HPP
40
T convert_string(const std::string &str)
converts std::string into other type
Definition smallUtils.hpp:23
std::string convert_string< std::string >(const std::string &str)
Definition smallUtils.hpp:33
project api's namespace
Definition atm.hpp:4