Files
roynatech2544 d71bab2ca8 libsafestoi: Drop the usage of std::optional
- Drops the requirement of C++17
- Also adapt the library users code
2023-12-02 16:12:56 +09:00

13 lines
215 B
C++

#include "SafeStoi.h"
#include <sstream>
int stoi_safe(const std::string& str, const int fallback) {
std::istringstream iss(str);
int value;
if (!(iss >> value)) {
return fallback;
}
return value;
}