aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-18 10:35:48 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-21 17:57:05 +0200
commit34ff85b715b377c4b2a8e30b1af8327aa7928e36 (patch)
tree0fd452859b8c3c6619ab1d3704879de4e6dc7f95 /lib
parent23672cbb025814f2d8d6960f72ab602ef7a55b41 (diff)
downloadlibquotient-34ff85b715b377c4b2a8e30b1af8327aa7928e36.tar.gz
libquotient-34ff85b715b377c4b2a8e30b1af8327aa7928e36.zip
Move out Overloads to util.h
...instead of tucking the template in filesourceinfo.cpp where it surely will be forgotten.
Diffstat (limited to 'lib')
-rw-r--r--lib/events/filesourceinfo.cpp9
-rw-r--r--lib/util.h13
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/events/filesourceinfo.cpp b/lib/events/filesourceinfo.cpp
index 11f93d80..e8b6794b 100644
--- a/lib/events/filesourceinfo.cpp
+++ b/lib/events/filesourceinfo.cpp
@@ -5,6 +5,7 @@
#include "filesourceinfo.h"
#include "logging.h"
+#include "util.h"
#ifdef Quotient_E2EE_ENABLED
# include "e2ee/qolmutils.h"
@@ -140,14 +141,6 @@ void JsonObjectConverter<JWK>::fillFrom(const QJsonObject& jo, JWK& pod)
fromJson(jo.value("ext"_ls), pod.ext);
}
-template <typename... FunctorTs>
-struct Overloads : FunctorTs... {
- using FunctorTs::operator()...;
-};
-
-template <typename... FunctorTs>
-Overloads(FunctorTs&&...) -> Overloads<FunctorTs...>;
-
QUrl Quotient::getUrlFromSourceInfo(const FileSourceInfo& fsi)
{
return std::visit(Overloads { [](const QUrl& url) { return url; },
diff --git a/lib/util.h b/lib/util.h
index d1623881..8a30f457 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -170,6 +170,19 @@ constexpr ImplPtr<ImplType> ZeroImpl()
return { nullptr, [](ImplType*) { /* nullptr doesn't need deletion */ } };
}
+//! \brief Multiplex several functors in one
+//!
+//! This is a well-known trick to wrap several lambdas into a single functor
+//! class that can be passed to std::visit.
+//! \sa https://en.cppreference.com/w/cpp/utility/variant/visit
+template <typename... FunctorTs>
+struct Overloads : FunctorTs... {
+ using FunctorTs::operator()...;
+};
+
+template <typename... FunctorTs>
+Overloads(FunctorTs&&...) -> Overloads<FunctorTs...>;
+
/** Convert what looks like a URL or a Matrix ID to an HTML hyperlink */
QUOTIENT_API void linkifyUrls(QString& htmlEscapedText);