Commit 75eb6443 by Jonathan Wakely Committed by Jonathan Wakely

future (__async_result_of): New alias template.

	* include/std/future (__async_result_of): New alias template.
	(async): Use __async_result_of to pass decayed types to result_of.
	* testsuite/30_threads/async/lwg2021.cc: New.
	* doc/xml/manual/intro.xml: Document LWG 2021 status.

From-SVN: r223866
parent 6759edde
2015-05-29 Jonathan Wakely <jwakely@redhat.com>
* include/std/future (__async_result_of): New alias template.
(async): Use __async_result_of to pass decayed types to result_of.
* testsuite/30_threads/async/lwg2021.cc: New.
* doc/xml/manual/intro.xml: Document LWG 2021 status.
PR libstdc++/66327
* include/bits/stl_algobase.h (__equal<true>::equal): Do not call
memcmp with null pointers.
......
......@@ -814,6 +814,12 @@ requirements of the license of GCC.
<listitem><para>Return the end of the filled range.
</para></listitem></varlistentry>
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2021">2021</link>:
<emphasis>Further incorrect uses of <code>result_of</code></emphasis>
</term>
<listitem><para>Correctly decay types in signature of <code>std::async</code>.
</para></listitem></varlistentry>
</variablelist>
</section>
......
......@@ -168,12 +168,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
deferred
};
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2021. Further incorrect usages of result_of
template<typename _Fn, typename... _Args>
future<typename result_of<_Fn(_Args...)>::type>
using __async_result_of = typename result_of<
typename decay<_Fn>::type(typename decay<_Args>::type...)>::type;
template<typename _Fn, typename... _Args>
future<__async_result_of<_Fn, _Args...>>
async(launch __policy, _Fn&& __fn, _Args&&... __args);
template<typename _Fn, typename... _Args>
future<typename result_of<_Fn(_Args...)>::type>
future<__async_result_of<_Fn, _Args...>>
async(_Fn&& __fn, _Args&&... __args);
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
......@@ -727,7 +733,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<_Res>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
friend future<typename result_of<_Fn(_Args...)>::type>
friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<_Res> _Base_type;
......@@ -770,7 +776,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<_Res&>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
friend future<typename result_of<_Fn(_Args...)>::type>
friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<_Res&> _Base_type;
......@@ -813,7 +819,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class promise<void>;
template<typename> friend class packaged_task;
template<typename _Fn, typename... _Args>
friend future<typename result_of<_Fn(_Args...)>::type>
friend future<__async_result_of<_Fn, _Args...>>
async(launch, _Fn&&, _Args&&...);
typedef __basic_future<void> _Base_type;
......@@ -1699,10 +1705,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// async
template<typename _Fn, typename... _Args>
future<typename result_of<_Fn(_Args...)>::type>
future<__async_result_of<_Fn, _Args...>>
async(launch __policy, _Fn&& __fn, _Args&&... __args)
{
typedef typename result_of<_Fn(_Args...)>::type result_type;
std::shared_ptr<__future_base::_State_base> __state;
if ((__policy & launch::async) == launch::async)
{
......@@ -1714,16 +1719,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__state = __future_base::_S_make_deferred_state(std::__bind_simple(
std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
}
return future<result_type>(__state);
return future<__async_result_of<_Fn, _Args...>>(__state);
}
/// async, potential overload
template<typename _Fn, typename... _Args>
inline future<typename result_of<_Fn(_Args...)>::type>
inline future<__async_result_of<_Fn, _Args...>>
async(_Fn&& __fn, _Args&&... __args)
{
return async(launch::async|launch::deferred, std::forward<_Fn>(__fn),
std::forward<_Args>(__args)...);
return std::async(launch::async|launch::deferred,
std::forward<_Fn>(__fn),
std::forward<_Args>(__args)...);
}
#endif // _GLIBCXX_ASYNC_ABI_COMPAT
......
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do compile { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } }
// { dg-options " -std=gnu++11 -pthread" { target *-*-freebsd* *-*-dragonfly* *-*-netbsd* *-*-linux* *-*-gnu* powerpc-ibm-aix* } }
// { dg-options " -std=gnu++11 -pthreads" { target *-*-solaris* } }
// { dg-options " -std=gnu++11 " { target *-*-cygwin *-*-darwin* } }
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { dg-require-atomic-builtins "" }
// LWG 2021. Further incorrect usages of result_of
// Arguments to result_of should use decay.
#include <future>
struct A
{
int operator()(int&&)&& { return 0; }
void operator()(int&)& { }
};
int main()
{
A a;
int i = 0;
std::future<int> f = std::async(a, i);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment