Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- struct Properties {
- Properties();
- Properties(std::string key) : key_(key) {};
- std::map<std::string, std::string> props = { {"string", "string"}, {"int", "46"}, {"bool", "false"} };
- operator std::string() { return getString(); };
- operator bool() { return getBool(); };
- operator int() { return getInt(); };
- private:
- std::string key_;
- int getInt() { if (props[key_].find_first_of("0123456789") != std::string::npos) return std::stoi(props[key_]); };
- bool getBool() { if (props[key_].find("true") != std::string::npos || props[key_].find("false") != std::string::npos) return (props[key_].find("true") != std::string::npos); };
- std::string getString() { return props[key_]; };
- };
- int main() {
- int integer = Properties("int");
- std::string text = Properties("string");
- bool boolean = Properties("bool");
- std::cout << "int, string, bool: " << integer << ' ' << text << ' ' << boolean << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement