From 0ef45bd23d48769674fe734f90b96bee82893fe1 Mon Sep 17 00:00:00 2001 From: Sacha Date: Sun, 2 Jun 2013 22:25:57 +1000 Subject: [PATCH] Move C++11 functions to std namespace. --- base/functional.h | 16 ++++++---------- net/http_client.cpp | 2 +- thread/threadpool.cpp | 8 ++++---- thread/threadpool.h | 6 +++--- ui/view.cpp | 2 +- ui/view.h | 6 +++--- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/base/functional.h b/base/functional.h index 3cab9d8620..1fdae0bb9e 100644 --- a/base/functional.h +++ b/base/functional.h @@ -10,7 +10,6 @@ #include #include #include -using boost::shared_ptr; #else #include using std::shared_ptr; @@ -23,7 +22,11 @@ using std::shared_ptr; #include #endif namespace std { -#ifndef __SYMBIAN32__ +#ifdef __SYMBIAN32__ + using boost::bind; + using boost::function; + using boost::shared_ptr; +#else using tr1::bind; using tr1::function; using tr1::shared_ptr; @@ -40,21 +43,14 @@ namespace std { { return shared_ptr(new T(arg1)); } - -#else -using std::bind; -using std::function; -using std::shared_ptr; +} #endif #ifdef __SYMBIAN32__ #define placeholder -#define p #elif defined(IOS) namespace placeholder = std::tr1::placeholders; -namespace p = std::tr1::placeholders; #else namespace placeholder = std::placeholders; -namespace p = std::placeholders; #endif diff --git a/net/http_client.cpp b/net/http_client.cpp index 7e9128c056..3e434cd6ff 100644 --- a/net/http_client.cpp +++ b/net/http_client.cpp @@ -174,7 +174,7 @@ int Client::POST(const char *resource, const std::string &data, Buffer *output) Download::Download(const std::string &url, const std::string &outfile) : url_(url), outfile_(outfile), progress_(0.0f), failed_(false) { - std::thread th(bind(&Download::Do, this)); + std::thread th(std::bind(&Download::Do, this)); th.detach(); } diff --git a/thread/threadpool.cpp b/thread/threadpool.cpp index dcc733025d..d79f2cd6c9 100644 --- a/thread/threadpool.cpp +++ b/thread/threadpool.cpp @@ -3,7 +3,7 @@ ///////////////////////////// WorkerThread WorkerThread::WorkerThread() : active(true), started(false) { - thread = new std::thread(bind(&WorkerThread::WorkFunc, this)); + thread = new std::thread(std::bind(&WorkerThread::WorkFunc, this)); doneMutex.lock(); while(!started) { }; } @@ -17,7 +17,7 @@ WorkerThread::~WorkerThread() { delete thread; } -void WorkerThread::Process(const function& work) { +void WorkerThread::Process(const std::function& work) { mutex.lock(); work_ = work; signal.notify_one(); @@ -56,7 +56,7 @@ void ThreadPool::StartWorkers() { } } -void ThreadPool::ParallelLoop(function loop, int lower, int upper) { +void ThreadPool::ParallelLoop(std::function loop, int lower, int upper) { mutex.lock(); StartWorkers(); int range = upper-lower; @@ -66,7 +66,7 @@ void ThreadPool::ParallelLoop(function loop, int lower, int upper int chunk = range/numThreads; int s = lower; for(int i=0; iProcess(bind(loop, s, s+chunk)); + workers[i]->Process(std::bind(loop, s, s+chunk)); s+=chunk; } loop(s, upper); diff --git a/thread/threadpool.h b/thread/threadpool.h index c4bff05f06..04caa96bd6 100644 --- a/thread/threadpool.h +++ b/thread/threadpool.h @@ -13,7 +13,7 @@ public: ~WorkerThread(); // submit a new work item - void Process(const function& work); + void Process(const std::function& work); // wait for a submitted work item to be completed void WaitForCompletion(); @@ -23,7 +23,7 @@ private: ::condition_variable done; // used to signal work completion ::recursive_mutex mutex, doneMutex; // associated with each respective condition variable volatile bool active, started; - function work_; // the work to be done by this thread + std::function work_; // the work to be done by this thread void WorkFunc(); @@ -40,7 +40,7 @@ public: // don't need a destructor, "workers" is cleared on delete, // leading to the stopping and joining of all worker threads (RAII and all that) - void ParallelLoop(function loop, int lower, int upper); + void ParallelLoop(std::function loop, int lower, int upper); private: const int numThreads; diff --git a/ui/view.cpp b/ui/view.cpp index db6f6c0fc4..9de1542e21 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -49,7 +49,7 @@ void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measure } } -void Event::Add(function func) { +void Event::Add(std::function func) { HandlerRegistration reg; reg.func = func; handlers_.push_back(reg); diff --git a/ui/view.h b/ui/view.h index 3ae7a30495..b6f8a439fe 100644 --- a/ui/view.h +++ b/ui/view.h @@ -157,14 +157,14 @@ struct EventParams { }; struct HandlerRegistration { - function func; + std::function func; }; class Event { public: Event() : triggered_(false) {} - void Add(function func); + void Add(std::function func); // Call this from input thread or whatever, it doesn't matter void Trigger(EventParams &e); @@ -410,7 +410,7 @@ class CheckBox : public ClickableItem { public: CheckBox(bool *toggle, const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0) : ClickableItem(layoutParams), text_(text), smallText_(smallText) { - OnClick.Add(bind(&CheckBox::OnClicked, this, placeholder::_1)); + OnClick.Add(std::bind(&CheckBox::OnClicked, this, placeholder::_1)); } virtual void Draw(UIContext &dc);