[variant] forward declarations
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++? I am building against Visual Studio 2013, Boost 1.55. Thank you... Best regards, Michael Powell
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. 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. HTH, Nate
On Fri, Jul 18, 2014 at 2:37 PM, Nathan Crookston
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Michael Powell
-
Nathan Crookston