Boost logo

Boost Users :

Subject: Re: [Boost-users] variant has non-trivial destructor even when all constituents have trivial destructor
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2015-11-27 10:11:09


On 11/26/2015 11:58 PM, ☂Josh Chia (谢任中) wrote:
> It seems that boost::variant has non-trivial destructor even for
> something like boost::variant<int32_t, int64_t>. Thus, It cannot be used
> in situations that call for a POD where calling the destructor is trivial.
>
> Particularly, I can't have a boost::lock_free::queue<boost::variant<X,
> Y>> even both X and Y are trivially destructible.

Just making `variant` trivially destructible would not be enough, as
`boost::lockfree::queue` also requires a trivial copy-assignment operator.

> How about making boost::variant trivially-destructible when everything
> in it is trivially-destructible?

For your particular use case, it would be far simpler to just use plain
old discriminated-unions.

Regards,

-- 
Agustín K-ballo Bergé.-
http://talesofcpp.fusionfenix.com

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