Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-10-02 05:21:55


| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Scott Woods
| Sent: Wednesday, October 01, 2003 10:00 PM
| To: Boost mailing list
| Subject: Re: [boost] Boost Test tools to test manipulators like hex,
| setw(15)...
|
|
| Have done some manipulator stuff, nothing with Boost test
| and infrequent flossing. Dont know if this is anything like
| a solution but your prototype of toString seemed odd;

| Should it not be;
|
| string toString(int value, std::ios_base& (* manipulator )(std::ios_base&) )

Indeed you are quite right and this

template <typename T>
string toString(T value, std::ios_base& (*manipulator)(std::ios_base&) )
{ // Convert T to string, using parameterless manipulator like std::hex.
        // Note uses default stream values, unless overwritten by manipulator.
        ostringstream oss;
        oss << manipulator << value; // No << ends required (causes a space and test
failure).
        cout << "value|" << value << "|" << ", toString |" << oss.str() << "|" <<
endl; // for test only.

        return oss.str();
}

works as expected:

toString(15, std::hex);

 outputs: value|15|, toString |f|

But I am now stuck trying to test setw and setprecision with, for example,
toString(15, setw(10))

at first expecting

string toString(T value, std::ios_base& (*manipulator(int))(std::ios_base&) )

or should it be

string toString(T value, ) ?

to do the business,

but for these the compiler reports it is trying to match

(int, std::_Smanip<_Arg>)

(My fancy manipulators with an int parameter don't use smanip, so will I have to
provide another version using std::ios_base& (*manipulator)(int)(std::ios_base&)
?)

Further IOS expert suggestions most welcome.

Thanks

Paul

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


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