Boost C++ Libraries: Ticket #4857: Boost.Parameter Constructor in Templates Not Supported? https://svn.boost.org/trac10/ticket/4857 <p> 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 <code>BOOST_PARAMETER_CONSTRUCTOR</code>: </p> <pre class="wiki"> #include &lt;boost/parameter.hpp&gt; namespace foo { BOOST_PARAMETER_NAME(arg1) BOOST_PARAMETER_NAME(arg2) template &lt;class Tag&gt; struct base { template &lt;class ArgPack&gt; base(ArgPack const &amp; args) : val1(args[_arg1]) , val2(args[_arg2]) {} int val1,val2; }; template &lt;class Tag&gt; struct derived : base&lt;Tag&gt; { BOOST_PARAMETER_CONSTRUCTOR( derived, (base&lt;Tag&gt;), tag, (optional (arg1,int,1) (arg2,int,2))) }; } /* foo */ struct default_ {}; int main(int argc, char * arg[]) { foo::derived&lt;default_&gt; instance(); return 0; } </pre><p> With GCC 4.4 on Ubuntu Linux I get the following errors: </p> <pre class="wiki">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 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4857 Trac 1.4.3 Dean Michael Berris Tue, 16 Nov 2010 09:14:04 GMT attachment set https://svn.boost.org/trac10/ticket/4857 https://svn.boost.org/trac10/ticket/4857 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_parameter_template.cpp</span> </li> </ul> <p> Original test file to reproduce the problem. </p> Ticket Daniel Wallin Tue, 16 Nov 2010 09:46:33 GMT <link>https://svn.boost.org/trac10/ticket/4857#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4857#comment:1</guid> <description> <p> There are two problems here: </p> <ol><li>Type requirements should be parenthesized: <pre class="wiki"> (arg1, (int)) </pre></li></ol><ol start="2"><li>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: </li></ol><blockquote> <p> <a href="http://www.boost.org/doc/libs/1_44_0/libs/parameter/doc/html/index.html#parameter-enabled-constructors">http://www.boost.org/doc/libs/1_44_0/libs/parameter/doc/html/index.html#parameter-enabled-constructors</a> </p> </blockquote> <blockquote> <p> but is missing from the reference documentation. </p> </blockquote> <p> Changing your example accordingly: </p> <pre class="wiki"> struct base { template &lt;class ArgPack&gt; base(ArgPack const &amp; 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&lt;Tag&gt; { BOOST_PARAMETER_CONSTRUCTOR( derived, (base&lt;Tag&gt;), tag, - (optional (arg1,int,1) (arg2,int,2))) + (optional (arg1,(int)) (arg2,(int)))) }; </pre><p> makes it compile. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dean Michael Berris</dc:creator> <pubDate>Tue, 16 Nov 2010 09:58:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4857#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4857#comment:2</guid> <description> <p> Interesting, thanks Daniel. I hope the documentation gets updated with a simple explanation between the difference between <code>BOOST_PARAMETER_CONSTRUCTOR()</code> and <code>BOOST_PARAMETER_FUNCTION()</code>. </p> <p> I think this ticket can be closed now, hoping to see a different ticket filed for updating the documentation for the clarification. </p> </description> <category>Ticket</category> </item> </channel> </rss>