more valueor variants

This commit is contained in:
Green Sky 2024-02-04 15:10:34 +01:00
parent 390b123fb7
commit d304d719e9
No known key found for this signature in database

View File

@ -78,6 +78,38 @@ struct CM_InternalOptional {
}
}
T& value_or(T& other) {
if (has_value) {
if constexpr (std::is_same_v<T, bool>) {
return b;
} else if constexpr (std::is_same_v<T, int64_t>) {
return i;
} else if constexpr (std::is_same_v<T, double>) {
return d;
} else if constexpr (std::is_same_v<T, CM_InternalStringView>) {
return s;
}
} else {
return other;
}
}
const T& value_or(const T& other) const {
if (has_value) {
if constexpr (std::is_same_v<T, bool>) {
return b;
} else if constexpr (std::is_same_v<T, int64_t>) {
return i;
} else if constexpr (std::is_same_v<T, double>) {
return d;
} else if constexpr (std::is_same_v<T, CM_InternalStringView>) {
return s;
}
} else {
return other;
}
}
T value_or(T&& other) {
if (has_value) {
if constexpr (std::is_same_v<T, bool>) {