Boost logo

Boost :

Subject: [boost] [Fwd: Re: [format] please add operator String()]
From: James Fowler (boost_list_at_[hidden])
Date: 2009-01-28 17:43:13


Thorsten Ottosen wrote:

> ...
> I my mind formatting is so closely tied to strings that I don't see
> any problem in the implicit conversion. IIRC, String.Format in other
> langauages return a String.

Is some valid reason for require explicit conversion? It sure would be
convenient for format to convert implicitly to string.

If there is a valid reason, what about a wrapper class? I've used
something close to the following for the last few years, and it hasn't
bit me so far :

    class sformat : public boost::format {
    public:
        sformat( const std::string &s ) : boost::format( s ) {}
        operator std::string () { return boost::str( *this ); }

        template <class T>
        sformat & operator%( T v ) {
            *((boost::format*)this) % v;
            return *this;
        }
    };

- James

-- 
______________________________________________
      James Fowler,  Open Sea Consulting
  770-714-3124 / james_at_[hidden]
     1486 Surf Court, Marietta, GA, 30066
       http://www.OpenSeaConsulting.com
-- 
______________________________________________
      James Fowler,  Open Sea Consulting
  770-714-3124 / james_at_[hidden]
     1486 Surf Court, Marietta, GA, 30066
       http://www.OpenSeaConsulting.com

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