Use boost::bind & boost::function instead of std equivalents for better compatibility.

This commit is contained in:
John Maguire 2012-11-21 17:17:37 +01:00
parent fd4c34c38b
commit fddce90624
2 changed files with 15 additions and 16 deletions

View File

@ -18,9 +18,8 @@
#ifndef CONCURRENTRUN_H
#define CONCURRENTRUN_H
#include <functional>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <QFuture>
#include <QRunnable>
@ -76,9 +75,9 @@ class ThreadFunctorBase : public QFutureInterface<ReturnType>, public QRunnable
template <typename ReturnType, typename... Args>
class ThreadFunctor : public ThreadFunctorBase<ReturnType> {
public:
ThreadFunctor(std::function<ReturnType (Args...)> function,
Args... args)
: function_(std::bind(function, args...)) {
ThreadFunctor(boost::function<ReturnType (Args...)> function,
Args... args)
: function_(boost::bind(function, args...)) {
}
virtual void run() {
@ -87,16 +86,16 @@ class ThreadFunctor : public ThreadFunctorBase<ReturnType> {
}
private:
std::function<ReturnType()> function_;
boost::function<ReturnType()> function_;
};
// Partial specialisation for void return type.
template <typename... Args>
class ThreadFunctor <void, Args...> : public ThreadFunctorBase<void> {
public:
ThreadFunctor(std::function<void (Args...)> function,
Args... args)
: function_(std::bind(function, args...)) {
ThreadFunctor(boost::function<void (Args...)> function,
Args... args)
: function_(boost::bind(function, args...)) {
}
virtual void run() {
@ -105,7 +104,7 @@ class ThreadFunctor <void, Args...> : public ThreadFunctorBase<void> {
}
private:
std::function<void()> function_;
boost::function<void()> function_;
};
@ -118,7 +117,7 @@ namespace ConcurrentRun {
template <typename ReturnType>
QFuture<ReturnType> Run(
QThreadPool* threadpool,
std::function<ReturnType ()> function) {
boost::function<ReturnType ()> function) {
return (new ThreadFunctor<ReturnType>(function))->Start(threadpool);
}
@ -126,7 +125,7 @@ namespace ConcurrentRun {
template <typename ReturnType, typename... Args>
QFuture<ReturnType> Run(
QThreadPool* threadpool,
std::function<ReturnType (Args...)> function,
boost::function<ReturnType (Args...)> function,
const Args&... args) {
return (new ThreadFunctor<ReturnType, Args...>(
function, args...))->Start(threadpool);
@ -139,7 +138,7 @@ namespace ConcurrentRun {
ReturnType (*function) (Args...),
const Args&... args) {
return Run(
threadpool, std::function<ReturnType (Args...)>(function), args...);
threadpool, boost::function<ReturnType (Args...)>(function), args...);
}
}

View File

@ -17,7 +17,7 @@
#include "songloader.h"
#include <functional>
#include <boost/bind.hpp>
#include <QBuffer>
#include <QDirIterator>
@ -231,7 +231,7 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename, bool block,
if (QFileInfo(filename).isDir()) {
if (!block) {
ConcurrentRun::Run<void>(&thread_pool_,
std::bind(&SongLoader::LoadLocalDirectoryAndEmit, this, filename));
boost::bind(&SongLoader::LoadLocalDirectoryAndEmit, this, filename));
return WillLoadAsync;
} else {
LoadLocalDirectory(filename);
@ -264,7 +264,7 @@ SongLoader::Result SongLoader::LoadLocal(const QString& filename, bool block,
// It's a playlist!
if (!block) {
ConcurrentRun::Run<void>(&thread_pool_,
std::bind(&SongLoader::LoadPlaylistAndEmit, this, parser, filename));
boost::bind(&SongLoader::LoadPlaylistAndEmit, this, parser, filename));
return WillLoadAsync;
} else {
LoadPlaylist(parser, filename);