Boost mozes naci na
www.boost.org.
Inace, evo listinga dopunjenog sa par primera koji ne koriste boost:
Code:
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <boost/bind.hpp>
#include <boost/mem_fn.hpp>
class klasa {
public:
klasa(int val) : Val_(val) {}
bool manje_od(int max) const { return Val_ < max; }
int value() const { return Val_; }
bool za_brisanje() { return Val_ < 4; }
bool operator<(const klasa &o) const { return Val_ < o.Val_; }
private:
int Val_;
};
void
napravi(std::vector<klasa> &v, int broj)
{
for (int i = 0; i < broj; ++i) {
v.push_back(i);
}
}
void
ispisi(const std::vector<klasa> &v)
{
for (std::vector<klasa>::const_iterator i = v.begin(); i != v.end(); ++i) {
std::cout << i->value() << " ";
}
std::cout << std::endl;
}
class kriterijum {
public:
kriterijum(int val) : Val_(val) {}
bool operator()(const klasa &o) { return o.value() < Val_; }
private:
int Val_;
};
int
main(int argc, char* argv[])
{
std::vector<klasa> v;
napravi(v, 10);
// Obrisi elemente manje od 3
std::vector<klasa>::iterator kraj = std::remove_if(v.begin(), v.end(),
boost::bind<bool>(boost::mem_fn(&klasa::manje_od), _1, 3));
v.erase(kraj, v.end());
ispisi(v);
kraj = std::remove_if(v.begin(), v.end(),
std::mem_fun_ref(&klasa::za_brisanje));
v.erase(kraj, v.end());
ispisi(v);
kraj = std::remove_if(v.begin(), v.end(), kriterijum(5));
v.erase(kraj, v.end());
ispisi(v);
kraj = std::remove_if(v.begin(), v.end(),
std::bind2nd(std::less<klasa>(), klasa(6)));
v.erase(kraj, v.end());
ispisi(v);
return 0;
}
Iskreno, pomocu funkcija standardne biblioteke ne umem da napisem primer ekvivalentan onom koji koristi boost sa VC++ 6.0.