|
Boost : |
From: Ullrich Koethe (u.koethe_at_[hidden])
Date: 2001-04-05 08:41:25
David Abrahams wrote:
>
> ----- Original Message -----
> From: <jk_at_[hidden]>
>
> > 5 Apr 2001 11:04:29 +0400 David Abrahams wrote:
> > >ParameterAdapter template has all the problems I alluded to: it is
> > >overloaded for a limited number of argumeents,
> >
> > It's better than nothing. I cannot imagine some API, standard or not,
> where
> > are functions with more than, say, 6 arguments; if there is more, it is
> sign
> > not to use this API (for me). So traits for functions having up to 10
> > parameters is absolutely enough. It is not perfect, but it will work and
> will
> > be useful. Anyway we cannot get better solution with the language as it is
> > now.
>
> I didn't read the paper in detail, but I don't see what the ParameterAdapter
> buys us over, say, what I did in Boost.Python. Again, am I missing
> something?
>
I think you are. The paper proposes to use heterogenous value lists to
pass arguments to functions and, in particular, constructors. It looks
like this:
class Foo
: public Bar
{
int size;
float norm;
template <class T>
Foo(List<T> const & args)
: size(Nth<0>(args)),
norm(Nth<1>(args)),
Bar(rest<2>(args))
{}
};
You would use it like this:
Foo foo(list(1, list(2.0, list("Bar's argument"))));
By a simple convenience function, you could abbreviate it to
Foo foo(list(1, 2.0, "Bar's argument"));
The technique becomes even more interesting if you introduce keyword
arguments:
struct Norm {};
struct Size {};
struct BarsArg {};
class Foo
: public Bar
{
int size;
float norm;
static const int default_size;
static const float default_norm;
template <class T>
Foo(KeywordList<T> const & args)
: size(get<Size>(args, default_size)), // use the default if the
norm(get<Norm>(args, default_norm)), // keyword isn't in the list
Bar(rest<2>(args))
{}
};
This would be used like this (Note that Size is not given):
Foo foo(list<Norm>(2.0, list<BarsArg>("Bar's argument)));
This approach completely eliminates the whole issue of how many
parameters a function has, in which order they occur, and whether some
can be left out in favour of a default. On the other hand, it departs
totally from the rest of C++, and it will probrably compile forever. But
still, a very interesting thought.
Regards
Ulli
-- ________________________________________________________________ | | | Ullrich Koethe Universität Hamburg / University of Hamburg | | FB Informatik / Dept. of Computer Science | | AB Kognitive Systeme / Cognitive Systems Group | | | | Phone: +49 (0)40 42883-2573 Vogt-Koelln-Str. 30 | | Fax: +49 (0)40 42883-2572 D - 22527 Hamburg | | Email: u.koethe_at_[hidden] Germany | | koethe_at_[hidden] | | WWW: http://kogs-www.informatik.uni-hamburg.de/~koethe/ | |________________________________________________________________|
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk