Boost logo

Boost :

Subject: Re: [boost] [parameter] named template parameters
From: Daniel Wallin (daniel_at_[hidden])
Date: 2011-11-07 05:56:29

On Thu, Nov 3, 2011 at 7:05 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
> On Wed, Nov 2, 2011 at 6:46 PM, Jeffrey Lee Hellrung, Jr.
> <jeffrey.hellrung_at_[hidden]> wrote:
>> On Wed, Nov 2, 2011 at 2:00 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]>wrote:
>>> Hello all (and especially Boost.Parameter's authors),
>>> The Boost.Parameter docs suggest to implement parameter-enabled class
>>> templates using a series of typedes for the argument pack and the
>>> actual argument types. I think it is best to define extra template
>>> parameters with default values to old the argument pack Args and named
>>> template parameters ClassType, etc as shown below. This allows to use
>>> the named template parameters within the class declaration for example
>>> in a base class (boost::python::class_<ClassType, ...>) instead that
>>> just in the class definition.
>>> Do you see any problem in using extra template parameter to define the
>>> argument pack and named template parameters?

This is similar to what I want to do for the C++11 Boost.Parameter
with functions:

  template <
    class... Args, class Pack = typename make_pack<parameters, Args...>::type
  void f(Args&&... args) {
    Pack pack(args...);
    int x = pack[_x];

In the case of class templates, the downside would be that the error
messages would be pretty horrible if the user passes too many
arguments. I guess it would be possible to guard a bit against that
though, and possibly make the error messages better.

>>> A couple more things:
>>> 1) I thing that BOOST_PARAMETER_TEMPLATE_KEYWORD(ClassType) macro
>>> should define a symbol _ClassType to be used for the named parameter
>>> so to be consistent with the BOOST_PARAMETER_NAME(x) which defined _x
>>> to be used for the named function parameter. However, ClassType is
>>> defined without the leading _. What is the reason for this asymmetry?
> Yes but these all sound like implementation reasons to me. If the
> parameter name keywords need the leading _ for functions, as a library
> users I'd expect the template parameters to follow the same
> convention. Why should a user expect template parameter name keywords
> to follow a different convention than function parameter name
> keywords?

We simply preferred making the names less ugly over consistency with
function parameters.

>> 2) I'd expect a macro that allows to specify tag and passing argument
>>> name for template parameters
>>> BOOST_PARAMETER_TEMPLATE_KEYWORD((PassClassType, mytag) ClassType) as
>>> for BOOST_PARAMETER_NAME((pass_x, mytag) x) does for function
>>> parameters. Why is such a usage of BOOST_PARAMETER_TEMPLATE_KEYWORD
>>> not supported?

Nobody implemented it. No real reason not to support it.

Daniel Wallin
BoostPro Computing

Boost list run by bdawes at, gregod at, cpdaniel at, john at