On 4/2/13, Vicente J. Botet Escriba <
vicent...@wanadoo.fr> wrote:
> I would like to know what should be the behavior of the following code
>
> #include <thread>
> #include <future>
> void f1(int &) {}
>
> void g1() {
> std::future<void> f = std::async(f1, 1);
> }
I would want an error. If the parameter is a writable reference,
it's likely the case that the programmer intends to return
information through that reference. We've lost that information
if the above compiles.
> ../example/std_async_test.cpp: In function ‘void g1()’:
> ../example/std_async_test.cpp:13:39: erreur: no matching function for
> call to ‘async(void (&)(int&), int)’
> std::future<void> f = std::async(f1, 1);
> ^
> ../example/std_async_test.cpp:13:39: note: candidates are:
> In file included from ../example/std_async_test.cpp:8:0:
> /usr/gcc-4.8/include/c++/4.8.0/future:1518:5: note: template<class _Fn,
> class ... _Args> std::future<typename std::result_of<_Functor(_ArgTypes
> ...)>::type> std::async(std::launch, _Fn&&, _Args&& ...)
> async(launch __policy, _Fn&& __fn, _Args&&... __args)
> ^
> /usr/gcc-4.8/include/c++/4.8.0/future:1518:5: note: template argument
> deduction/substitution failed:
> ../example/std_async_test.cpp:13:39: note: cannot convert ‘f1’ (type
> ‘void(int&)’) to type ‘std::launch’
> std::future<void> f = std::async(f1, 1);
> ^
> In file included from ../example/std_async_test.cpp:8:0:
> /usr/gcc-4.8/include/c++/4.8.0/future:1538:5: note: template<class _Fn,
> class ... _Args> std::future<typename std::result_of<_Functor(_ArgTypes
> ...)>::type> std::async(_Fn&&, _Args&& ...)
> async(_Fn&& __fn, _Args&&... __args)
> ^
> /usr/gcc-4.8/include/c++/4.8.0/future:1538:5: note: template argument
> deduction/substitution failed:
> /usr/gcc-4.8/include/c++/4.8.0/future: In substitution of
> ‘template<class _Fn, class ... _Args> std::future<typename
> std::result_of<_Functor(_ArgTypes ...)>::type> std::async(_Fn&&, _Args&&
> ...) [with _Fn = void (&)(int&); _Args = {int}]’:
> ../example/std_async_test.cpp:13:39: required from here
> /usr/gcc-4.8/include/c++/4.8.0/future:1538:5: erreur: no type named
> ‘type’ in ‘class std::result_of<void (&(int))(int&)>’
>
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
std-discussio...@isocpp.org.
> To post to this group, send email to
std-dis...@isocpp.org.
> Visit this group at
>
http://groups.google.com/a/isocpp.org/group/std-discussion/?hl=en.
>
>
>
--
Lawrence Crowl