From cbc52bc6a4f92ac4c5379912b09adb37a6ea1918 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 28 Apr 2017 17:27:07 -0700 Subject: [vcpkg] Remove OptBool in favor of Optional --- toolsrc/include/OptBool.h | 48 ------------------------------- toolsrc/include/PostBuildLint_BuildInfo.h | 3 +- toolsrc/include/VcpkgCmdArguments.h | 8 +++--- toolsrc/include/vcpkg_optional.h | 25 ++++++++++++++++ 4 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 toolsrc/include/OptBool.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/OptBool.h b/toolsrc/include/OptBool.h deleted file mode 100644 index 90655cb7e..000000000 --- a/toolsrc/include/OptBool.h +++ /dev/null @@ -1,48 +0,0 @@ -#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); - } -} diff --git a/toolsrc/include/PostBuildLint_BuildInfo.h b/toolsrc/include/PostBuildLint_BuildInfo.h index 4a4560b8e..29fa09e6c 100644 --- a/toolsrc/include/PostBuildLint_BuildInfo.h +++ b/toolsrc/include/PostBuildLint_BuildInfo.h @@ -1,6 +1,5 @@ #pragma once -#include "OptBool.h" #include "PostBuildLint_BuildPolicies.h" #include "PostBuildLint_LinkageType.h" #include "filesystem_fs.h" @@ -15,7 +14,7 @@ namespace vcpkg::PostBuildLint LinkageType crt_linkage; LinkageType library_linkage; - std::map policies; + std::map policies; }; BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath); diff --git a/toolsrc/include/VcpkgCmdArguments.h b/toolsrc/include/VcpkgCmdArguments.h index 7cab0f192..316987100 100644 --- a/toolsrc/include/VcpkgCmdArguments.h +++ b/toolsrc/include/VcpkgCmdArguments.h @@ -1,6 +1,6 @@ #pragma once -#include "OptBool.h" +#include "vcpkg_optional.h" #include #include #include @@ -14,9 +14,9 @@ namespace vcpkg std::unique_ptr vcpkg_root_dir; std::unique_ptr triplet; - OptBool debug = OptBoolC::UNSPECIFIED; - OptBool sendmetrics = OptBoolC::UNSPECIFIED; - OptBool printmetrics = OptBoolC::UNSPECIFIED; + Optional debug = nullopt; + Optional sendmetrics = nullopt; + Optional printmetrics = nullopt; std::string command; std::vector command_arguments; diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h index b5a3268f0..03fa50678 100644 --- a/toolsrc/include/vcpkg_optional.h +++ b/toolsrc/include/vcpkg_optional.h @@ -64,4 +64,29 @@ namespace vcpkg bool m_is_present; T m_t; }; + + template + bool operator==(const Optional& o, const T& t) + { + if (auto p = o.get()) return *p == t; + return false; + } + template + bool operator==(const T& t, const Optional& o) + { + if (auto p = o.get()) return t == *p; + return false; + } + template + bool operator!=(const Optional& o, const T& t) + { + if (auto p = o.get()) return *p != t; + return true; + } + template + bool operator!=(const T& t, const Optional& o) + { + if (auto p = o.get()) return t != *p; + return true; + } } -- cgit v1.2.3