vcpkg/toolsrc/include/OptBool.h
Alexander Karatarakis 09b9340515 Make constexprs static
2017-04-25 17:56:18 -07:00

49 lines
1.2 KiB
C++

#pragma once
#include <string>
#include <map>
namespace vcpkg
{
struct OptBool final
{
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;
};
namespace OptBoolC
{
static constexpr OptBool UNSPECIFIED(OptBool::BackingEnum::UNSPECIFIED);
static constexpr OptBool ENABLED(OptBool::BackingEnum::ENABLED);
static constexpr OptBool DISABLED(OptBool::BackingEnum::DISABLED);
}
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 OptBoolC::UNSPECIFIED;
}
return parse(*it);
}
}