2017-03-10 14:06:10 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-10 14:06:10 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-10 14:06:10 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <mapbox/variant.hpp>
|
|
|
|
|
|
|
|
// We use base::variant<> alias and base::get_if() helper while we don't have std::variant<>.
|
|
|
|
namespace base {
|
|
|
|
|
2017-03-29 15:09:16 +00:00
|
|
|
template <typename... Types>
|
2017-08-11 07:16:07 +00:00
|
|
|
using variant = mapbox::util::variant<Types...>;
|
2017-03-29 15:09:16 +00:00
|
|
|
|
2017-03-10 14:06:10 +00:00
|
|
|
template <typename T, typename... Types>
|
|
|
|
inline T *get_if(variant<Types...> *v) {
|
2017-03-10 15:53:16 +00:00
|
|
|
return (v && v->template is<T>()) ? &v->template get_unchecked<T>() : nullptr;
|
2017-03-10 14:06:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 15:09:16 +00:00
|
|
|
template <typename T, typename... Types>
|
|
|
|
inline const T *get_if(const variant<Types...> *v) {
|
|
|
|
return (v && v->template is<T>()) ? &v->template get_unchecked<T>() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
// Simplified visit
|
|
|
|
template <typename Method, typename... Types>
|
|
|
|
inline auto visit(Method &&method, const variant<Types...> &value) {
|
|
|
|
return value.match(std::forward<Method>(method));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Method, typename... Types>
|
|
|
|
inline auto visit(Method &&method, variant<Types...> &value) {
|
|
|
|
return value.match(std::forward<Method>(method));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Method, typename... Types>
|
|
|
|
inline auto visit(Method &&method, variant<Types...> &&value) {
|
|
|
|
return value.match(std::forward<Method>(method));
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:06:10 +00:00
|
|
|
} // namespace base
|