Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,082 of 33,346    |
|    =?windows-1252?Q?Daniel_Kr=FCgler?= to space.cadet@nokiamail.com    |
|    Re: Is a lambda copied by value when use    |
|    23 May 13 04:18:11    |
   
   From: daniel.kruegler@googlemail.com   
      
   On 2013-05-23 07:39, space.cadet@nokiamail.com wrote:   
   > Hi,   
   > When a lambda is used with say, a std::find_if algorithm, is it a   
   > good idea to allow it to change some variable in the object?   
      
   As usual you have to know what you are doing ;-)   
      
   > That is, is the following a good practice?   
   > std::find_if(std::begin(collection), std::end(collection), [&](thing t)   
   > {   
   > if (t == something)   
   > {   
   > return true;   
   > }   
   > ++row_number;   
   > return false;   
   > });   
      
   Note that stateful function objects in Library algorithms have to   
   ensure that they keep the state external, because such library   
   function are free to copy the provided function object. This is also   
   indicated by the non-normative note in 25.1 p10:   
      
   "[ Note: Unless otherwise specified, algorithms that take function   
   objects as arguments are permitted to copy those function objects   
   freely. Programmers for whom object identity is important should   
   consider using a wrapper class that points to a noncopied   
   implementation object such as reference_wrapper
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca