c++ - too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_0' -


i'm trying compile simple grammar using boost spirit, compilation error , after spending hour trying figure out reason hope community sees problem or be. source code viper.h:

#pragma once  #include <string> #include <vector>  #define boost_spirit_unicode #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/fusion/adapted/boost_tuple.hpp>  namespace nsunic = boost::spirit::unicode; namespace nsqi = boost::spirit::qi;   namespace viper {      struct identifier     {         std::wstring name;     };      struct identifier2     {         std::wstring name;     };      struct function     {         boost::variant<identifier, identifier2> func;     };      struct program     {         std::vector<function> functions;     }; } boost_fusion_adapt_struct(     viper::identifier,     (std::wstring, name) )  boost_fusion_adapt_struct(     viper::identifier2,     (std::wstring, name) )  boost_fusion_adapt_struct(     viper::function,     (boost::variant<viper::identifier,viper::identifier2>, func) )  boost_fusion_adapt_struct(     viper::program,     (std::vector<viper::function>, functions) )  namespace viper {      template<typename iterator> struct function_parser : nsqi::grammar<iterator, program(), nsqi::space_type>     {         function_parser() : function_parser::base_type(program)         {             identifier %=                 nsqi::eps                 >> (char_('a') > *(nsqi::alnum | nsqi::char_('_')));              identifier2 %=                 nsqi::eps                 >> (char_('b') > *(nsqi::alnum | nsqi::char_('_')));              function %=                 identifier | identifier2;              program %=                 nsqi::eps                 >> +function;         }          nsqi::rule<iterator, identifier()> identifier;         nsqi::rule<iterator, identifier2()> identifier2;         nsqi::rule<iterator, function(), nsqi::space_type> function;         nsqi::rule<iterator, program(), nsqi::space_type> program;     };      std::wstring render(const program& f)     {         std::wostringstream s;          const auto functions_count = f.functions.size();         for(auto j=0; j<functions_count; ++j)         {             if(j>0)             {                 s << l",";             }             s << f.functions[j].name;         }         return s.str();     }      template<typename iterator> std::wstring parse(iterator first, iterator last)     {         using nsqi::phrase_parse;          program f;         function_parser<iterator> fp;          auto b = phrase_parse(first, last, fp, nsqi::space, f);         if(b)         {             return render(f);         }         return std::wstring(l"fail");     }  } 

the output of compiler this:

1>------ build started: project: viper.notepad, configuration: debug win32 ------ 1>build started 24-jan-16 17:40:29. 1>initializebuildstatus: 1>  touching "debug\viper.notepad.unsuccessfulbuild". 1>clcompile: 1>  outputs up-to-date. 1>  viper.notepad.cpp 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): warning c4002: many actual parameters macro 'boost_fusion_adapt_struct_filler_0' 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): error c2146: syntax error : missing ',' before identifier 'attribute_type' 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): error c2065: 'attribute_type' : undeclared identifier 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): error c2143: syntax error : missing '>' before ';' 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): error c2208: 'boost::variant' : no members defined using type 1>c:\users\srzmtl\local_copies\visual studio\visual studio 2010\viper\viper\viper.h(51): fatal error c1903: unable recover previous error(s); stopping compilation 1> 1>build failed. 1> 1>time elapsed 00:00:23.25 ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

line 51 closing ')' of 3rd boost_fusion_adapt_struct() macro.

the problem boost::variant<viper::identifier,viper::identifier2> contains comma (,) , such interpreted 2 arguments preprocessor.

a workaround:

typedef boost::variant<viper::identifier,viper::identifier2> variant;  boost_fusion_adapt_struct(     viper::function,     (variant, func) ) 

some other workarounds listed here.


Comments