Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit d2904ee

Browse files
authored
fix: gcc9 issue for std::variant (#1310)
1 parent 1e7c2ac commit d2904ee

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

engine/utils/url_parser.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,35 @@
77
#include "exceptions/malformed_url_exception.h"
88

99
namespace url_parser {
10+
11+
struct explicit_bool {
12+
bool b = false;
13+
template <class T, std::enable_if_t<std::is_same_v<T, bool>, bool> = true>
14+
explicit_bool(T v) : b(v) {}
15+
explicit_bool(explicit_bool const&) noexcept = default;
16+
explicit_bool& operator=(explicit_bool const&) & noexcept = default;
17+
explicit_bool() noexcept = default;
18+
~explicit_bool() noexcept = default;
19+
bool operator!() const { return !b; }
20+
explicit operator bool() const { return b; }
21+
};
22+
23+
struct explicit_int {
24+
int i = 0;
25+
template <class T, std::enable_if_t<std::is_same_v<T, int>, int> = true>
26+
explicit_int(T v) : i(v) {}
27+
explicit_int(explicit_int const&) noexcept = default;
28+
explicit_int& operator=(explicit_int const&) & noexcept = default;
29+
explicit_int() noexcept = default;
30+
~explicit_int() noexcept = default;
31+
32+
explicit operator int() const { return i; }
33+
};
1034
struct Url {
1135
std::string protocol;
1236
std::string host;
1337
std::vector<std::string> pathParams;
14-
std::unordered_map<std::string, std::variant<std::string, int, bool>> queries;
38+
std::unordered_map<std::string, std::variant<std::string, explicit_int, explicit_bool>> queries;
1539

1640
std::string GetProtocolAndHost() const { return protocol + "://" + host; }
1741

@@ -102,10 +126,10 @@ inline std::string FromUrl(const Url& url) {
102126
std::string value_str;
103127
if (std::holds_alternative<std::string>(value)) {
104128
value_str = std::get<std::string>(value);
105-
} else if (std::holds_alternative<int>(value)) {
106-
value_str = std::to_string(std::get<int>(value));
107-
} else if (std::holds_alternative<bool>(value)) {
108-
value_str = std::get<bool>(value) ? "true" : "false";
129+
} else if (std::holds_alternative<explicit_int>(value)) {
130+
value_str = std::to_string(int(std::get<explicit_int>(value)));
131+
} else if (std::holds_alternative<explicit_bool>(value)) {
132+
value_str = std::get<explicit_bool>(value) ? "true" : "false";
109133
}
110134
if (!query_string.empty()) {
111135
query_string += "&";

0 commit comments

Comments
 (0)