iterator

G

Gary Wessle

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
 
G

gamediaceo

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
 
G

gamediaceo

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
 
R

red floyd

Gary said:
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.
 
J

Jerry Coffin

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));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top