Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-02 06:34:02

On Thu, Oct 02, 2003 at 11:37:06AM +0100, Paul A. Bristow wrote:
> Silly me! It helps to put the manipulator first!
> BOOST_MESSAGE("i = "<< makeManip(flog)(hex) << i );
> Question on setw is still relevant.

I imagine

  BOOST_MESSAGE("i = "<< makeManip(flog)( setw(5) ) << i );

or whatever will work. Actually, I am prone to expect that, e.g.,
plain setw(n) works without anything extra, but this is just a guess.
(If neither of these works, ask again and I'll take a closer look.)

If you look at the implementation of makeManip, you'll see there's no
black magic here. In fact, there are just three overloads for the
identity function.

The only reason you have to do crazy stuff for, e.g., "endl" is because
endl is not the name of an object. It's the name of a template
function. Obscure C++ rules allow such a name to be coerced into a
value -- specifically, a pointer to a particular instance of the
template function -- when there is enough local context information to
determine which instance you mean. makeManip() just helps provide this
"coercion context".

In retrospect, a better manipulator design would be to replace stuff like

   template <class WhateverArgs>
   ... endl( ... ) { ... }


   struct endl_type : public manipulator_tag {
      template <class WhateverArgs>
      static ... go( ... ) { ... }
   } endl;
   // and corresponding changes to streams

so that you can use endl (et al.) without jumping through hoops.

-Brian McNamara (lorgon_at_[hidden])

Boost list run by bdawes at, gregod at, cpdaniel at, john at