summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/copyable-mutex.cpp9
-rw-r--r--compat/copyable-mutex.hpp6
-rw-r--r--compat/qhash.hpp15
3 files changed, 21 insertions, 9 deletions
diff --git a/compat/copyable-mutex.cpp b/compat/copyable-mutex.cpp
index 7c112c5e..dde84c83 100644
--- a/compat/copyable-mutex.cpp
+++ b/compat/copyable-mutex.cpp
@@ -2,10 +2,7 @@
mutex& mutex::operator=(const mutex& datum)
{
- inner = nullptr;
- inner = std::make_unique<QMutex>(datum->isRecursive()
- ? QMutex::Recursive
- : QMutex::NonRecursive);
+ inner.emplace(datum->isRecursive() ? QMutex::Recursive : QMutex::NonRecursive);
return *this;
}
@@ -15,7 +12,7 @@ mutex::mutex(const mutex& datum)
}
mutex::mutex(mutex::mode m) :
- inner(std::make_unique<QMutex>(static_cast<QMutex::RecursionMode>(int(m))))
+ inner { std::in_place, static_cast<QMutex::RecursionMode>(int(m)) }
{
}
@@ -31,6 +28,6 @@ QMutex* mutex::operator->() const
mutex::operator QMutex*() const
{
- return const_cast<QMutex*>(inner.get());
+ return const_cast<QMutex*>(&inner.value());
}
diff --git a/compat/copyable-mutex.hpp b/compat/copyable-mutex.hpp
index af82876d..46c6c88c 100644
--- a/compat/copyable-mutex.hpp
+++ b/compat/copyable-mutex.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <memory>
+#include <optional>
#include <QMutex>
@@ -8,7 +8,7 @@
class OTR_COMPAT_EXPORT mutex
{
- std::unique_ptr<QMutex> inner;
+ std::optional<QMutex> inner;
public:
enum mode
@@ -19,7 +19,7 @@ public:
mutex& operator=(const mutex& datum);
mutex(const mutex& datum);
- mutex(mode m = normal);
+ explicit mutex(mode m = normal);
QMutex* operator&() const;
operator QMutex*() const;
diff --git a/compat/qhash.hpp b/compat/qhash.hpp
new file mode 100644
index 00000000..a9685007
--- /dev/null
+++ b/compat/qhash.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <functional>
+#include <QString>
+#include <QHashFunctions>
+
+namespace std {
+template<> struct hash<QString>
+{
+ inline unsigned operator()(const QString& value) const
+ {
+ return qHash(value);
+ }
+};
+}