From: daniel.kruegler@googlemail.com   
      
   On 2013-01-21 04:16, Frank Birbacher wrote:   
   > Am 19.01.13 16:22, schrieb Daniel Krügler:   
   >> Theoretically this would be possible. I'm not so sure that this is   
   >> really a sufficient reason to extend the rules in that way,   
   >> though.   
   >   
   > Sometimes I wish I could move-initialize the captured values,   
      
   Agreed. This is one of the major complaints currently (following the   
   request for polymorphic lambdas) in regard to constraints on lambda   
   expressions. To my knowledge there is work on this to solve the problem   
   but I cannot find a proposal at the very moment.   
      
   > especially when working with std::function like in:   
   >   
   > typedef std::function Callback;   
   >   
   > Callback twice(Callback c)   
   > {   
   > //will copy "c", but I want to move it into the lambda:   
   > return [c](std::string const& s){   
   > c(s); c(s); // call twice   
   > };   
   > }   
   >   
   > The std::function does not do reference counting, does it? QOI?   
      
   I'm not aware of one (but I haven't looked into many). There is some   
   evidence that a reference-counted implementation would not be   
   conforming, because the difference would be user-observable in a way   
   that would point to a conflict with the wording. In [func.wrap.func.con]   
   p4 we have for the copy constructor:   
      
   function(const function& f);   
   [..]   
      
   4 Postconditions: !*this if !f; otherwise, *this targets a copy of   
   f.target().   
      
   and [func.wrap.func.targ] p3 provides a means to observe the address of   
   the contained target:   
      
   template T* target() noexcept;   
   template const T* target() const noexcept;   
      
   [..]   
      
   3 Returns: If target_type() == typeid(T) a pointer to the stored   
   function target; otherwise a null pointer.   
      
   The wording for std::function is intended to support the   
   short-object-optimization, thought. There are several places that point   
   to special guarantees in regard to function pointers and   
   reference_wrapper objects, such as   
      
   "shall not throw exceptions if f’s target is a callable object passed   
   via reference_wrapper or a function pointer."   
      
   and especially the note   
      
   [ 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 ]   
      
   I just notice that there are currently no no-throw-guarantees for   
   targets that are pointer to members, this looks like an oversight to me   
   and should be changed.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|