Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.Convert
From: Vladimir Batov (batov_at_[hidden])
Date: 2009-02-20 22:08:31


> It seems like there's still a lot of discussion going on about the
> interface even when Vladimir is plodding on, so I thought I might offer
> another candidate that I haven't seen put forth just yet.

I personally do not mind wotking in such a mode. I am merely implemeting
what we are seemingly settling on (as far as my interpretation goes) like
'convert' as a class, etc. to see how it works out in reality. And,
therefore, my "plodding on" should not be an ideas' deterrent of any kind.

> template<class Target, class Source>
> *unspecified-type* convert_to(const Source& value);
>
> This would give us the flexibility to easily implement an interface that
> could be used like so:
>
> int i = convert_to<int>("5").get(); // get "5" converted to int (throw
> on error)
>
> unsigned u = convert_to<unsigned>("-1").get_or(0); // get "-1" converted
> to unsigned or else 0
>
> int i = convert_to<int>("0xff").get_special(as_hex()); // get "0xff"
> converted to int using as_hex functor

My immediate concern is a lot of new vocabulary introduced. That can provide
tons of useful stuff... that the majority of people might never use.

Secondly, I am not sure what are the advantages of the alternative interface
above. We seem to achieve all the above with the existing interface and only
1 (!) new keyword ("convert_to") in stad of 5 (convert_to, get, get_or,
get_special, as_hex).

// get "5" converted to int (throw on error)
int i = convert_to<int>("5")(throw_t());
// get "-1" converted to unsigned or else 0
unsigned u = convert_to<unsigned>("-1", 0);
// get "0xff" converted to int using as_hex functor
int i = convert_to<int>("0xff") >> std::hex;

With all due respect the interface immediately above looks (to me) more
consistent and easier extendable.

[snip]

Still, I am keeping an open mind on that. If something else comes up, I may
well flip onto your side (the current implementation already looks nothing
as what I started with showing what a "flipper" I am). :-)

V.


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