#include <list>
#include <iostream>
#include <sstream>
class summator{
    std::list<int> vars;
public:
    summator& operator << (int o)
    {
        vars.push_back(o);
        return *this;
    }
    summator& operator << (const char *o)
    {
        vars.push_back(atoi(o));
        return *this;
    }
    summator& calc_internal()
    {
        int sum = 0;
        while(!vars.empty()){
            sum += vars.front();
            vars.pop_front();
        }
        std::cout << "sum = " << sum;
        return *this;
    }
    
    summator& operator << ( summator & (f)( summator & ) ) {
        return f( *this );
    }    
};

summator & calc( summator & o )
{
	return o.calc_internal();
}


int main(int argc, char* argv[])
{
    summator sum;
    sum << 1 << 2 << "3" << calc;
    return 0;
}
