mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-01 15:05:56 +00:00
Use 'if constexpr ()' instead of tag dispatch.
This commit is contained in:
@@ -187,29 +187,14 @@ optional_wrap_once_t<Type> make_optional(Type &&value) {
|
||||
return optional_wrap_once_t<Type> { std::forward<Type>(value) };
|
||||
}
|
||||
|
||||
template <typename Type, typename Method>
|
||||
inline auto optional_chain(
|
||||
const optional<Type> &value,
|
||||
Method &method,
|
||||
std::false_type)
|
||||
-> optional_chain_result_t<decltype(method(*value))> {
|
||||
return value ? make_optional(method(*value)) : none;
|
||||
}
|
||||
|
||||
template <typename Type, typename Method>
|
||||
inline auto optional_chain(
|
||||
const optional<Type> &value,
|
||||
Method &method,
|
||||
std::true_type)
|
||||
-> optional_chain_result_t<decltype(method(*value))> {
|
||||
return value ? (method(*value), true) : false;
|
||||
}
|
||||
|
||||
template <typename Type, typename Method>
|
||||
inline auto operator|(const optional<Type> &value, Method method)
|
||||
-> optional_chain_result_t<decltype(method(*value))> {
|
||||
using is_void_return = std::is_same<decltype(method(*value)), void>;
|
||||
return optional_chain(value, method, is_void_return {});
|
||||
if constexpr (std::is_same_v<decltype(method(*value)), void>) {
|
||||
return value ? (method(*value), true) : false;
|
||||
} else {
|
||||
return value ? make_optional(method(*value)) : none;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
Reference in New Issue
Block a user