Boost logo

Boost Users :

From: Josue Gomes (josue.gomes.honeypot_at_[hidden])
Date: 2005-12-13 09:33:53


Hi,

Can transform_iterator be used in conjunction with remove_if algorithm?
The compiler (vc7.1, vc8, g++) is refusing to compile this:

#include <string>
#include <utility>
#include <vector>
#include <functional>
#include <cassert>
#include <iostream>
#include <boost/iterator/transform_iterator.hpp>

std::vector<std::pair<std::string, int> > c;

struct to_num {
        typedef int result_type;

        int operator()(const std::pair<std::string, int>& p) const
        {
                return p.second;
        }
};

int main()
{
        using std::make_pair;

        c.push_back(make_pair("A", 2));
        c.push_back(make_pair("A", 3));
        c.push_back(make_pair("A", 4));

        c.push_back(make_pair("A", 15));
        c.push_back(make_pair("A", 16));
        c.push_back(make_pair("A", 17));
        assert(c.size() == 6);

        std::remove_if(
                boost::make_transform_iterator(c.begin(), to_num()),
                boost::make_transform_iterator(c.end(), to_num()),
                std::bind1st(std::less_equal<int>(), 10));

        assert(c.size() == 6);
}

Regards,
Josue


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net