Boost logo

Boost :

Subject: Re: [boost] Query of interest for a container output library
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2013-01-31 12:27:38


> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Tal Zion
> Sent: Thursday, January 31, 2013 4:26 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Query of interest for a container output library
> --
> View this message in context:
http://boost.2283326.n4.nabble.com/Query-of-interest-for-a-container-
> output-library-tp4641997p4642051.html

I don't want to muddy this conversation, but I wonder if you are ignoring Steven Watanabe's
type_erasure library (perhaps because it's highly un- or anti-descriptive name).

http://www.boost.org/doc/libs/1_52_0/doc/html/container/containers_of_incomplete_types.html

It provides what many users want to list containers without much tiresome typing or any troublesome
'typing'.

But (at the price of some compile time) it *also provides very easy (and quite fancy) formatting*.

Steven's simple example is:
int test[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

separator_printer p1(", "); // Construct a sequence printer with comma separator.
p1.print(std::cout, test); // Outputs: 1,2,3,4,5,6,7,8,9,10

where test could be any ostreamable container.

but with a little more work one can produce other 'printers' which give a lot of layout control
using parameters, for example:

decor_printer p1decor("int[10] = {", ", ", "};\n"); // Construct a sequence printer with prefix {,
comma separator and } newline terminator.

A few typical (and more fancy) examples of output are:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10|
  int[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  1___2___3___4___5___6___7___8___9___10
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  
  +1.0000, +2.0000, +3.0000, +4.0000, +5.0000, +6.0000, +7.0000, +8.0000, +9.0000, +10.000
  
  2345.6 m, 123.40 m, 0.012300 m
  45210.(+/-1234.0) m, 789.00(+/-2.5000) m, 0.00056700(+/-2.3400e-005) m
  one, two, three, four, five, six, seven, eight, nine, ten
  ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN
  1,2,3,4,
  5,6,7,8,
  9,10
                 1 4 7 10
                 2 5 8
                 3 6 9
  
  1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000, 7.0000, 8.0000, 9.0000, 10.000
  1.0000,2.0000,3.0000,4.0000,
  5.0000,6.0000,7.0000,8.0000,
  9.0000,10.000
  3.0000,4.0000,5.0000,6.0000,
  7.0000
  0, -2.0000
  1, 9.9000
  1, 9.9000
  4, 6.6000
  1, 9.9000
  2, 8.8000
  3, 7.7000
  4, 6.6000
  
  1, 9.9000,2, 8.8000,3, 7.7000,4, 6.6000
  
  1.23 +/-0.056 (42)
  1.23 +/-0.056 (42),4.56 +/-0.021 (99)
  1.23 +/-0.056 (42) First #1, 2012-Aug-10 10:03:35
  4.56 +/-0.021 (99) Second #1, 2012-Aug-08 10:01:56
  1.23 +/-0.056 (42) First #1, 2012-Aug-10 10:03:35,4.56 +/-0.021 (99) Second #1, 2012-Aug-08
10:01:56

Some are probably messed up by the browser but you will get the flavour.

Paul


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