aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/async.h
blob: 85702c1142c8642a49747b9b92bf50a29d78fb46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Standin for C++0x's std::async
* (C) 2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_ASYNC_H__
#define BOTAN_ASYNC_H__

#include <future>
#include <thread>

namespace Botan {

/**
* A simple version of std::async (as it is not in GCC 4.5)
* Will be removed once GCC supports it natively
*/
template<typename F>
auto std_async(F f) -> std::unique_future<decltype(f())>
   {
   typedef decltype(f()) result_type;
   std::packaged_task<result_type ()> task(std::move(f));
   std::unique_future<result_type> future = task.get_future();
   std::thread thread(std::move(task));
   thread.detach();
   return future;
   }

}

#endif