Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-01-31 07:36:08


I strongly support this suggestion - its very easy but very convenient.
(Why didn't I think of it!)

I note that it uses the default precision etc of ostream os,
but that one can override this for example by adding

   os.precision(10); // Instead of default 6

or
   os.precision(std::numeric_limits<Type>::digits10+2);

if you want to see everything.

Specializations for particular types could provide
different precisions etc.

Paul

Dr Paul A Bristow, hetp Chromatography
Prizet Farmhouse
Kendal, Cumbria
LA8 8AB UK
+44 1539 561830
Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]

> -----Original Message-----
> From: brianjparker [mailto:brianjparker_at_[hidden]]
> Sent: Monday, January 28, 2002 3:11 AM
> To: boost_at_[hidden]
> Subject: [boost] Re: to_string(v)
>
>
> --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> > I just wrote this:
> >
> > template<class V> std::string to_string(V const & v)
> > {
> > std::ostringstream os;
> > os << v;
> > return os.str();
> > }
> >
> > template<> std::string to_string(std::string const & v)
> > {
> > return v;
> > }
> >
> > for Nth time. Why don't we have this in Boost? And where should it
> go?
>
> I agree wholeheartedly with this- I use this function regularly and
> would like to see it in the Boost utility header.
> (An example that I use a lot is in debug messages, e.g. one can
> use "Var 1:" + to_string(var) + "etc...").
>
> A minor improvement may be to add an overload-
>
> inline
> std::string to_string(const char* in)
> {
> std::string str(in);
> return str;
> }
>
> which, although redundant, is more efficient for a C string argument
> (of course, one could just use std::string(in) directly, but using
> to_string is more consistent).
>
> In fact, this would be an excellent function to add to the standard
> <string> header in the next library revision- perhaps someone on the
> committee could put in a formal proposal to add it.
>
> ,Brian Parker
>
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>


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