File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33#include < cmath>
44#include < sstream>
5+ #include < stdexcept>
56#include < string>
7+ #include < type_traits>
68#include < vector>
79
810template <typename T> void split_response (const std::string& str, std::vector<T>& vec) {
11+ static_assert (std::is_integral_v<T>, " T must be an integral type." );
12+
913 std::stringstream ss (str);
1014 std::string item;
15+
1116 while (std::getline (ss, item, ' ,' )) {
12- if constexpr (std::is_floating_point_v<T>) {
13- vec.push_back (static_cast <T>(std::stod (item)));
14- } else if constexpr (std::is_integral_v<T>) {
15- double item_double = std::stod (item);
16- vec.push_back (static_cast <T>(std::floor (item_double)));
17- } else {
18- static_assert (std::is_arithmetic_v<T>, " T must be an arithmetic type." );
17+ try {
18+ vec.push_back (static_cast <T>(std::stoll (item)));
19+ } catch (const std::exception&) {
20+ throw std::runtime_error (" Server call returned malformed response string: " + str);
1921 }
2022 }
2123}
You can’t perform that action at this time.
0 commit comments