Boost logo

Boost :

Subject: Re: [boost] [variant] awkward recursion
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-10-30 10:11:39

on Mon Oct 29 2012, Steven Watanabe <> wrote:

> On 10/29/2012 02:59 PM, Mathias Gaunard wrote:
>> On 29/10/12 22:33, Dave Abrahams wrote:
>>> As I had feared, and as
>>> demonstrates, extra dynamic allocations will be used to store maps and
>>> vectors (or anything at all?) in the variant.
>> Why not fix the implementation then instead of writing hacks?
> There's no automatic way around dynamic allocation.
> a) vector<variant<...> > requires variant to be complete.
> b) variant<std::vector<...> > requires vector to be
> complete because it needs to know the sizeof(std::vector<...>).
> The only way to break the cyclic dependency is
> to make the size of variant not depend on the
> size of the vector.

Yup. We "know" the indirection is already there in std::vector/map, but
we can't use it. Yes, I realize that the implementation is free to do
the small object optimization, which *could* blow our assumption that
the indirection isn't needed... but in practice, it doesn't. Tant pis.

Dave Abrahams
BoostPro Computing                  Software Development        Training             Clang/LLVM/EDG Compilers  C++  Boost

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