optional<T> -> Optional<T>

This commit is contained in:
Alexander Karatarakis 2017-04-03 16:27:51 -07:00
parent 9e19213498
commit 95428f5369
8 changed files with 26 additions and 26 deletions

View File

@ -25,15 +25,15 @@ namespace vcpkg::Dependencies
struct InstallPlanAction struct InstallPlanAction
{ {
InstallPlanAction(); InstallPlanAction();
InstallPlanAction(const InstallPlanType& plan_type, optional<BinaryParagraph> binary_pgh, optional<SourceParagraph> source_pgh); InstallPlanAction(const InstallPlanType& plan_type, Optional<BinaryParagraph> binary_pgh, Optional<SourceParagraph> source_pgh);
InstallPlanAction(const InstallPlanAction&) = delete; InstallPlanAction(const InstallPlanAction&) = delete;
InstallPlanAction(InstallPlanAction&&) = default; InstallPlanAction(InstallPlanAction&&) = default;
InstallPlanAction& operator=(const InstallPlanAction&) = delete; InstallPlanAction& operator=(const InstallPlanAction&) = delete;
InstallPlanAction& operator=(InstallPlanAction&&) = default; InstallPlanAction& operator=(InstallPlanAction&&) = default;
InstallPlanType plan_type; InstallPlanType plan_type;
optional<BinaryParagraph> binary_pgh; Optional<BinaryParagraph> binary_pgh;
optional<SourceParagraph> source_pgh; Optional<SourceParagraph> source_pgh;
}; };
struct PackageSpecWithInstallPlan struct PackageSpecWithInstallPlan

View File

@ -59,9 +59,9 @@ namespace vcpkg::System
return println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); return println(c, Strings::format(messageTemplate, messageArg1, messageArgs...));
} }
optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept; Optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept;
optional<std::wstring> get_registry_string(HKEY base, const CWStringView subkey, const CWStringView valuename); Optional<std::wstring> get_registry_string(HKEY base, const CWStringView subkey, const CWStringView valuename);
const fs::path& get_ProgramFiles_32_bit(); const fs::path& get_ProgramFiles_32_bit();

View File

@ -4,23 +4,23 @@
namespace vcpkg namespace vcpkg
{ {
struct nullopt_t struct NullOpt
{ {
explicit constexpr nullopt_t(int) {} explicit constexpr NullOpt(int) {}
}; };
const static constexpr nullopt_t nullopt{ 0 }; const static constexpr NullOpt nullopt{ 0 };
template <class T> template <class T>
class optional class Optional
{ {
public: public:
// Constructors are intentionally implicit // Constructors are intentionally implicit
constexpr optional(nullopt_t) : m_is_present(false), m_t() { } constexpr Optional(NullOpt) : m_is_present(false), m_t() { }
optional(const T& t) : m_is_present(true), m_t(t) { } Optional(const T& t) : m_is_present(true), m_t(t) { }
optional(T&& t) : m_is_present(true), m_t(std::move(t)) { } Optional(T&& t) : m_is_present(true), m_t(std::move(t)) { }
T&& value_or_exit(const LineInfo& line_info) && T&& value_or_exit(const LineInfo& line_info) &&
{ {

View File

@ -20,7 +20,7 @@ namespace vcpkg::Commands::Edit
if (env_EDITOR.empty()) if (env_EDITOR.empty())
{ {
const optional<std::wstring> env_EDITOR_optional = System::get_environmental_variable(L"EDITOR"); const Optional<std::wstring> env_EDITOR_optional = System::get_environmental_variable(L"EDITOR");
if (auto e = env_EDITOR_optional.get()) if (auto e = env_EDITOR_optional.get())
{ {
env_EDITOR = *e; env_EDITOR = *e;
@ -46,7 +46,7 @@ namespace vcpkg::Commands::Edit
}; };
for (auto&& keypath : regkeys) for (auto&& keypath : regkeys)
{ {
const optional<std::wstring> code_installpath = System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation"); const Optional<std::wstring> code_installpath = System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation");
if (auto c = code_installpath.get()) if (auto c = code_installpath.get())
{ {
auto p = fs::path(*c) / "Code.exe"; auto p = fs::path(*c) / "Code.exe";

View File

@ -45,7 +45,7 @@ static void inner(const VcpkgCmdArguments& args)
} }
else else
{ {
const optional<std::wstring> vcpkg_root_dir_env = System::get_environmental_variable(L"VCPKG_ROOT"); const Optional<std::wstring> vcpkg_root_dir_env = System::get_environmental_variable(L"VCPKG_ROOT");
if (auto v = vcpkg_root_dir_env.get()) if (auto v = vcpkg_root_dir_env.get())
{ {
vcpkg_root_dir = fs::absolute(*v); vcpkg_root_dir = fs::absolute(*v);
@ -76,7 +76,7 @@ static void inner(const VcpkgCmdArguments& args)
} }
else else
{ {
const optional<std::wstring> vcpkg_default_triplet_env = System::get_environmental_variable(L"VCPKG_DEFAULT_TRIPLET"); const Optional<std::wstring> vcpkg_default_triplet_env = System::get_environmental_variable(L"VCPKG_DEFAULT_TRIPLET");
if (auto v = vcpkg_default_triplet_env.get()) if (auto v = vcpkg_default_triplet_env.get())
{ {
default_target_triplet = Triplet::from_canonical_name(Strings::utf16_to_utf8(*v)); default_target_triplet = Triplet::from_canonical_name(Strings::utf16_to_utf8(*v));

View File

@ -13,7 +13,7 @@ namespace vcpkg::Dependencies
{ {
} }
InstallPlanAction::InstallPlanAction(const InstallPlanType& plan_type, optional<BinaryParagraph> binary_pgh, optional<SourceParagraph> source_pgh) InstallPlanAction::InstallPlanAction(const InstallPlanType& plan_type, Optional<BinaryParagraph> binary_pgh, Optional<SourceParagraph> source_pgh)
: plan_type(std::move(plan_type)), binary_pgh(std::move(binary_pgh)), source_pgh(std::move(source_pgh)) : plan_type(std::move(plan_type)), binary_pgh(std::move(binary_pgh)), source_pgh(std::move(source_pgh))
{ {
} }

View File

@ -69,7 +69,7 @@ namespace vcpkg::System
for (auto&& env_wstring : env_wstrings) for (auto&& env_wstring : env_wstrings)
{ {
const optional<std::wstring> value = System::get_environmental_variable(env_wstring); const Optional<std::wstring> value = System::get_environmental_variable(env_wstring);
auto v = value.get(); auto v = value.get();
if (!v || v->empty()) if (!v || v->empty())
continue; continue;
@ -161,7 +161,7 @@ namespace vcpkg::System
putchar('\n'); putchar('\n');
} }
optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept Optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept
{ {
auto sz = GetEnvironmentVariableW(varname, nullptr, 0); auto sz = GetEnvironmentVariableW(varname, nullptr, 0);
if (sz == 0) if (sz == 0)
@ -181,7 +181,7 @@ namespace vcpkg::System
return hkey_type == REG_SZ || hkey_type == REG_MULTI_SZ || hkey_type == REG_EXPAND_SZ; return hkey_type == REG_SZ || hkey_type == REG_MULTI_SZ || hkey_type == REG_EXPAND_SZ;
} }
optional<std::wstring> get_registry_string(HKEY base, const CWStringView subKey, const CWStringView valuename) Optional<std::wstring> get_registry_string(HKEY base, const CWStringView subKey, const CWStringView valuename)
{ {
HKEY k = nullptr; HKEY k = nullptr;
LSTATUS ec = RegOpenKeyExW(base, subKey, NULL, KEY_READ, &k); LSTATUS ec = RegOpenKeyExW(base, subKey, NULL, KEY_READ, &k);

View File

@ -38,7 +38,7 @@ namespace vcpkg
return false; return false;
} }
static optional<fs::path> find_if_has_equal_or_greater_version(const std::vector<fs::path>& candidate_paths, const std::wstring& version_check_arguments, const std::array<int, 3>& expected_version) static Optional<fs::path> find_if_has_equal_or_greater_version(const std::vector<fs::path>& candidate_paths, const std::wstring& version_check_arguments, const std::array<int, 3>& expected_version)
{ {
auto it = std::find_if(candidate_paths.cbegin(), candidate_paths.cend(), [&](const fs::path& p) auto it = std::find_if(candidate_paths.cbegin(), candidate_paths.cend(), [&](const fs::path& p)
{ {
@ -99,7 +99,7 @@ namespace vcpkg
candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "CMake" / "bin" / "cmake.exe"); candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "CMake" / "bin" / "cmake.exe");
candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "CMake" / "bin"); candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "CMake" / "bin");
const optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); const Optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version);
if (auto p = path.get()) if (auto p = path.get())
{ {
return *p; return *p;
@ -143,7 +143,7 @@ namespace vcpkg
candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "git" / "cmd" / "git.exe"); candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "git" / "cmd" / "git.exe");
candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "git" / "cmd" / "git.exe"); candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "git" / "cmd" / "git.exe");
const optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); const Optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version);
if (auto p = path.get()) if (auto p = path.get())
{ {
return *p; return *p;
@ -250,9 +250,9 @@ namespace vcpkg
return Strings::split(ec_data.output, "\n"); return Strings::split(ec_data.output, "\n");
} }
static optional<fs::path> get_VS2015_installation_instance() static Optional<fs::path> get_VS2015_installation_instance()
{ {
const optional<std::wstring> vs2015_cmntools_optional = System::get_environmental_variable(L"VS140COMNTOOLS"); const Optional<std::wstring> vs2015_cmntools_optional = System::get_environmental_variable(L"VS140COMNTOOLS");
if (auto v = vs2015_cmntools_optional.get()) if (auto v = vs2015_cmntools_optional.get())
{ {
const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash
@ -305,7 +305,7 @@ namespace vcpkg
} }
// VS2015 // VS2015
const optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance(); const Optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance();
if (auto v = vs_2015_installation_instance.get()) if (auto v = vs_2015_installation_instance.get())
{ {
const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat"; const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat";