Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread] Can't compile package_task code with 1.54
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2013-06-01 09:15:12


2013/6/1 Vicente J. Botet Escriba <vicente.botet_at_[hidden]>

I don't find a constructor of function from a rvalue functor.
>
> From the standard:
> template<class F> function(F f);
> template <class F, class A> function(allocator_arg_t, const A& a, F f);
> 7 Requires: F shall be *CopyConstructible*. f shall be Callable
> (20.10.11.2) for argument types ArgTypes
> and return type R. The copy constructor and destructor of A shall not
> throw exceptions.
> 8 Postconditions: !*this if any of the following hold:
> — f is a NULL function pointer.
> — f is a NULL pointer to member.
> — F is an instance of the function class template, and !f
> 9 Otherwise, *this targets a copy of f initialized with std::move(f).
> [Note: Implementations are
> encouraged to avoid the use of dynamically allocated memory for small
> callable objects, for example,
> where f’s target is an object holding only a pointer or reference to an
> object and a member function
> pointer. — end note ]
> 10 Throws: shall not throw exceptions when f is a function pointer or a
> reference_wrapper<T> for some
> T. Otherwise, may throw bad_alloc or any exception thrown by F’s copy or
> move constructor.
>
> But I find an assignment
>
> template<class F> function& operator=(F&& f);
> 18 Effects: function(std::forward<F>(f)).swap(*this);
> 19 Returns: *this
>
> This seems confusing. What am I missing?
>
>
>
I don't have a standard but this is in sync what you describe:

http://en.cppreference.com/w/cpp/utility/functional/function/function

http://en.cppreference.com/w/cpp/utility/functional/function/operator%3D

confusing indeed.

Anyway, trying to:

#define BOOST_THREAD_VERSION 4

#include <boost/thread/future.hpp>
#include <functional>

int main()
{
  boost::packaged_task<void()> t;

  std::function<void()> f2;
  f2 = std::move(t);
}

gives exactly the same compilation error:

1>------ Build started: Project: ConsoleApplication2, Configuration: Debug
Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio
11.0\vc\include\xrefwrap(317): error C2248:
'boost::packaged_task<<unnamed-symbol>>::packaged_task' : cannot access
private member declared in class 'boost::packaged_task<<unnamed-symbol>>'
1> with
1> [
1> <unnamed-symbol>=void (void)
1> ]
1> d:\devel\boost_1_54_0_beta1\boost\thread\future.hpp(2783) : see
declaration of 'boost::packaged_task<<unnamed-symbol>>::packaged_task'
1> with
1> [
1> <unnamed-symbol>=void (void)
1> ]
1> c:\program files (x86)\microsoft visual studio
11.0\vc\include\xrefwrap(404) : see reference to function template
instantiation
'std::_Callable_base<_Ty,_Indirect>::_Callable_base<_Ty&>(_Ty2)' being
compiled
1> with
1> [
1> _Ty=boost::packaged_task<void (void)>,
1> _Indirect=false,
1> _Ty2=boost::packaged_task<void (void)> &
1> ]

but that might as well be VC2012 bug as there is plenty :/

Regards,
Simon



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net