Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > iterator

Reply
Thread Tools

iterator

 
 
Gary Wessle
Guest
Posts: n/a
 
      02-01-2007
dear all
I am not doing this right.

time_t Grid::n_report(const vector<time_t>& times, const time_t& now_time){
for( vector<time_t>::iterator i = times.begin(); i != times.end(); i++ ){
if( *i >= now_time ) return *i;

the iterator for the first arg is not right, how do I make it const
iter to a ref vector?

thanks
 
Reply With Quote
 
 
 
 
gamediaceo@gmail.com
Guest
Posts: n/a
 
      02-01-2007
On Jan 31, 7:01 pm, Gary Wessle <(E-Mail Removed)> wrote:
> dear all
> I am not doing this right.
>
> time_t Grid::n_report(const vector<time_t>& times, const time_t& now_time){
> for( vector<time_t>::iterator i = times.begin(); i != times.end(); i++ ){
> if( *i >= now_time ) return *i;
>
> the iterator for the first arg is not right, how do I make it const
> iter to a ref vector?
>
> thanks


What do you mean, the iterator is not right? What are you expecting it
to be? Do you have some sample input/output? Posting that would help
tremendously!

Cheers,
Henry

--------
http://hamath.blogspot.com - Science, technology, and interesting
stuff Blog

 
Reply With Quote
 
 
 
 
gamediaceo@gmail.com
Guest
Posts: n/a
 
      02-01-2007
Well, after creating my own test-program using essentially your code,
it would not compile with the "const" keyword in front of the
vector<time_t>& times parameter -- apparently, the iterator cannot be
created from a const vector, so leave out the const keyword in the
parameter and you should be fine.

Cheers,
Henry

--------
http://hamath.blogspot.com - Science, technology, and interesting
stuff Blog

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      02-01-2007
Gary Wessle wrote:
> dear all
> I am not doing this right.
>
> time_t Grid::n_report(const vector<time_t>& times, const time_t& now_time){
> for( vector<time_t>::iterator i = times.begin(); i != times.end(); i++ ){
> if( *i >= now_time ) return *i;
>
> the iterator for the first arg is not right, how do I make it const
> iter to a ref vector?
>


make it a vector<time_t>::const_iterator.



 
Reply With Quote
 
Jerry Coffin
Guest
Posts: n/a
 
      02-01-2007
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
says...
> dear all
> I am not doing this right.
>
> time_t Grid::n_report(const vector<time_t>& times, const time_t& now_time){
> for( vector<time_t>::iterator i = times.begin(); i != times.end(); i++ ){
> if( *i >= now_time ) return *i;
>
> the iterator for the first arg is not right, how do I make it const
> iter to a ref vector?


It sounds like you want an iterator to a constant item, which would be a
const_iterator. OTOH, it appears find_if would do the job:

std::find_if(times.begin(), times.end(),
std::bind2nd(std::greater<time_t>(), now_time));

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
List iterator assignment fails, assert iterator not dereferencable David Bilsby C++ 5 10-09-2007 02:05 PM
What makes an iterator an iterator? Steven D'Aprano Python 28 04-20-2007 03:34 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
Iterator doubts, Decision on Iterator usage greg C++ 6 07-17-2003 01:26 PM



Advertisments