// This file is part of Desktop App Toolkit, // a set of libraries for developing nice desktop applications. // // For license and copyright information please follow this link: // https://github.com/desktop-app/legal/blob/master/LEGAL // #pragma once #include namespace base { template struct optional_wrap_once { using type = std::optional; }; template struct optional_wrap_once> { using type = std::optional; }; template using optional_wrap_once_t = typename optional_wrap_once>::type; template struct optional_chain_result { using type = optional_wrap_once_t; }; template <> struct optional_chain_result { using type = bool; }; template using optional_chain_result_t = typename optional_chain_result::type; template optional_wrap_once_t make_optional(Type &&value) { return optional_wrap_once_t { std::forward(value) }; } } // namespace base template inline auto operator|(const std::optional &value, Method method) -> base::optional_chain_result_t { if constexpr (std::is_same_v) { return value ? (method(*value), true) : false; } else { return value ? base::optional_chain_result_t( method(*value)) : std::nullopt; } }