/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once namespace base { namespace details { // This implementation was taken from range-v3 library. // It was modified so that more than one of passed function objects // could be called with an argument list and the first one that // matches gets used instead of a compile-time ambiguity error. // // This allows to write "default" visitor handlers with [](auto&&) syntax. template constexpr bool is_callable_v = rpl::details::is_callable_plain_v; template struct overloaded; template <> struct overloaded<> { }; template struct overloaded : private First , private overloaded { private: using Others = overloaded; public: overloaded() = default; constexpr overloaded(First first, Rest... rest) : First(std::move(first)) , Others(std::move(rest)...) { } template auto operator()(Args&&... args) -> decltype(std::declval()(std::forward(args)...)) { return static_cast(*this)(std::forward(args)...); } template auto operator()(Args&&... args) const -> decltype(std::declval()(std::forward(args)...)) { return static_cast(*this)(std::forward(args)...); } template < typename... Args, typename = std::enable_if_t>> auto operator()(Args&&... args) -> decltype(std::declval()(std::forward(args)...)) { return static_cast(*this)(std::forward(args)...); } template < typename... Args, typename = std::enable_if_t>> auto operator()(Args&&... args) const -> decltype(std::declval()(std::forward(args)...)) { return static_cast(*this)(std::forward(args)...); } }; } // namespace details template Function overload(Function &&function) { return std::forward(function); } template 1)>> auto overload(Functions ...functions) { return details::overloaded(std::move(functions)...); } } // namespace base