Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-01 16:20:24


On Wed, Oct 01, 2003 at 09:19:13PM +0100, Paul A. Bristow wrote:
> I have some fancy manipulators that I want to test carefully.
>
> Simply to show the problem, imagine I would like to be able to test the effect
> of the std::ios::hex and setw() manipulators.
>
> I have tried this (but without much expectation as
> BOOST_MESSAGE("message", i << hex); doesn't work (Gennady said he
> might make it in future)
...
> Suggestions - please.

The C++ manipulator interface is IMO (and in hindsight) done all wrong.
Here is what I have done to make it work in FC++:

----------------------------------------------------------------------
// makeManip(aStream)(aManip) returns the manipulator for that stream
// e.g. makeManip(cout)(endl)
template <class C, class T>
struct ManipMaker {
   std::basic_ostream<C,T>& (*
   operator()( std::basic_ostream<C,T>& (*pfn)( std::basic_ostream<C,T>&) )
         const )( std::basic_ostream<C,T>& ) { return pfn; }
   std::basic_ios<C,T>& (*
   operator()( std::basic_ios<C,T>& (*pfn)( std::basic_ios<C,T>& ) )
         const )( std::basic_ios<C,T>& ) { return pfn; }
   std::ios_base& (*
   operator()( std::ios_base& (*pfn)( std::ios_base& ) )
         const )( std::ios_base& ) { return pfn; }
};
template <class C, class T>
ManipMaker<C,T> makeManip( std::basic_ios<C,T>& )
{ return ManipMaker<C,T>(); }
----------------------------------------------------------------------

I expect that even if

   BOOST_MESSAGE("message", i << hex);

doesn't work, you will find that

   BOOST_MESSAGE("message", i << makeManip(cerr)(hex) );

does (assuming that BOOST_MESSAGE goes to "cerr").

-- 
-Brian McNamara (lorgon_at_[hidden])

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