Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
f323d182
Unverified
Commit
f323d182
authored
Oct 29, 2021
by
pfeatherstone
Committed by
GitHub
Oct 29, 2021
Browse files
simplification using C++11 types (#2446)
Co-authored-by:
pfeatherstone
<
peter@me
>
parent
d29a8fc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
38 deletions
+5
-38
dlib/threads/async.h
dlib/threads/async.h
+5
-38
No files found.
dlib/threads/async.h
View file @
f323d182
...
@@ -18,29 +18,6 @@ namespace dlib
...
@@ -18,29 +18,6 @@ namespace dlib
namespace
impl
namespace
impl
{
{
template
<
typename
T
>
struct
selector
{};
template
<
typename
T
,
typename
U
,
typename
V
>
void
call_prom_set_value
(
T
&
prom
,
U
&
fun
,
selector
<
V
>
)
{
prom
.
set_value
(
fun
());
}
template
<
typename
T
,
typename
U
>
void
call_prom_set_value
(
T
&
prom
,
U
&
fun
,
selector
<
void
>
)
{
fun
();
prom
.
set_value
();
}
template
<
typename
>
struct
result_of
;
template
<
typename
>
struct
result_of
;
#if (__cplusplus >= 201703L || \
#if (__cplusplus >= 201703L || \
...
@@ -71,21 +48,11 @@ namespace dlib
...
@@ -71,21 +48,11 @@ namespace dlib
Args
&&
...
args
Args
&&
...
args
)
)
{
{
auto
prom
=
std
::
make_shared
<
std
::
promise
<
typename
impl
::
result_of
<
Function
(
Args
...)
>::
type
>>
();
using
return_type
=
typename
impl
::
result_of
<
Function
(
Args
...)
>::
type
;
std
::
future
<
typename
impl
::
result_of
<
Function
(
Args
...)
>::
type
>
ret
=
prom
->
get_future
();
using
task_type
=
std
::
packaged_task
<
return_type
()
>
;
using
bind_t
=
decltype
(
std
::
bind
(
std
::
forward
<
Function
>
(
f
),
std
::
forward
<
Args
>
(
args
)...));
auto
task
=
std
::
make_shared
<
task_type
>
(
std
::
bind
(
std
::
forward
<
Function
>
(
f
),
std
::
forward
<
Args
>
(
args
)...));
auto
fun
=
std
::
make_shared
<
bind_t
>
(
std
::
bind
(
std
::
forward
<
Function
>
(
f
),
std
::
forward
<
Args
>
(
args
)...));
auto
ret
=
task
->
get_future
();
tp
.
add_task_by_value
([
fun
,
prom
]()
tp
.
add_task_by_value
([
task
]()
{(
*
task
)();});
{
try
{
impl
::
call_prom_set_value
(
*
prom
,
*
fun
,
impl
::
selector
<
typename
impl
::
result_of
<
Function
(
Args
...)
>::
type
>
());
}
catch
(...)
{
prom
->
set_exception
(
std
::
current_exception
());
}
});
return
ret
;
return
ret
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment