mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-27 06:20:07 +00:00
clarify/fix std::visit compile time check
This commit is contained in:
3 files changed
+9
-5
No files matched your search
@@ -132,6 +132,10 @@ private:
|
|||||||
static inline Version mVersion { 3, 9, 2 };
|
static inline Version mVersion { 3, 9, 2 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Used to static_assert in std::visit
|
||||||
|
template<class>
|
||||||
|
inline constexpr bool AlwaysFalseV = false;
|
||||||
|
|
||||||
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
|
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
|
||||||
std::string LowerString(std::string str);
|
std::string LowerString(std::string str);
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -378,7 +378,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
|
|||||||
|
|
||||||
std::visit([&os](auto&& arg) {
|
std::visit([&os](auto&& arg) {
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
if constexpr (std::is_same_v<T, std::vector<TDetachedLuaValue>>) {
|
if constexpr (std::is_same_v<T, TDetachedLuaValue::Array>) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (auto val : arg) {
|
for (auto val : arg) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
@@ -386,7 +386,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
|
|||||||
}
|
}
|
||||||
os << val;
|
os << val;
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<T, std::unordered_map<std::string, TDetachedLuaValue>>) {
|
} else if constexpr (std::is_same_v<T, TDetachedLuaValue::Object>) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (auto [key, val] : arg) {
|
for (auto [key, val] : arg) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
@@ -406,7 +406,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
|
|||||||
// monostate means no result value
|
// monostate means no result value
|
||||||
os << "";
|
os << "";
|
||||||
else
|
else
|
||||||
static_assert(false, "non-exhaustive visitor!");
|
static_assert(AlwaysFalseV<T>, "non-exhaustive visitor!");
|
||||||
},
|
},
|
||||||
value.V);
|
value.V);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -570,7 +570,7 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
|
|||||||
// monostate means no result value
|
// monostate means no result value
|
||||||
Result.set(i, sol::lua_nil_t());
|
Result.set(i, sol::lua_nil_t());
|
||||||
else
|
else
|
||||||
static_assert(false, "non-exhaustive visitor!");
|
static_assert(AlwaysFalseV<T>, "non-exhaustive visitor!");
|
||||||
}, Snapshot.Result.V);
|
}, Snapshot.Result.V);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1259,7 +1259,7 @@ void TLuaEngine::StateThreadData::operator()() {
|
|||||||
} else if constexpr (std::is_same_v<T, float>) {
|
} else if constexpr (std::is_same_v<T, float>) {
|
||||||
LuaArgs.push_back(sol::make_object(StateView, arg));
|
LuaArgs.push_back(sol::make_object(StateView, arg));
|
||||||
} else {
|
} else {
|
||||||
static_assert(false, "unhandled variant");
|
static_assert(AlwaysFalseV<T>, "unhandled variant");
|
||||||
}
|
}
|
||||||
}, Arg);
|
}, Arg);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user