1 #ifndef CONSOLEREADER_H_
2 #define CONSOLEREADER_H_
32 T
ReadValue(
const std::string& prompt, std::function<
bool(T)> validator)
42 std::getline(std::cin, input);
54 std::cout <<
"Invalid value. Please try again." << std::endl;
60 std::stringstream ss(input);
62 if (!(ss >> val) || ss.rdbuf()->in_avail() != 0)
63 std::cout <<
"Invalid value. Please try again." << std::endl;
78 return ReadValue<T>(prompt, [](T) {
return true; });
82 inline std::string ReadValue<std::string>(
const std::string& prompt, std::function<bool(std::string)> validator)
91 std::getline(std::cin, input);
103 std::cout <<
"Invalid value. Please try again." << std::endl;
108 if (validator(input))
115 #endif // CONSOLEREADER_H_