This is quite neat, and works for me using MSVC 7.0 but:

1 The layout is screwed up by the mail attachment process and requires some
editing to avoid compile errors.

2  The filename formatlist.hpp might be better?

3  Requires language extensions enabled.

Compiling...
testFomatList.cpp
testFomatList.cpp(38) : warning C4239: nonstandard extension used : 'argument' :
conversion from 'stl::formatlist_t<ForwardIterator>' to
'stl::formatlist_t<ForwardIterator> &'
        with
        [
            ForwardIterator=std::vector<int,std::allocator<int>>::iterator
        ]
        and
        [
            ForwardIterator=std::vector<int,std::allocator<int>>::iterator
        ]
        A reference that is not to 'const' cannot be bound to a non-lvalue
Linking...

Build log was saved at "file://j:\Cpp\FormatList\Debug\BuildLog.htm"
FormatList - 0 error(s), 1 warning(s)

but fails without

Compiling...
testFomatList.cpp
testFomatList.cpp(38) : error C2679: binary '<<' : no operator found which takes
a right-hand operand of type 'stl::formatlist_t<ForwardIterator>' (or there is
no acceptable conversion)
        with
        [
            ForwardIterator=std::vector<int,std::allocator<int>>::iterator
        ]

Build log was saved at "file://j:\Cpp\FormatList\Debug\BuildLog.htm"
FormatList - 1 error(s), 0 warning(s)

for the line

// default list: "[ i1, i2, ..., in ]"
std::cout << "list = " << stl::formatlist( v ) << '\n';

I suspect this can be cured to make it more Standard and more portable?

4  I haven't tried with the all important 3 and  more dimensions like matrixes.

5  Many more examples and documentation desirable, of course.  My slightly
longer test file attached. (Last example might suit input to a spreadsheet using
tab as a separator?)

and finally a nit -  Separator is wrongly spelled.

Paul

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


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Reece Dunn
> Sent: Friday, March 14, 2003 6:07 PM
> To: [EMAIL PROTECTED]
> Subject: [boost] Adding a generic list manipulator
>
>
> I have an output stream manipulator that allows the user of it to print out
> a list in a given range (first, last) or by a container c (c.begin(),
> c.end()).
>
> I am looking at adding this into the boost library. The source code for it
> is in the attachment (printlist.hpp).
>
> An example of its use is:
>
> std::vector< int >               v( 10 );
> std::generate( v.begin(), v.end(), std::rand );
>
> // default list: "[ i1, i2, ..., in ]"
> std::cout << "list = " << stl::formatlist( v ) << '\n';
>
> // parenthesis: "( i1, i2, ..., in )"
> std::cout << "list = " << stl::formatlist( v ).format( '(', ')' ) << '\n';
>
> // special: "[ i1 | i2 | ... | in ]"
> std::cout << "list = " << stl::formatlist( v ).format( '|' ).space( true,
> true ) << '\n';
>
> At the moment I have only tested it on MS VC++.NET 7.0, but have only used
> the C++ standard language and the iostream header, so it should work on
> compliant compilers (with non-advanced template support).
>
> Is there any interest for this? Does anyone have comments, suggestions or
> questions? How do I go about adding this into boost and making it
> boost-compliant?
>
> Thanks for your assistance,
>
> -rhd-
> mailto:[EMAIL PROTECTED]
>
>
> _________________________________________________________________
>
>
// test FormatList

#include <iostream>
#include <iomanip>
#include <vector> // for vector
#include <algorithm> // for generate
#include <cstdlib> // for rand

#include "formatList.hpp" // for formatlist

using std::cout;
using std::cin;
using std::endl;
using std::dec;
using std::hex;
using std::boolalpha;
using std::string;
using std::setprecision;
using std::setw;
using std::vector;
using std::generate;

const char nl = '\n';
const char tab = '\t';
const char space = ' ';

int main()
{
        cout << "Test";
#if defined(__FILE__) && defined(__TIMESTAMP__)
        cout << "  " << __FILE__ << space << __TIMESTAMP__;
#endif
        cout << endl;
        std::vector< int > v( 10 );
        std::generate( v.begin(), v.end(), std::rand );

        // default list: "[ i1, i2, ..., in ]"
        std::cout << "list = " << stl::formatlist( v ) << '\n';

        // parenthesis: "( i1, i2, ..., in )"
        std::cout << "list = " << stl::formatlist( v ).format( '(', ')' ) << '\n';

        // special: "[ i1 | i2 | ... | in ]"
        std::cout << "list = " << stl::formatlist( v ).format( '|' ).space( true, true 
) << '\n';

        // special: "( i1 tab i2 tab ... tab in )"
        std::cout << "list = " << stl::formatlist( v ).format('(', ')', tab ).space( 
false, false ) << '\n';
        return 0;
}  // main


/*

Boost post 
Reece Dunn  [EMAIL PROTECTED]

Requires C++ language extension option.

Test  testFomatList.cpp Wed Mar 19 17:43:07 2003
list = [ 41, 18467, 6334, 26500, 19169, 15724, 11478, 29358, 26962, 24464 ]
list = ( 41, 18467, 6334, 26500, 19169, 15724, 11478, 29358, 26962, 24464 )
list = [ 41 | 18467 | 6334 | 26500 | 19169 | 15724 | 11478 | 29358 | 26962 | 2446
4 ]
list = ( 41     18467   6334    26500   19169   15724   11478   29358   26962   2
4464 )
Press any key to continue




*/
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to