Opened 12 years ago
Last modified 12 years ago
#4857 new Bugs
Boost.Parameter Constructor in Templates Not Supported?
Reported by: | Dean Michael Berris | Owned by: | Daniel Wallin |
---|---|---|---|
Milestone: | To Be Determined | Component: | parameter |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: |
Description
If I try to create a Boost.Parameter Constructor as shown in the following code listing, I get a handful of errors in the preprocessor code used by BOOST_PARAMETER_CONSTRUCTOR
:
#include <boost/parameter.hpp> namespace foo { BOOST_PARAMETER_NAME(arg1) BOOST_PARAMETER_NAME(arg2) template <class Tag> struct base { template <class ArgPack> base(ArgPack const & args) : val1(args[_arg1]) , val2(args[_arg2]) {} int val1,val2; }; template <class Tag> struct derived : base<Tag> { BOOST_PARAMETER_CONSTRUCTOR( derived, (base<Tag>), tag, (optional (arg1,int,1) (arg2,int,2))) }; } /* foo */ struct default_ {}; int main(int argc, char * arg[]) { foo::derived<default_> instance(); return 0; }
With GCC 4.4 on Ubuntu Linux I get the following errors:
dean@dean-desktop:~/Source/spike$ g++ -o boost_parameter_template boost_parameter_template.cpp -I~/boost/ boost_parameter_template.cpp:24: error: macro "BOOST_PARAMETER_FOR_EACH_pred_aux2" passed 3 arguments, but takes just 2 boost_parameter_template.cpp:24: error: macro "BOOST_PP_SPLIT_0" requires 2 arguments, but only 1 given boost_parameter_template.cpp:24: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given boost_parameter_template.cpp:24: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given boost_parameter_template.cpp:24: error: ‘BOOST_PP_IIF_0’ was not declared in this scope boost_parameter_template.cpp:24: error: template argument 1 is invalid boost_parameter_template.cpp:24: error: ‘BOOST_PP_REPEAT_1_BOOST_PP_TUPLE_ELEM_2_0’ does not name a type
Attachments (1)
Change History (3)
by , 12 years ago
Attachment: | boost_parameter_template.cpp added |
---|
comment:1 by , 12 years ago
There are two problems here:
- Type requirements should be parenthesized:
(arg1, (int))
- BOOST_PARAMETER_CONSTRUCTOR() is far less convenient than BOOST_PARAMETER_FUNCTION() in that it does not take default values for optional parameters, but rather expects the base constructor to do the right thing. This is shown in the docs at:
but is missing from the reference documentation.
Changing your example accordingly:
struct base { template <class ArgPack> base(ArgPack const & args) - : val1(args[_arg1]) - , val2(args[_arg2]) + : val1(args[_arg1 | 0]) + , val2(args[_arg2 | 0]) {} int val1,val2; @@ -24,7 +24,7 @@ struct derived : base<Tag> { BOOST_PARAMETER_CONSTRUCTOR( derived, (base<Tag>), tag, - (optional (arg1,int,1) (arg2,int,2))) + (optional (arg1,(int)) (arg2,(int)))) };
makes it compile.
comment:2 by , 12 years ago
Interesting, thanks Daniel. I hope the documentation gets updated with a simple explanation between the difference between BOOST_PARAMETER_CONSTRUCTOR()
and BOOST_PARAMETER_FUNCTION()
.
I think this ticket can be closed now, hoping to see a different ticket filed for updating the documentation for the clarification.
Original test file to reproduce the problem.