
Scott,
Thanks. What you're proposing is an elegant work around.
I posted separately but it leaves me feeling I'm missing something about
extensibility that the std/boost authors had in mind.
Regards, Andy
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Scott McMurray
Sent: 07 April 2008 23:10
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [boost][lexical_cast] simple example doesn't
workwith vector<T>
On Mon, Apr 7, 2008 at 3:26 PM, Andy Stevenson
The suggestions were to put it into namespace std or boost, both seem to work by the way.
However what is actually right here? Extending std seems distinctly non-std !
I really don't like either of them. Putting it in std:: is non-standard, and unsafe in practice as it's quite plausible that many people would want to give an implementation for it. Putting it in boost:: isn't really satisfactory either, since then it won't be simple to call in your normal code. Perhaps do something like this: template <typename T> struct space_separated_formatter { T &c; space_separated_formatter(T &c_) : c(c_) {} }; template <typename T> space_separated_formatter<T const> space_separated(T const &c) { return space_separated_formatter<T const>(c); } namespace std { template <typename T> ostream &operator<<(ostream &sink, space_separated_formatter<T> const &c) { copy( c.begin(), c.end(), ostream_iterator<typename T::value_type>(sink, " ") ); return sink; } } then boost::lexical_caststd::string( space_separated(myvec) ) or std::cout << space_separated(myvec); Still perhaps illegal, but probably safe in practice, especially if you wrap the type up into a namespace, since it'd make collisions unlikely. But whether it'd be worth it is a whole other story... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users