#pragma once #include #include namespace vcpkg { struct OptBool final { enum class BackingEnum { UNSPECIFIED = 0, ENABLED, DISABLED }; static OptBool parse(const std::string& s); template static OptBool from_map(const std::map& 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; }; namespace OptBoolC { static constexpr OptBool UNSPECIFIED(OptBool::BackingEnum::UNSPECIFIED); static constexpr OptBool ENABLED(OptBool::BackingEnum::ENABLED); static constexpr OptBool DISABLED(OptBool::BackingEnum::DISABLED); } template OptBool OptBool::from_map(const std::map& map, const T& key) { auto it = map.find(key); if (it == map.cend()) { return OptBoolC::UNSPECIFIED; } return parse(*it); } }