On 29 mar, 13:45, Leigh Johnston <(EMail Removed)> wrote:
> On 29/03/2011 08:33, Michael Doubez wrote:
>
>
>
>
>
>
>
>
>
> > On 29 mar, 01:04, Leigh Johnston<(EMail Removed)> *wrote:
> >> On 28/03/2011 23:20, James Kanze wrote:
>
> >>> On Mar 26, 4:55 pm, "MikeP"<(EMail Removed)> * *wrote:
> >>>> James Kanze wrote:
> >>>>> On Mar 23, 9:51 am, Michael Doubez<(EMail Removed)> * *wrote:
> >>>>>> On 22 mar, 18:04, Leigh Johnston<(EMail Removed)> * *wrote:
>
> >>>>> * * *[...]
> >>>>>> Using unsigned to indicate the parameter must be positive
>
> >>>>> Is not a valid argument for anything, unless the valid range is
> >>>>> exactlyl [0...UINT_MAX]. *C++ doesn't have ranged integral
> >>>>> types, so you have to make do. *Any type which will hold the
> >>>>> desired range is equally good from that point of view, and the
> >>>>> type of an argument can never be assumed to tell you anything
> >>>>> about the range.
>
> >>>>> Suppose I want to represent the value of a six sided die which
> >>>>> has been thrown. *The legal range is 1...6. *Which type,
> >>>>> unsigned or int, tells me more about this? *The answer, of
> >>>>> course, is neither.
>
> >>>> Focusing on an exact range is a strawman, for it is not relevant to the
> >>>> discussion of the relative semantic value of using signed or unsigned.
>
> >>> Which is exactly what I said. *Arguments concerning the range
> >>> are vacuous, since C++ doesn't support ranged variables.
>
> >>>> Any suggestion that unsigned does not give more meaning than
> >>>> signed (when signed is used to represent variables that cannot
> >>>> be negative) is, of course, incorrect.
>
> >>> But it doesn't give any additional useful information, in most
> >>> cases.
>
> >>>> Using signed for the die value gives rise to questions
> >>>> about what kind of concoction the programmer developed where a die value
> >>>> CAN be negative.
>
> >>> No. *In the places I've worked, using unsigned for the die value
> >>> gives rise to questions as to why the programmer wanted modulo
> >>> arithmetic, or what sort of bitwise operations he had in mind.
>
> >>> It's a question of expectations, not a language issue, nor a
> >>> techical issue. *The expectations of most programmers I've met
> >>> (and practically all I've worked with) are that unsigned means
> >>> bitwise or modulo. *I've also pointed out where those
> >>> expectations come from.
>
> >> Again you are uttering nonsense (or bullshit: you choose); unsigned
> >> types are not just for "bitwise or modulo": std::size_t is an unsigned
> >> type and is used to represent sizes and indices; char can be an unsigned
> >> type and char is used for representing string characters.
>
> > IMO, the fact that a size type is used for indices is part of the
> > problem. Shouldn't it be an index type ?
> > An index is likely to be computed and eventually become negative at
> > some point (when computing a difference); so it should be a signed
> > type
>
> No; size_type is used for indices and difference_type is used for ..
> wait for it.. differences.
Between iterator. Which is much help at this point.
Does the standard guarantee that difference_type works in all case
with size_t ?
> > But we want to compare an index to a size, that led to having index
> > type the same as size type.
>
> > I would have prefered the other way around: the size type same as
> > index type  i.e signed.
>
> Your personal preferences are not really relevant; what is relevant are
> the idioms that have been standardized by the C++ Standard.
Like vector<bool>, valarray<> and auto_ptr<> ?

Michael
