[geos-devel] More Info - Another Portability Quirk
Norman Vine
nhv at cape.com
Sun Oct 6 23:34:21 EDT 2002
Paul Ramsey writes:
> I just went through my stl_*.h files, as well as the G++ STL online
> documentation, and it looks like at() is a recent addition to the G++
> STL -- sometime in the 3.x series (mine is from gcc 2.96 vintage). Are
> there other accessors which are possible, or is a latest-and-greatest
> STL going to be one of our requirements? Is there a way of having
> configure check the existance of various components of the STL?
Paul
You can use the [] operator, in fact I made all of the changes
locally todo this then realized that the at() method performs
an out of range check that the [] operator doesn't so didn't
forward my changes.
as you noticed according to http://gcc.gnu.org/libstdc++/status.html
gcc users will need to use a 3.x version inorder to use libstdc++3
My current thinking is that it is probably worth going with the
newer at() because of the builtin range checking
As a temporary measure I could update my patch so that it
was done with a bunch of
#if defined(__GNUC__) && (__GNUC__ < 3 )
use []
#else
use at()
#endif
but this is rather ugly :-(
Another solution would be to use a typedef
#if defined(__GNUC__) && (__GNUC__ < 3 )
typedef GEOS_VECTOR geos_vector
template < class _Tp >
class geos_vector < _Tp > : public vector < _Tp >
{
// add at() members
reference at(size_type __n)
{ return (*this)[__n]; }
const_reference at(size_type __n) const
{ return (*this)[__n]; }
}
#else
typedef GEOS_VECTOR vector
#endif
and change all occurrences of vector to GEOS_VECTOR
Cheers
Norman
More information about the geos-devel
mailing list