diff options
Diffstat (limited to 'toolsrc/include/OptBool.h')
| -rw-r--r-- | toolsrc/include/OptBool.h | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/toolsrc/include/OptBool.h b/toolsrc/include/OptBool.h index 4098e6f03..b6b26833b 100644 --- a/toolsrc/include/OptBool.h +++ b/toolsrc/include/OptBool.h @@ -3,31 +3,46 @@ #include <string> #include <map> -namespace vcpkg::OptBool +namespace vcpkg { - enum class Type + struct OptBool final { - UNSPECIFIED = 0, - ENABLED, - DISABLED + enum class BackingEnum + { + UNSPECIFIED = 0, + ENABLED, + DISABLED + }; + + static OptBool parse(const std::string& s); + + template<class T> + static OptBool from_map(const std::map<T, std::string>& map, const T& key); + + constexpr OptBool() : backing_enum(BackingEnum::UNSPECIFIED) {} + constexpr explicit OptBool(BackingEnum backing_enum) : backing_enum(backing_enum) { } + constexpr operator BackingEnum() const { return backing_enum; } + + private: + BackingEnum backing_enum; }; - Type parse(const std::string& s); + namespace OptBoolC + { + constexpr OptBool UNSPECIFIED(OptBool::BackingEnum::UNSPECIFIED); + constexpr OptBool ENABLED(OptBool::BackingEnum::ENABLED); + constexpr OptBool DISABLED(OptBool::BackingEnum::DISABLED); + } - template <class T> - Type from_map(const std::map<T, std::string>& map, const T& key) + template<class T> + OptBool OptBool::from_map(const std::map<T, std::string>& map, const T& key) { auto it = map.find(key); if (it == map.cend()) { - return Type::UNSPECIFIED; + return OptBoolC::UNSPECIFIED; } return parse(*it); } } - -namespace vcpkg -{ - using OptBoolT = OptBool::Type; -}
\ No newline at end of file |
