Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: for(size_t a=begin();a!=end();++a){}

Reply
Thread Tools

Re: for(size_t a=begin();a!=end();++a){}

 
 
Chris \( Val \)
Guest
Posts: n/a
 
      07-13-2003

"John Harrison" <(E-Mail Removed)> wrote in message
news:bequq3$84kaj$(E-Mail Removed)-berlin.de...
|
| "Chris ( Val )" <(E-Mail Removed)> wrote in message
| news:bepeoe$7n5gs$(E-Mail Removed)-berlin.de...
| >
| > "Agent Mulder" <(E-Mail Removed)> wrote in message
| > news:beok7s$m4a$(E-Mail Removed)1.nb.home.nl...
| > | Hi group,
| > |
| > | I am in doubt about the type to
| > | use in a for-statement when applied
| > | to a vector. Logic tells me it should be
| > |
| > | vector<int>v;
| > | for(size_t a=v.begin();a!=v.end();++a);
| > |
| > | But even Stroustrup uses a plain int
| > | to traverse the vector (in paragraph
| > | 5.5 References). What style should I
| > | adopt?
| >
| > Use, 'size_type' ...
| >
| > std::vector<int>::size_type Idx( 0 );
| > for( Idx; Idx < v.size(); ++Idx )
| > // ...
| >
| > Cheers.
| > Chris Val
| >
|
| vector<T>::size_type is a typedef for the size_type of the allocator that
| the vector is using. In an STL compatable allocator size_type must be
| equivalent to size_t. I'm not sure exactly what 'equivalent' means but
| size_t sure saves a lot of typing.

Maybe, but even 'Stroustroup' has in the past acknowledged that
'size_type' is the preferred method. I have since tried to find this
response on google groups, but have had no luck.

Cheers.
Chris Val







 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-13-2003

"Chris ( Val )" <(E-Mail Removed)> wrote in message
news:ber468$85ctr$(E-Mail Removed)-berlin.de...
>
> "John Harrison" <(E-Mail Removed)> wrote in message
> news:bequq3$84kaj$(E-Mail Removed)-berlin.de...
> |
> | "Chris ( Val )" <(E-Mail Removed)> wrote in message
> | news:bepeoe$7n5gs$(E-Mail Removed)-berlin.de...
> | >
> | > "Agent Mulder" <(E-Mail Removed)> wrote in message
> | > news:beok7s$m4a$(E-Mail Removed)1.nb.home.nl...
> | > | Hi group,
> | > |
> | > | I am in doubt about the type to
> | > | use in a for-statement when applied
> | > | to a vector. Logic tells me it should be
> | > |
> | > | vector<int>v;
> | > | for(size_t a=v.begin();a!=v.end();++a);
> | > |
> | > | But even Stroustrup uses a plain int
> | > | to traverse the vector (in paragraph
> | > | 5.5 References). What style should I
> | > | adopt?
> | >
> | > Use, 'size_type' ...
> | >
> | > std::vector<int>::size_type Idx( 0 );
> | > for( Idx; Idx < v.size(); ++Idx )
> | > // ...
> | >
> | > Cheers.
> | > Chris Val
> | >
> |
> | vector<T>::size_type is a typedef for the size_type of the allocator

that
> | the vector is using. In an STL compatable allocator size_type must be
> | equivalent to size_t. I'm not sure exactly what 'equivalent' means but
> | size_t sure saves a lot of typing.
>
> Maybe, but even 'Stroustroup' has in the past acknowledged that
> 'size_type' is the preferred method. I have since tried to find this
> response on google groups, but have had no luck.
>
> Cheers.
> Chris Val
>


I'm getting my information from Josuttis, who says that the types must be
equivalent without specifying anywhere what that term means.

john


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-14-2003

"Andrey Tarasevich" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> John Harrison wrote:
> >> ...
> >> | vector<T>::size_type is a typedef for the size_type of the allocator

> > that
> >> | the vector is using. In an STL compatable allocator size_type must be
> >> | equivalent to size_t. I'm not sure exactly what 'equivalent' means

but
> >> | size_t sure saves a lot of typing.
> >>
> >> Maybe, but even 'Stroustroup' has in the past acknowledged that
> >> 'size_type' is the preferred method. I have since tried to find this
> >> response on google groups, but have had no luck.
> >> ...

> > I'm getting my information from Josuttis, who says that the types must

be
> > equivalent without specifying anywhere what that term means.
> > ...

>
> I don't remember seeing this in the standard. The equivalence between
> 'size_t' and 'std::allocator::size_type' is explicitly declared. But not
> the equivalence between 'std::allocator::size_type' and
> 'std::vector::size_type'.
>
> Strictly speaking, the original (non-TC1ed) version of the C++ standard,
> which didn't explicitly require 'std::vector's elements to be stored
> continuously, didn't really need this equivalence at all. Moreover, it
> would be flat-out strange to see it declared there.
>
> --
> Best regards,
> Andrey Tarasevich
> Brainbench C and C++ Programming MVP
>


Yes, you're right I think. I was confused.

john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments