#ifndef __FLAGS_PARSE_HPP__ #define __FLAGS_PARSE_HPP__ #include // For istringstream. #include #include #include #include #include namespace flags { template Try parse(const std::string& value) { T t; std::istringstream in(value); in >> t; if (!in.good() && !in.eof()) { return Error("Failed to convert into required type"); } return t; } template <> inline Try parse(const std::string& value) { return value; } template <> inline Try parse(const std::string& value) { if (value == "true" || value == "1") { return true; } else if (value == "false" || value == "0") { return false; } return Error("Expecting a boolean (e.g., true or false)"); } template <> inline Try parse(const std::string& value) { return Duration::parse(value); } } // namespace flags { #endif // __FLAGS_PARSE_HPP__