diff options
author | lloyd <[email protected]> | 2009-12-24 22:19:09 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-24 22:19:09 +0000 |
commit | 72aaefc3ae5211e5cbd74520ec58c0bfb172f860 (patch) | |
tree | b1b31afa932fcbe77f900ff8e48f8e8fa72907b4 /src/utils/async.h | |
parent | ab35e8266cb93df950c0f93a74f9714d9de40f1c (diff) | |
parent | 75234461be7187b1582cd80134e6d6aaeee82c3e (diff) |
propagate from branch 'net.randombit.botan' (head 775a8de3f880cdc75105b4fa607bcc25bd3a99d1)
to branch 'net.randombit.botan.c++0x' (head b88067c1db54346de91f4930a7cf435609c557c0)
Diffstat (limited to 'src/utils/async.h')
-rw-r--r-- | src/utils/async.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/async.h b/src/utils/async.h new file mode 100644 index 000000000..85702c114 --- /dev/null +++ b/src/utils/async.h @@ -0,0 +1,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 |