Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2002-02-11 12:05:48


> It's manipulator-like; it can work for user-defined types. Currently,
> though, it is expensive. It needs a seperator between units, because in
> general there is no way to know what is and is not a manipulator.

I have a library to define manipulators in a unified framework
which solves that part of the proble. There should be enough
interest to have it submitted.

> Pretty
> much safe. It's only meant to be a proof of concept at present. Any
> interest?

That syntax is what I already submitted eons ago. See

   http://www.ece.ucdavis.edu/~kenelson/ofrstream.cc

The general opinion here seems to have been that reuse of the operator
<< is a bad idea. Especially because you can end up with something
like

   cout << format<char>("%1");
   cout << y1;

The real question here is what value did you get from
specifying each argument using an operator over a function?
Compare yours/format2/format3...

   cout << format<char>("%1 %2") << name << endi << count << endi << endf;

verses (format2)
  
   cout << format("%1 %2") % name % count;

verses (format3)

   cout << format("%1$s %2$s")(name)(count);

How much clarity was gained from using an operator << verses operator
% or operator()? I personally like << but the detractors have won out,
and I really don't see operator % as a option.

--Karl

 
> // -- test.cpp --
>
> #include "format.hpp"
>
> #include <iostream>
> #include <string>
> #include <complex>
>
> int main()
> {
> int x=6;
> double y=5;
> std::complex<double> y2(5,0.5);
> std::string s="foo";
> std::cout<<format<char>("%1 %0 ")<<y2<<endi<<y<<endi<<x<<endf<<"\n";
> std::cout<<"back to normal"<<std::endl;
> std::cout<<y2<<std::endl;
> std::cout<<format<char>("%1 %2 %0")<<y2<<endi<<y<<endf<<std::endl;
> }


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