mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
upload code
This commit is contained in:
38
3rdparty/QThreadCreateThread.hpp
vendored
Normal file
38
3rdparty/QThreadCreateThread.hpp
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <QThread>
|
||||
|
||||
// FOR OLD QT
|
||||
|
||||
class QThreadCreateThread : public QThread {
|
||||
public:
|
||||
explicit QThreadCreateThread(std::future<void> &&future)
|
||||
: m_future(std::move(future)) {
|
||||
// deleteLater
|
||||
connect(this, &QThread::finished, this, &QThread::deleteLater);
|
||||
}
|
||||
|
||||
private:
|
||||
void run() override {
|
||||
m_future.get();
|
||||
}
|
||||
|
||||
std::future<void> m_future;
|
||||
};
|
||||
|
||||
inline QThread *createThreadImpl(std::future<void> &&future) {
|
||||
return new QThreadCreateThread(std::move(future));
|
||||
}
|
||||
|
||||
template<typename Function, typename... Args>
|
||||
QThread *createQThread(Function &&f, Args &&... args) {
|
||||
using DecayedFunction = typename std::decay<Function>::type;
|
||||
auto threadFunction =
|
||||
[f = static_cast<DecayedFunction>(std::forward<Function>(f))](auto &&... largs) mutable -> void {
|
||||
(void) std::invoke(std::move(f), std::forward<decltype(largs)>(largs)...);
|
||||
};
|
||||
|
||||
return createThreadImpl(std::async(std::launch::deferred,
|
||||
std::move(threadFunction),
|
||||
std::forward<Args>(args)...));
|
||||
}
|
||||
Reference in New Issue
Block a user