[Libpqxx-general] distance() return type
Jorgen Austvik - Sun Norway
Jorgen.Austvik at Sun.COM
Tue Jul 15 12:00:10 UTC 2008
Hi,
in include/pqxx/compiler-internal.hxx, the distance function is defined
like this:
----8<-----------8<-----------8<-----------8<-----------8<-----------8<-------
/// Wrapper for std::distance; not all platforms have std::distance().
template<typename T> inline ptrdiff_t distance(T first, T last)
{
#ifdef PQXX_HAVE_DISTANCE
return PGSTD::distance(first, last);
#else
// Naive implementation. All we really need for now.
iterator_traits<T>::difference_type d = 0;
while (first != last) ++d;
return d;
#endif
}
----8<-----------8<-----------8<-----------8<-----------8<-----------8<-------
I am curious why the return type of the function is ptrdiff_t while it
looks like std::distance returns iterator_traits<T>::difference_type[1],
and the d variable certainly has that type - should they all be
iterator_traits<T>::difference_type?
On the Sun Studio compiler, with it's Rough Wave STL implementation,
iterator_traits does not exist (and std::distance is also non-standard).
There I just change iterator_traits<T>::difference_type d = 0 to
ptrdiff_t d = 0, which seems to do the job there.
[1] http://www.sgi.com/tech/stl/distance.html
[2] http://wikis.sun.com/pages/viewpage.action?pageId=6455548
-J
--
Jørgen Austvik, Software Engineering - QA
Sun Microsystems Database Group
http://blogs.sun.com/austvik/
http://www.austvik.net/
More information about the Libpqxx-general
mailing list