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.


View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at