Boost logo

Boost :

From: Thomas Klimpel (klimpel_at_[hidden])
Date: 2005-07-19 18:19:32


Ronald Garcia wrote:
> I made the changes you show below

thanks

> with the exception of the switch to ptrdiff_t for the index type.
> It's not obvious to me that that is the correct change to make

I have to admit that the name "std::ptrdiff_t" sounds strange in the
context of "index", but there are some container classes in boost that
use std::ptrdiff_t as the argument type for operator[],
"boost::scoped_array" and "boost::shared_array" for example. And I think
"std::ptrdiff_t" makes perfect sense as the index type for an operator[]
that accepts both negative and positive integers.

There might be types with more comforting names like

typedef boost::intmax_t index; // from "boost/cstdint.hpp"
typedef boost::detail::integer_traits<std::size_t>::difference_type
index; // from "boost/detail/numeric_traits.hpp"
typedef intmax_t index;
typedef intptr_t index;

but "intmax_t" and "intptr_t" seem to be more part of the "c standard"
than of the "c++ standard", and the boost types don't help me with the
annoying warnings on 32-bit windows with Visual C++.NET. On 32-bit
windows, size_t is defined as "typedef _W64 unsigned int size_t;"
where the _W64 just means that I will get warning messages, if I convert
this type to a type without _W64. Now ptrdiff_t works for me, because it
is defined as "typedef _W64 int ptrdiff_t;".

Besides the warnings issue, "boost::detail::multi_array::index" should
be a signed integer type, that satisfies the assertion
"assert(sizeof(boost::detail::multi_array::index) ==
sizeof(std::size_t));". While this assertion will probably be satisfied
on all current platforms, it is not garantied by the standard, which
just reads: "The types are 'ptrdiff_t' which is the signed integer type
of the result of substracting two pointers; 'size_t' which is the
unsigned integer type of the result of the sizeof operator;".

Thanks,

Thomas


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk