Boost logo

Boost :

Subject: Re: [boost] Boost.Convert+Boost.Parameter
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-02-24 13:56:11


Vladimir.Batov_at_[hidden] wrote:

> So, convert() can take those parameters in. Given we do not know how many
> parameters there might be I'd suggest we set those parameters with
> operator(). Like
>
> convert<string, int>(str)(default_ = -1)(throw_ =
> false)(some_other_parameter_ = ...)

There's no need for that clumsy syntax. The Boost.Parameter keywords
already provide the operator, overload, so you can write:

   convert< string >((param1 = val1, param2 = val2, ...));

...and so on for as many parameters you like. Note the double
parenthesis. The "convert" function here accepts only _one_ argument,
which is basically a tuple of references to the argument values with a
fancy syntax for retrieving them:

   template< typename ToT, typename ArgsT >
   ToT convert(ArgsT const& args)
   {
     int p1 = args[param1]; // mandatory
     string p2 = args[param2 | "ouch"]; // optional
   }

Boost.Parameter also provide macros that allow to declare the "convert"
function in order to elide the need of the double parenthesis and to
even allow to mix the positional arguments with named ones.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk