All pastes #186941 Raw Edit

Someone

public cpp v1 · immutable
#186941 ·published 2006-09-30 17:18 UTC
rendered paste body
#include <iostream>#include <vector>#include <numeric>#include <tr1/functional>class X {public:    X(int i):m_i(i) { }    static int plus(int i, X *x) {        return i + x->m_i;    }    int get_i() const { return m_i; }private:    int m_i;};struct call_delete {    template <typename T>    void operator()(T *t) {        delete t;        t = 0;    }};int operator+(int n, const X &x) { return n + x.get_i(); }int main(){    std::vector<X*> x;    x.push_back(new X(3));    x.push_back(new X(5));    std::cout << std::accumulate(x.begin(), x.end(), 2, X::plus) << std::endl;    std::cout << std::accumulate(x.begin(), x.end(), 3,        std::tr1::bind(std::plus<int>(), std::tr1::placeholders::_1,            std::tr1::bind(&X::get_i, std::tr1::placeholders::_2))) << std::endl;    std::for_each(x.begin(), x.end(), call_delete());    std::vector<X> y;    y.push_back(1);    y.push_back(2);    std::cout << std::accumulate(y.begin(), y.end(), 0) << std::endl;}