Subject: Re: [boost] [type-traits] aligned_storage in unions
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-09-20 15:37:35
On 09/20/10 13:56, dherring_at_[hidden] wrote:
> On Mon, 20 Sep 2010, Larry Evans wrote:
>> On 09/20/10 10:50, dherring_at_[hidden] wrote:
>>> In particular, "Temporary Heap Backup" and "Future Direction".
>>> We have some specialized requirements. We couldn't even use
>>> boost::shared_ptr until it added both the custom allocator and deleter.
>>> The "never-empty guarantee" conflicts with our needs and is not a
>>> concern at this time.
>> An alternative to boost::variant is the:
>> which *might* work for you. I say *might* because I don't
>> know exactly what you mean by:
>> "never-empty guarantee" conflicts with our needs
>> because those needs are not spelled out.
> Rephrase: We don't need the never-empty guarantee; but it conflicts
> with the always-in-place requirement. Steven's suggestion to add
> boost::blank looks promising. The documentation should be updated to
> mention it.
I'm still unsure what "always-in-place" means. Based on what Steven
was saying, I'm guessing it means only stack or static storage can
be used (i.e. no calls to new or malloc). Is that right?
If so, then one_of_maybe satisfies that requirement. However,
unlike boost::variant, it makes no provision for failure of
operator= when the source and target are different types; however,
that could be remedied by simply catching any throw and setting
which() to indicate the one_of_maybe was uninitialized. Since
the uninitialized value ( of type nothing, defined here:
) cannot throw during construction, it would workaround the operator=
> This container looks interesting; but other than the sources, I don't
> see any documentation?
Will work on that ;)
> For now, we'll stick with what I've cobbled together.
>>> As a side note, we also must expose both the type of the "which" and the
>>> discriminant to member mapping (which may be N:1; see the CORBA IDL
>>> spec). So I believe boost::variant would still be hard to use even if
>>> the heap issue were resolved.
>> I'm also unsure of what's meant by:
>> the discriminant to member mapping (which may be N:1).
>> If you mean types could be duplicated, IOW, allow:
>> then that's what one_of_maybe does.
>> The one place I found for corba spec (found with google "corba idl
>> spec") was here:
> If you're interested, see also Part 1, section 184.108.40.206 of
> and the C++ mapping on
> We support a slight variant of this spec.
>> This layout (discriminant followed by dependent value) is the
>> exact reverse of the container_one_of_maybe is laid out.
>> Originally, the discrimiant was 1st; however, the following
> That order doesn't bother me too much. The "N:1" notation meant that,
> just like a "switch statement", there may be N cases that specify one
> member. It is also possible for multiple members to have the same type.
This is what I meant to imply by the example:
With the current variant, this won't work; however, it's perfectly OK
with one_of_maybe. One reason I wanted this was to emulate
the way lex works, which returns a discriminated union. Most of
the types in the union are simply unused because one's not really
interested in the character string representation of some keyword,
instead, one is only interested in which keyword was found, and that's
encoded in the discriminant. One_of_maybe has another special
type for this very purpose. It takes up no room (there's
a specialization of size_of template which returns 0 for
this special type); hence, it doesn't contribute to the calculation
of the size of one_of_maybe.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk