Boost logo

Boost :

Subject: Re: [boost] [convert] Default Syntax Idea
From: Vladimir Batov (batov_at_[hidden])
Date: 2009-02-25 04:44:11


> From: <Vladimir.Batov_at_[hidden]>
>> From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>
>> I was thinking a bit about syntax for the default value for the
>> notional boost::convert() and kin. How about the following:
>>
>> int const i(3);
>> string const s("something");
>> int const j(convert<int>(s) | 5);
>
> Yes, this idea is similar to
>
> int j = convert<int>(s).or_default(5);
>
> but does not introduce new vocabulary (my main hesitation). With the
> suggested op|, as I am reading it, it makes perfect reading just like I'd
> read English. And that is usually my criterion for an interface. So, I am
> voting 'yes'... in principle.

Now I am not so sure. In isolation it looks good:

    int j = convert_to<int>(s) | 5;

What happens when we start mixing with

    int j = convert_to<int>(s) | 5 >> std::hex;
    int j = convert_to<int>(s) | 5 >> boost::dothow >> std::hex;
or even
    int j = convert_to<int>(s) >> boost::dothow >> std::hex | 5;

That is, it goes against what you said (and I agree with) -- "Returning a
default value ... ought not be treated like formatting". Above we do treat
the default like formatting, don't we? Now I feel confused and want back to
the comfort of

    int j = convert_from<string, int>(s, 5) >> std::hex;

V.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk