Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant] forward declarations
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2014-07-18 15:59:42


On Fri, Jul 18, 2014 at 2:37 PM, Nathan Crookston
<nathan.crookston_at_[hidden]> wrote:
> Hi Michael,
>
> Michael Powell wrote:
>>
>> Hello,
>>
>> I've got some structs in a AST of sorts which the main player in the
>> mix is a node. In at least one of the use cases, one of the variant
>> types must be forward declared at the time the node can be declared.
>> Possibly one or two other similar use cases.
>>
>> Error 2 error C2139: 'xml::xelement' : an undefined class is not
>> allowed as an argument to compiler intrinsic type trait
>> '__is_nothrow_constructible'
>>
>> i:\installs\development\boost.org\1.55.0\boost_1_55_0\stage\include\boost\type_traits\has_nothrow_constructor.hpp
>> 24 1 xml
>>
>> However, I am bumping into C2139, above.
>>
>> Is there any way for variant to work with forward declared structs (or
>> classes, etc)? Or am I just asking too much from C++?
>
>
> Like undiscriminated unions, variant cannot hold incomplete types. Without
> knowing the sizes of its potential members, it wouldn't know the maximum
> size it should allocate.

I was afraid of this.

> The solution to problems like this is usually to hold a pointer to the
> incomplete type (not sure if variant works with move-only types like
> std::unique_ptr). Variant has some syntactic sugar to allow recursive
> variants (where one child could be another variant of the same type) for
> tree-like structures.

It's possible, provided I can persuade Spirit Qi, which I want to
synthesize the results. Instead of variant, possibly I capture a base
node type instead and do some dynamic casting when necessary, but
that's starting to be more trouble than it's worth.

> HTH,
> Nate
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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