#include template class FormattedBackInserter: public std::iterator { public: explicit FormattedBackInserter(std::string& target): first_(true), target_(target) { } FormattedBackInserter& operator=(const ValueType& value) { if (!first_) target_.push_back(' '); else first_ = false; insert(value); return *this; } /// Simply returns *this. FormattedBackInserter& operator*() { return *this; } /// Simply returns *this. (This %iterator does not "move".) FormattedBackInserter& operator++() { return *this; } /// Simply returns *this. (This %iterator does not "move".) FormattedBackInserter operator++(int) { return *this; } private: void insert(const ValueType& value) { if (value > 9) insert(value/10); target_.push_back('0' + value % 10); } bool first_; std::string& target_; };