Re: Accelerated C++: Exercise 3-2
On Apr 15, 7:55 am, "Andrew Koenig" <a...@acm.org> wrote:
"zeppe" <z...@nospam.remove.all.this.email.it> wrote in message
news:461eb659$2_1@x-privat.org...
The program seems well written! Just a note: it's useless to typedef the
std::vector<double>::size_type: use directly std::size_t.
Useless? Why? std::vector<double>::size_type is an unsigned type that h=
as
room to hold the number of elements in any vector<double>. It is not
difficult for me to imagine machine architectures in which thie type diff=
ers
from std::size_t, and I can see no obvious reason why std::size_t would be
preferable on such architectures.
The standard says that vector<>::size_type comes from the
allocator, and that in the default allocator, it must be a
size_t. IMHO, whether to use std::vector<double>::size_type or
simply size_t is largely a matter of style.
If you're using typedef's, the issue becomes a little less
subjective: if I've something like:
typedef std::vector< double > VectDbl ;
then VectDbl::size_type will automatically adjust if I change
the typedef to use a user defined allocator; size_t won't (and
could be wrong).
I think that using an object of std::vector<double>::size_type to represe=
nt
an index of a std::vector<double> object is an example of saying what you
mean.
A very verbose way:-). That's why I say it is a matter of
style. It is certainly more explicit; you're not just using
size_t, you're using a specific type because it is the size_type
of std::vector.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34