iterator

Discussion in 'C++' started by Gary Wessle, Feb 1, 2007.

  1. Gary Wessle

    Gary Wessle Guest

    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
    Gary Wessle, Feb 1, 2007
    #1
    1. Advertising

  2. Gary Wessle

    Guest

    On Jan 31, 7:01 pm, 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?
    >
    > 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, 2007
    #2
    1. Advertising

  3. Gary Wessle

    Guest

    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, 2007
    #3
  4. Gary Wessle

    red floyd Guest

    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.
    red floyd, Feb 1, 2007
    #4
  5. Gary Wessle

    Jerry Coffin Guest

    In article <>,
    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.
    Jerry Coffin, Feb 1, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,399
  2. greg
    Replies:
    6
    Views:
    444
    Dietmar Kuehl
    Jul 17, 2003
  3. Replies:
    6
    Views:
    628
    Jim Langston
    Oct 30, 2005
  4. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,132
    Steven D'Aprano
    Apr 20, 2007
  5. David Bilsby
    Replies:
    5
    Views:
    2,025
    David Bilsby
    Oct 9, 2007
Loading...

Share This Page