accumulate() usage

Discussion in 'C++' started by Allerdyce.John@gmail.com, Feb 2, 2006.

  1. Guest

    Hi,

    I have a function with add elements of a STL list from 'start' to
    'end'.
    In the debugger, the size of the list is 2 and start is 0 and end is 1.
    But it never goes itside 'do_add' and it just return 0. I expect it
    just 'sum' the FIRST element (since start is 0 and end is 1).

    Can you please tell me why is that?

    _myList is a type of vector<int>
    float getTotal(int start,int end) {
    vector<int>::iterator beginItr = _myList.begin() + start;
    vector<int>::iterator endItr = _myList.begin() + end;


    return accumulate (beginItr, endItr, 0.0, do_add<int, float>());

    }
    , Feb 2, 2006
    #1
    1. Advertising

  2. wrote:

    > But it never goes itside 'do_add' and it just return 0. I expect it
    > just 'sum' the FIRST element (since start is 0 and end is 1).
    >
    > Can you please tell me why is that?
    >
    > _myList is a type of vector<int>
    > float getTotal(int start,int end) {
    > vector<int>::iterator beginItr = _myList.begin() + start;
    > vector<int>::iterator endItr = _myList.begin() + end;
    > return accumulate (beginItr, endItr, 0.0, do_add<int, float>());


    This code works fine when I tried it (After adding necessary minimal
    definitions and other stuff). Could you please give the complete code
    which demonstrates the problem?
    Neelesh Bodas, Feb 2, 2006
    #2
    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. Brian K. Michalk

    64 bit add and accumulate with MMX

    Brian K. Michalk, Sep 20, 2003, in forum: Perl
    Replies:
    6
    Views:
    637
    Terje Mathisen
    Sep 20, 2003
  2. Roedy Green

    Accumulate 1.0

    Roedy Green, Jul 17, 2004, in forum: Java
    Replies:
    0
    Views:
    369
    Roedy Green
    Jul 17, 2004
  3. cesco
    Replies:
    5
    Views:
    445
    Maxim Yegorushkin
    Feb 13, 2006
  4. Replies:
    1
    Views:
    1,706
  5. Henrique A. Menarin

    Boost algorithm ll::accumulate question

    Henrique A. Menarin, Jan 28, 2007, in forum: C++
    Replies:
    7
    Views:
    957
    Roland Pibinger
    Jan 29, 2007
Loading...

Share This Page