Skip to content

Commit 5ed350c

Browse files
committed
[Build] compatibility with VS17.3 and later, for C++23 <expected> has been introduced in VS17.3.6, and std::expected has conflict/inconsistent with the makeshift (expected-lite)
1 parent fb35c93 commit 5ed350c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/common/updating/updating.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,20 @@ namespace updating
8282
// prevent the warning that may show up depend on the value of the constants (#defines)
8383
#pragma warning(push)
8484
#pragma warning(disable : 4702)
85+
#if USE_STD_EXPECTED
86+
std::future<std::expected<github_version_info, std::wstring>> get_github_version_info_async(const bool prerelease)
87+
#else
8588
std::future<nonstd::expected<github_version_info, std::wstring>> get_github_version_info_async(const bool prerelease)
89+
#endif
8690
{
8791
// If the current version starts with 0.0.*, it means we're on a local build from a farm and shouldn't check for updates.
8892
if constexpr (VERSION_MAJOR == 0 && VERSION_MINOR == 0)
8993
{
94+
#if USE_STD_EXPECTED
95+
co_return std::unexpected(LOCAL_BUILD_ERROR);
96+
#else
9097
co_return nonstd::make_unexpected(LOCAL_BUILD_ERROR);
98+
#endif
9199
}
92100

93101
try
@@ -139,7 +147,11 @@ namespace updating
139147
catch (...)
140148
{
141149
}
150+
#if USE_STD_EXPECTED
151+
co_return std::unexpected(NETWORK_ERROR);
152+
#else
142153
co_return nonstd::make_unexpected(NETWORK_ERROR);
154+
#endif
143155
}
144156
#pragma warning(pop)
145157

src/common/updating/updating.h

+11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
#include <filesystem>
77
#include <variant>
88
#include <winrt/Windows.Foundation.h>
9+
//#if __MSVC_VERSION__ >= 1933 // MSVC begin to support std::unexpected in 19.33
10+
#if __has_include(<expected> ) // use the same way with excepted-lite to detect std::unexcepted, as using it as backup
11+
#include <expected>
12+
#define USE_STD_EXPECTED 1
13+
#else
914
#include <expected.hpp>
15+
#define USE_STD_EXPECTED 0
16+
#endif
1017

1118
#include <common/version/helper.h>
1219

@@ -27,7 +34,11 @@ namespace updating
2734

2835
std::future<std::optional<std::filesystem::path>> download_new_version(const new_version_download_info& new_version);
2936
std::filesystem::path get_pending_updates_path();
37+
#if USE_STD_EXPECTED
38+
std::future<std::expected<github_version_info, std::wstring>> get_github_version_info_async(const bool prerelease = false);
39+
#else
3040
std::future<nonstd::expected<github_version_info, std::wstring>> get_github_version_info_async(const bool prerelease = false);
41+
#endif
3142
void cleanup_updates();
3243

3344
// non-localized

0 commit comments

Comments
 (0)