[Fusion] Adapted struct with member optional<variant<A, B>> needs typedef
Hello, The following program (written in VS2008/VC9 with Boost 1.44) doesn't compile: #include <boost/fusion/include/adapt_struct.hpp> #include <boost/optional.hpp> #include <boost/variant/variant.hpp> #include <string> #include <vector> struct Word {std::string str;}; struct Text {std::string str;}; struct Transition { boost::optional<boost::variant<Word,Text>> token; }; BOOST_FUSION_ADAPT_STRUCT(Word,(std::string, str)) BOOST_FUSION_ADAPT_STRUCT(Text,(std::string, str)) BOOST_FUSION_ADAPT_STRUCT( Transition, (boost::optional<boost::variant<Word,Text>>, token) ) int main(int argc,char *argv[]) { return 0; } Compiler output: error warning C4002: too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0'. <etc> If I introduce a typedef for the long type: typedef boost::optional<boost::variant<Word,Text>> TokenType; and change the adapt struct to use the shorter name, it works: BOOST_FUSION_ADAPT_STRUCT( Transition, (TokenType, token) ) Why is this, and what are the constraints on the types fed to BOOST_FUSION_ADAPT_STRUCT? Thanks, Pete
Hi Pete, On Mon, Sep 27, 2010 at 5:28 AM, PB <newbarker@gmail.com> wrote: <snip code>
BOOST_FUSION_ADAPT_STRUCT( Transition, (boost::optional<boost::variant<Word,Text>>, token) ) <snip code> Compiler output: error warning C4002: too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0'. <etc>
Why is this, and what are the constraints on the types fed to BOOST_FUSION_ADAPT_STRUCT?
The problem seems to be that the preprocessor is seeing the ',' in boost::variant and is parsing it like a tuple of 3 objects: "boost::optional<boost::variant<Word," "Text>>" and "token", while Boost.Fusion expects 2 objects. The normal solution is to add a set of parentheses around the token with a comma, but that doesn't seem to work here. I think your typedef solution is probably the simplest and best for this case -- but my skills with the preprocessor are definitely incomplete. HTH, Nate
On Mon, Sep 27, 2010 at 5:19 PM, Nathan Crookston <nathan.crookston@gmail.com> wrote:
Hi Pete,
On Mon, Sep 27, 2010 at 5:28 AM, PB <newbarker@gmail.com> wrote: <snip code>
BOOST_FUSION_ADAPT_STRUCT( Transition, (boost::optional<boost::variant<Word,Text>>, token) ) <snip code> Compiler output: error warning C4002: too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0'. <etc>
Why is this, and what are the constraints on the types fed to BOOST_FUSION_ADAPT_STRUCT?
The problem seems to be that the preprocessor is seeing the ',' in boost::variant and is parsing it like a tuple of 3 objects: "boost::optional<boost::variant<Word," "Text>>" and "token", while Boost.Fusion expects 2 objects. The normal solution is to add a set of parentheses around the token with a comma, but that doesn't seem to work here. I think your typedef solution is probably the simplest and best for this case -- but my skills with the preprocessor are definitely incomplete.
Nate, Ahh. I didn't think about the comma. Perhaps the BOOST_FUSION_ADAPT_STRUCT macro itself needs some parentheses internally. I'll stick to the typedef but hopefully if this can be fixed, the right people are viewing this topic. Thanks, Pete
PB schrieb:
On Mon, Sep 27, 2010 at 5:19 PM, Nathan Crookston <nathan.crookston@gmail.com> wrote:
Hi Pete,
On Mon, Sep 27, 2010 at 5:28 AM, PB <newbarker@gmail.com> wrote: <snip code>
BOOST_FUSION_ADAPT_STRUCT( Transition, (boost::optional<boost::variant<Word,Text>>, token) ) <snip code> Compiler output: error warning C4002: too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0'. <etc>
Why is this, and what are the constraints on the types fed to BOOST_FUSION_ADAPT_STRUCT?
The problem seems to be that the preprocessor is seeing the ',' in boost::variant and is parsing it like a tuple of 3 objects: "boost::optional<boost::variant<Word," "Text>>" and "token", while Boost.Fusion expects 2 objects. The normal solution is to add a set of parentheses around the token with a comma, but that doesn't seem to work here. I think your typedef solution is probably the simplest and best for this case -- but my skills with the preprocessor are definitely incomplete.
Nate,
Ahh. I didn't think about the comma. Perhaps the BOOST_FUSION_ADAPT_STRUCT macro itself needs some parentheses internally.
I'll stick to the typedef but hopefully if this can be fixed, the right people are viewing this topic.
I think this issue cannot be fixed. Is there a method to extract a type from a parenthesized type expression without losing cv-qualifiers? BTW. this issue already came up a few times. Paul Mensonides summed it up pretty well 7 years ago: http://article.gmane.org/gmane.comp.lib.boost.devel/84424 -Christopher
On Mon, Sep 27, 2010 at 7:26 PM, Christopher Schmidt <mr.chr.schmidt@online.de> wrote:
PB schrieb:
On Mon, Sep 27, 2010 at 5:19 PM, Nathan Crookston <nathan.crookston@gmail.com> wrote:
Hi Pete,
On Mon, Sep 27, 2010 at 5:28 AM, PB <newbarker@gmail.com> wrote: <snip code>
BOOST_FUSION_ADAPT_STRUCT( Transition, (boost::optional<boost::variant<Word,Text>>, token) ) <snip code> Compiler output: error warning C4002: too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0'. <etc>
Why is this, and what are the constraints on the types fed to BOOST_FUSION_ADAPT_STRUCT?
The problem seems to be that the preprocessor is seeing the ',' in boost::variant and is parsing it like a tuple of 3 objects: "boost::optional<boost::variant<Word," "Text>>" and "token", while Boost.Fusion expects 2 objects. The normal solution is to add a set of parentheses around the token with a comma, but that doesn't seem to work here. I think your typedef solution is probably the simplest and best for this case -- but my skills with the preprocessor are definitely incomplete.
Nate,
Ahh. I didn't think about the comma. Perhaps the BOOST_FUSION_ADAPT_STRUCT macro itself needs some parentheses internally.
I'll stick to the typedef but hopefully if this can be fixed, the right people are viewing this topic.
I think this issue cannot be fixed. Is there a method to extract a type from a parenthesized type expression without losing cv-qualifiers? BTW. this issue already came up a few times. Paul Mensonides summed it up pretty well 7 years ago:
Christopher, Thanks for the link. It's all clear now. Thanks, Pete
participants (3)
-
Christopher Schmidt
-
Nathan Crookston
-
PB