]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fiber/include/boost/fiber/future/async.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / include / boost / fiber / future / async.hpp
CommitLineData
7c673cae
FG
1
2// Copyright Oliver Kowalke 2013.
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_FIBERS_ASYNC_HPP
8#define BOOST_FIBERS_ASYNC_HPP
9
10#include <algorithm>
11#include <memory>
12#include <type_traits>
13#include <utility>
14
15#include <boost/config.hpp>
16
17#include <boost/fiber/future/future.hpp>
18#include <boost/fiber/future/packaged_task.hpp>
19#include <boost/fiber/policy.hpp>
20
21namespace boost {
22namespace fibers {
23
24template< typename Fn, typename ... Args >
25future<
26 typename std::result_of<
27 typename std::enable_if<
28 ! detail::is_launch_policy< typename std::decay< Fn >::type >::value,
29 typename std::decay< Fn >::type
30 >::type( typename std::decay< Args >::type ... )
31 >::type
32>
33async( Fn && fn, Args && ... args) {
34 typedef typename std::result_of<
35 typename std::decay< Fn >::type( typename std::decay< Args >::type ... )
36 >::type result_t;
37
38 packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{
39 std::forward< Fn >( fn) };
40 future< result_t > f{ pt.get_future() };
41 fiber{ std::move( pt), std::forward< Args >( args) ... }.detach();
42 return f;
43}
44
45template< typename Policy, typename Fn, typename ... Args >
46future<
47 typename std::result_of<
48 typename std::enable_if<
49 detail::is_launch_policy< Policy >::value,
50 typename std::decay< Fn >::type
51 >::type( typename std::decay< Args >::type ...)
52 >::type
53>
54async( Policy policy, Fn && fn, Args && ... args) {
55 typedef typename std::result_of<
56 typename std::decay< Fn >::type( typename std::decay< Args >::type ... )
57 >::type result_t;
58
59 packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{
60 std::forward< Fn >( fn) };
61 future< result_t > f{ pt.get_future() };
62 fiber{ policy, std::move( pt), std::forward< Args >( args) ... }.detach();
63 return f;
64}
65
66template< typename Policy, typename StackAllocator, typename Fn, typename ... Args >
67future<
68 typename std::result_of<
69 typename std::enable_if<
70 detail::is_launch_policy< Policy >::value,
71 typename std::decay< Fn >::type
72 >::type( typename std::decay< Args >::type ... )
73 >::type
74>
75async( Policy policy, std::allocator_arg_t, StackAllocator salloc, Fn && fn, Args && ... args) {
76 typedef typename std::result_of<
77 typename std::decay< Fn >::type( typename std::decay< Args >::type ... )
78 >::type result_t;
79
80 packaged_task< result_t( typename std::decay< Args >::type ... ) > pt{
81 std::allocator_arg, salloc, std::forward< Fn >( fn) };
82 future< result_t > f{ pt.get_future() };
83 fiber{ policy, std::move( pt), std::forward< Args >( args) ... }.detach();
84 return f;
85}
86
87}}
88
89#endif // BOOST_FIBERS_ASYNC_HPP