$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Rene Rivera (grafik.list_at_[hidden])
Date: 2004-11-16 02:45:03
E. Gladyshev wrote:
> 1. I think that one of the important
> applications of the library is creating
> named parameters wrapper around legacy
> C interfaces with a bunch of parameters.
> It seems to me that named parameters functors
> are an elegant way to do it without macros.
> I personally belong to a large group
> of developers who don't favor macros unless there are
> really necessary. Please I don't mean to
> get into a discussion about macros in general.
I don't remember there being a requirement to use macros on this 
named_params library. And I showed how to do exactly that, wrap C style 
function, in my example (in my review) without macros.
> Here is an example with class members.
> I think that it is much more fun
> than macros.  :)
> 
> struct widget
> {
>     //define a named parameters functor
>     typedef ttl::func::named_params_function<
>         int //the function returns 'int'
>         (
>             //'argument name',  'argument type'
>               title,             const char*
>             , style,             ttl::func::numeric_argument<int, 45> 
> //the default is 45
>         )
>     > create_functor;
> 
>     //
>     widget()
>     {
>         //initialize the functor with create_impl
>         create = boost::bind( &widget::create_impl, this, _1, _2 );
>     }
> 
>     create_functor create;
> 
> private:
>     int create_impl( const char* title, int style );
> };
> 
> main()
> {
>     widget w;
> 
>     w.create( w.create.arg<title>("my widget") );
> 
>     return 0;
> 
> }
It may be "fun", but the overhead is overwhelming. I find this 
alternative more appealing...
namespace {
        boost::keyword<struct title_t> title;
        boost::keyword<struct style_t> style;
}
struct widget {
        widget() { }
        int create( const char * title, int style );
        template<class Params>
        inline int create(const Params & params) {
                return create(params[title], params[style | int(45));
        }
};
int main() {
        widget w;
        w.create((title = "my widget));
        return 0;
}
Especially considering that the overhead is *zero* with release 
optimizations. And you can also do the more normal construction by adding:
        template<class Params>
        widget(const Params& params) {
                create(params[title], params[style | int(45));
        }
I fail to see how the functor gives you anything here. Perhaps you need 
a better counter example?
-- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq