|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-11-13 12:17:57
Peter Dimov wrote:
[snip]
> Does the library support named constructor parameters, by
> the way?
Yes, by creating forwarding constructors and delegating to some init
function.
struct X
{
typedef keywords<...> init_kw;
template<class A0>
X(A0 const& a0)
{
init(init_kw(a0));
}
template<class A0, class A1>
X(A0 const& a0, A1 const& a1)
{
init(init_kw(a0, a1));
}
.. etc ..
private:
template<class Args>
void init(Args const& args)
{
....
}
};
It's harder if you need to use initializer lists. I guess you can do:
template<class A0>
X(A0 const& a0)
: x(init_kw(a0)[x | 0])
, y(init_kw(a0)[y | 0])
{
}
template<class A0, class A0>
X(A0 const& a0, A1 const& a1)
: x(init_kw(a0,a1)[x | 0])
, y(init_kw(a0,a1)[y | 0])
{
}
Or add another level of inheritance to avoid repeating the extraction
and the defaults.
-- Daniel Wallin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk