|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2006-03-06 17:02:26
Rene Rivera wrote:
> I've been Boost.Parameter a bit by now and I have some usability
> feedback. There is one thing that currently bugs be a bit, the type
> defined by parameter::binding. All my uses so far have been of the form:
>
> typedef typename
> boost::remove_reference<
> boost::remove_const<
> boost::parameter::binding<ArgPack,tag::something>::type
> >::type
> >::type
> something_t;
>
> something_t s = args[something];
>
> Or equivalent thereof. So every use I have I end up removing the ref and
> const because I'm really interested in the original type, and hence want
> to make a copy. Now I understand the rational outlined in "Eliminating
> Copies"
> <http://www.boost.org/libs/parameter/doc/html/index.html#eliminating-copies>.
> But I think that isn't enough of a justification for dirtying up the
> user interface, as above. I'd rather that the binding type where the
> value type so that one would have:
>
> typedef typename
> boost::parameter::binding<ArgPack,tag::something>::type
> something_t;
>
> something_t s = args[something];
>
> Having it that way one still has the option of more naturally using the
> reference type as;
>
> something_t const & q = args[something];
I don't think the rationale for this is completely expressed in the
docs. The reason binding<> works like this is because of dangling
references to defaults. Consider from your example above:
something_t const & q = args[something | 0];
When binding<> returns the default type here you will get a dangling
reference here:
int const& = args[something | 0]
Our design handles this by letting binding<> return a reference type
when an argument is bound to the keyword, and otherwise return the
default type unchanged.
I would consider adding a binding_value<> metafunction though.
-- Daniel Wallin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk