From: David Abrahams (dave_at_[hidden])
Date: 2004-11-18 09:38:24
Daniel Wallin <dalwan01_at_[hidden]> writes:
> Joel de Guzman wrote:
>> 1) WRT DSL, I'm not quite sure about the syntax for
>> defaults. Example:
>> params[name | "unnamed"]
>> I have a strong feeling that there's a better syntax but I am
>> not sure what it is now. I read in the thread that the syntax
>> params[name] | "unnamed"
>> is not doable, but I'm not quite sure. Perhaps a clarification
>> will set me straight. Having the default in the brackets seems to
>> rather awkward. Perhaps:
>> is better?
> That has exactly the same problem as having the | outside the brackets.
> The problem is that operator would need to return something other than
> the actual parameter reference, something that:
> 1) Is convertible to the parameter type.
> We still need params[name], with no default to work.
> 2) Has operator|() or defaults_to() member function.
> So, we'd need a conversion operator. But if we have a conversion
> operator, we can't reliably pass the arguments to function templates
> because the type deduction will go wrong.
One possible alternative is
but I find that highly illogical to read, because the specification
of the default precedes the keyword it's defaulting.
However, Thorsten's prodding has made me wonder if we need || for the
lazy case at all. It seems as though
params.has(name) ? params[name] : something_else;
is superior in every way except brevity. And there will be
substantial cases where it's briefer as well, because there's no need
to build a function object for something_else.
Am I missing something?
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk