Function pointer example STL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include <algorithm>
#include <iostream>
#include <list>


    bool compare(int n) 
    {
        return ((n % 3) == 0);
    }


int main()
{
    const int a[] = { 5, 2, 6, 1, 13, 9, 19 };
    const int count = sizeof(a) / sizeof(a[0]);
    std::list<int> l(a, a+ count);
    std::cout << l.size();
    std::remove_if(l.begin(), l.end(), compare);
    std::cout << l.size() << std::endl;

    return 0;
}

77


Could you help me why these doesn't work?
If "comapre" would work properly the code would return "75", but it returns "77" as if compare is always true/not accepted by "remove_if"!
No elements are removed from the container. See here:
http://www.cplusplus.com/reference/algorithm/remove_if/
Topic archived. No new replies allowed.