Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.Convert
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-02-20 21:18:22


On Thu, Feb 19, 2009 at 12:57 PM, Andrew Troschinetz
<ast_at_[hidden]> wrote:
> 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.
>
> 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)

My problem with the convert_to<int> syntax is that it demands that the
function it binds to is a template. For me it is crucial for any to-
and from- string conversion framework to be able to bind simple
user-defined overloads like:

class foo;
char const * to_string( foo const & );

or

class bar;
std::string to_string( bar const & );

or

template <class T> class foobar;

template <class T>
std::string to_string( foobar<T> const & );

The interface specification, I think, has to be that converting to
string is done through unqualified call (so ADL kicks in) using
automatic argument deduction if templates are involved.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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