2
0
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:
John Preston
2017-09-29 13:55:25 +03:00
parent 5cc7cb1d85
commit ea0f6b9a12
5 changed files with 78 additions and 176 deletions

View File

@@ -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