Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant] variant member function apply_visitor( visitor ) thread-safe?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-09-08 11:55:25


On Mon, Sep 8, 2008 at 5:39 PM, Steven Watanabe <watanabesj_at_[hidden]>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.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net