Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] A suggestion
From: Vladimir.Batov_at_[hidden]
Date: 2009-02-08 18:52:31


> > Foo default_foo;
> > Foo foo = lexical_cast(str, default_foo);
> >
> > (or whatever instead of lexical_cast) has no Foo::Foo() requirement.
>
> and... how is lexical_cast going to come up with an object into which it
> can stream? Is it going to use default_foo? In that case, what if
> streaming fails partway through? Are you assuming copyability?

Yes, the copy-constructability requirement is still there. Currently
lexicac_cast does

    if(interpreter << arg) {
        Target result; // DEFAULT-CONSTRUCTED
        if (interpreter >> result)
            return result;
    }
    throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)));
    return Target(); // DEFAULT-CONSTRUCTED

For the proposed "extended" interface I imagined something as
simple/minimal as

    if(interpreter << arg) {
        Target result(failure_value); // COPY-CONSTRUCTED
        if (interpreter >> result)
            return result;
    }
    return failure_value; // COPY-CONSTRUCTED

The likely reason I got so hooked up on extending lexical_cast (rather
than branching off) is that it already implements 95% of what I need/do.
With lexical_cast submitted for TR2 I had an impression that it was the
preferred interface we should be utilizing rather than branching off on
our own. Now I get the feeling that people are suggesting/implying we
should leave lexical_cast behind as an
interesting-but-not-quite-successful experiment (which I somewhat agree
with) and start fresh free of its shackles.

V.


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