On Mon, Sep 8, 2008 at 5:39 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG


Ovanes Markarian wrote:
so you mean there are no VTable fakes inside as it is suggested by Andrei
and in fact an additional numeric type identifier is stored? Which type from
the type list is stored?
 

At the lowest level, boost::variant<std::string, int> (e.g.)
looks something like:

class variant {
  boost::aligned_storage<
      max(sizeof(std::string), sizeof(int)),
      lcm(alignment_of<std::string>::value, alignment_of<int>::value)> buffer_;
  int which_;
};

apply_visitor is implemented something to the effect of

switch(which_) {
  case 0: return(f(*static_cast<std::string*>(buffer_.address())));
  case 1: return(f(*static_cast<int*>(buffer_.address())));

}

Ok! That's great. This is what I was concerned of. So variant provides basic thread safety guarantee.