Topic: abstract class as first template argument to ostream_iterator
Author: Alberto Barbati <AlbertoBarbati@libero.it>
Date: Fri, 3 Sep 2004 00:46:53 GMT Raw View
Simon Richter wrote:
> g++ 3.4 accepts this code, Sun CC does not, telling me that Abstract is an
> abstract class (RogueWave STL obviously instantiates such an object obviously).
> The C++ standard does not specify whether the first template argument to
> std::ostream_iterator needs to be a concrete class.
Both Comeau 4.3.3 (online) and VC 7.1 also accepts the code.
> It is obvious that it is possible to provide an implementation that accepts an
> abstract class here. Should this be made a requirement, so that programmers can
> use ostream_iterators with abstract base classes, or is it better to leave that
> "implementation defined", effectively disallowing its use in portable code?
According to my interpretation of 24.5.2, there is nothing in the
standard that prevents you to portably use abstract classes. The
standard provides a reference implementation of ostream_iterator whose
only requirement on the type T is in 24.5.2.2: if "value" is a "const
T&" then the expression "*out_stream << value" shall be defined. Any
implementation that have stricter requirements on T is violating
17.3.1.2/6 and is thus non-conformant.
Alberto
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]