Boost logo

Boost :

Subject: Re: [boost] [variant] assign and access the assigned value simultaneously
From: feverzsj (feverzsj_at_[hidden])
Date: 2014-03-28 13:21:52


hi list,
   Let me explain this in more detail.
   Say, if one want to renew an object of some type which may be hold by a
variant, and not care about the object's old data, he may do somthing like:
       
       // assure variant hold object of type T
       if(var.which() != T's index)
             var = T(); // 2 visitation + copy
       T& t = boost::get<T>(var); // 1 visitation
       // process t

   If we have T& t = var.assign(T()), 1 visitation can be eliminated.
   If we have T& t = var.construct<T>(...), only 1 visitation and optionally
1 in place construction are needed.

regars.

--
View this message in context: http://boost.2283326.n4.nabble.com/variant-assign-and-access-the-assigned-value-simultaneously-tp4660327p4660782.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk