Topic: What next for Standard C++ Library?


Author: Kresimir Fresl <fresl@grad.hr>
Date: 1997/11/11
Raw View
Dave Levitt wrote:

> What would be some useful, general purpose utility classes [and
> templates] that could be added without altering the language in the
> current draft standard?

Well, my suggestion is not a new class, but an addition
to iostream classes. I complained about that problem long
ago (it was November 12, 1996 ;o), so I will repeat some
parts of my posting.

My suggestion is to add constructors (and other member
functions) with string parameters to ifstream and ofstream
classes. For example, without them one has to write:

   cout << "Enter file name -> ";
   string file_name;
   cin >> file_name;
   ifstream in_file (file_name.c_str());

instead of just

   ifstream in_file (file_name);

I found that rather annoying. And in many articles there are
recommendations to use vectors instead of C arrays and strings
instead of char*s. Why do we have to manualy convert high level
to low level language constructs? (And, how can one explain
`.c_str()' in beginner's C++ course?)

And here are some quotes from the reply by Mr. Dietmar Kuehl
to my previous posting. (Mr. Kuehl's reply was the only reply,
far as DejaNews knows, but I don't think that this issue
is of such minor interest).
> I think, the 'char const *' constructors and open functions
> should be replaced by functions using 'string', maybe augmented
> by versions taking a 'wstring'. I guess, to effectively raise
> an issue [at ANSI commitee], it would be necessary to think of
> the exact modification to be done and not to leave all the work
> to the committee. The questions arising here are, whether the
> open function should continue to accept 'char const *' or
> accept only objects of type 'string' (I guess for backward
> compatibility it would be necessary to support 'char const *'
> function, maybe as being deprecated),

I think that they should continue to accept `char const *'.
Here's the example (relevant part of it) from 3rd edition
of Stroustrup's book:

  int main (int argc, char* argv[]) {
     std::ifstream from (argv[1]);
     // ...
     std::ofstream to (argv[2]);
     // ...
  }

> and whether there should also be functions accepting arguments
> of type 'wstring' or even member templates accepting
> 'basic_string<T, Traits>'s. I guess, it would be reasonable
> to restrict the modification to accept a 'string' but then
> I don't know how those feel who use 'wstring's for their normal
> strings due to the encoding they use. While it is obvious that
> the open functions using a 'string' can be implemented everywhere
> where they can be implemented using a 'char const *', I don't
> know whether this also holds for 'wstring'.
> --
> <mailto:dietmar.kuehl@uni-konstanz.de>


fres

e-mail: fresl@grad.hr
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Dirk Herrmann <Herrmann@ida.ing.tu-bs.de>
Date: 1997/11/07
Raw View
Dave Levitt wrote:
>
> What would be some useful, general purpose utility classes [and
> templates] that could be added without altering the language in the
> current draft standard?
>
> A couple of suggestions:

- Regular expressions supporting matches against strings etc.
  Maybe this had been discussed by the committee?
  I think XTL offers an implementation, but I have not looked
  at it.

- Hashtables
  Maybe it would have been more consequent to define set and map as
  modifiers of some tree or hashtable representation? like

  template <class T, class Rep = rb_tree<T, less<T>>>
  class set

  or

  template <class T, class Rep = hashtable<T, as_uint<T>, less<T>>>
  class set,
  where as_unit (the hash function) basically performs a static_cast
  to unsigned int (maybe size_t would be better? anyway...)

Best regards, Dirk Herrmann
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/11/07
Raw View
"Paul D. DeRocco" <pderocco@ix.netcom.com> writes:

|>  Dave Levitt wrote:
|>  >
|>  > What would be some useful, general purpose utility classes [and
|>  > templates] that could be added without altering the language in the
|>  > current draft standard?
|>
|>  How about a streambuf, that could be inserted between a stream
|>  and an existing streambuf, that does column counting, tab
|>  expansion, line wrap, and stuff like that? It's always irritated
|>  me that the output formatting features of ostreams (not to
|>  mention printf) didn't handle such details.

So what should these streambuf's do?  It's trivial (well almost, once
you understand the undocumented subtilities of streambuf) to implement
for each specific case.  I even have a template which encapsulates all
of the boilerplating -- I can typically knock up a new filtering
streambuf to do things like this in about 10-15 lines of code.

(I'm going to see about getting this stuff up on the net somewhere.  In
the meantime, if you send me an email requesting it, I'll send it to
you.  Exceptionally, it's even documented in English, rather than
French.)

As an example, the code for a line wrapping inserter:

 class LineWrappingInserter
 {
 public:
  LineWrappingInserter( int pos = 80 )
   :   myLineLength( pos )
   ,   myColumnNo( 0 )
  {
  }
  int                 insert( streambuf* sb , int ch )
  {
   int                 result( 0 ) ;
   if ( ch == '\n' )
    myColumnNo = 0 ;
   else
   {
    if ( myColumnNo >= myLineLength )
     result = insert( sb , '\n' ) ;
    ++ myColumnNo ;
   }
   if ( result != EOF )
    result = sb->sputc( ch ) ;
   return result ;
  }
  void                finalize( streambuf* sb )
  {
   if ( myColumnNo != 0 )
    sb->sputc( '\n' ) ;
  }
 private:
  int                 myLineLength ;
  int                 myColumnNo ;
 } ;

and it's use:

    FilteringOstream< LineWrappingInserter >
                        output( cout.rdbuf() ) ;
    while ( cin.peek() != EOF )
        output.put( (char)cin.get() ) ;

It took about a quarter of an hour to write and test -- is something
this simple and this specialized really appropriate for standardization?

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
        I'm looking for a job -- Je recherche du travail
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Dave Levitt <dlevitt.no.spam.please@ibm.net>
Date: 1997/11/04
Raw View
What would be some useful, general purpose utility classes [and
templates] that could be added without altering the language in the
current draft standard?

A couple of suggestions:

1) A class patterned after Java's File class, encapsulating platform
dependant filesystem naming  and access control conventions. Additional
[overloaded] constructors for things like streams that open operating
system files could also take references to instances of a C++ file
class.

and

2) A library function to clear the screen ;-)    [The number 1 newbie
question]
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1997/11/05
Raw View
Dave Levitt wrote:
>
> What would be some useful, general purpose utility classes [and
> templates] that could be added without altering the language in the
> current draft standard?

How about a streambuf, that could be inserted between a stream
and an existing streambuf, that does column counting, tab
expansion, line wrap, and stuff like that? It's always irritated
me that the output formatting features of ostreams (not to
mention printf) didn't handle such details.

And while we're at it, why not an output stream manipulator that
causes the insertion of commas into long numbers?

Also, I frequently use a stripped version of auto_ptr, which I
simply call ptr, that has no concept of ownership. I use it
merely to guarantee deletion of a heap object on leaving a
block, and never do any of the other things that auto_ptr's are
designed for, so I prefer its efficiency.

--

Ciao,
Paul
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/11/05
Raw View
Paul D. DeRocco wrote:

> And while we're at it, why not an output stream manipulator that
> causes the insertion of commas into long numbers?

IMO this would better be done with a locale.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]