clarify/fix std::visit compile time check

This commit is contained in:
Lion Kortlepel
2026-04-19 20:34:20 +00:00
parent 4045727c8b
commit 06bd719dbf
3 changed files with 9 additions and 5 deletions
+4
View File
@@ -132,6 +132,10 @@ private:
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);
std::string LowerString(std::string str);
+3 -3
View File
@@ -378,7 +378,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
std::visit([&os](auto&& 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;
for (auto val : arg) {
if (i > 0) {
@@ -386,7 +386,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
}
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;
for (auto [key, val] : arg) {
if (i > 0) {
@@ -406,7 +406,7 @@ std::ostream& operator<<(std::ostream& os, const TDetachedLuaValue& value) {
// monostate means no result value
os << "";
else
static_assert(false, "non-exhaustive visitor!");
static_assert(AlwaysFalseV<T>, "non-exhaustive visitor!");
},
value.V);
+2 -2
View File
@@ -570,7 +570,7 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
// monostate means no result value
Result.set(i, sol::lua_nil_t());
else
static_assert(false, "non-exhaustive visitor!");
static_assert(AlwaysFalseV<T>, "non-exhaustive visitor!");
}, Snapshot.Result.V);
}
@@ -1259,7 +1259,7 @@ void TLuaEngine::StateThreadData::operator()() {
} else if constexpr (std::is_same_v<T, float>) {
LuaArgs.push_back(sol::make_object(StateView, arg));
} else {
static_assert(false, "unhandled variant");
static_assert(AlwaysFalseV<T>, "unhandled variant");
}
}, Arg);
}