From 90940a774eab876c38d5cef981b4be5bae67a462 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 8 Jul 2018 23:20:56 +0200 Subject: modernize only --- compat/copyable-mutex.cpp | 9 +++------ compat/copyable-mutex.hpp | 6 +++--- compat/qhash.hpp | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 compat/qhash.hpp (limited to 'compat') 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(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(static_cast(int(m)))) + inner { std::in_place, static_cast(int(m)) } { } @@ -31,6 +28,6 @@ QMutex* mutex::operator->() const mutex::operator QMutex*() const { - return const_cast(inner.get()); + return const_cast(&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 +#include #include @@ -8,7 +8,7 @@ class OTR_COMPAT_EXPORT mutex { - std::unique_ptr inner; + std::optional 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 +#include +#include + +namespace std { +template<> struct hash +{ + inline unsigned operator()(const QString& value) const + { + return qHash(value); + } +}; +} -- cgit v1.2.3