473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

iterator

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
Feb 1 '07 #1
4 1741
On Jan 31, 7:01 pm, Gary Wessle <phd...@yahoo.comwrote:
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

Feb 1 '07 #2
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

Feb 1 '07 #3
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.

Feb 1 '07 #4
In article <m3************@localhost.localdomain>, ph****@yahoo.com
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.
Feb 1 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
0
by: nick | last post by:
Hi, I need to manage a "layered" collection of objects, where each layer grows independently, e.g, o--+--+--+--+--+ 1st layer | o 2nd layer (empty) | o--+--+--+ 3rd...
14
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
16
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
27
by: Steven D'Aprano | last post by:
I thought that an iterator was any object that follows the iterator protocol, that is, it has a next() method and an __iter__() method. But I'm having problems writing a class that acts as an...
4
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
2
by: Terry Reedy | last post by:
Luis Zarrabeitia wrote: Interesting observation. Iterators are intended for 'iterate through once and discard' usages. To zip a long sequence with several short sequences, either use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.