Subject: Re: [boost] Holding char arrays in boost variants, what is the correct way?
From: Troy Straszheim (straszheim_at_[hidden])
Date: 2011-06-14 12:18:24
On Tue, Jun 14, 2011 at 8:23 AM, Michael Goldshteyn <mgoldshteyn_at_[hidden]
> What is the correct way of getting several character arrays into a variant:
> // This doesn't work
> typedef boost::variant<int,char,char> MyType;
And it is odd looking. IIRC the problem is that those two array types decay
// This does, but seems like a lot of work
> template <int len>
> struct MyChar
> char val_[len];
> typedef boost::variant<int,MyChar<256>,MyChar<8192> > MyType;
> What is the best way to do this?
variant<int, boost::array<char, 256>, boost::array<char, 8192> >
is what you've got above minus some wheel-reinventing, but IIRC the variant
always carries enough storage around with it to store the largest type in
its argument list (see make_storage)... so you won't save space with this,
if that is your intention.