Пример 15.6. Вспомогательные классы для инициализации стандартных последовательностей с применением синтаксиса с запятыми
#include <vector>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
template<class Seq_T>
struct comma helper {
typedef typename Seq_T::value_type value_type;
explicit comma_helper(Seq_T& x) : m(x) {}
comma_helper& operator=(const value_type& x) {
m.clear();
return operator+=(x);
}
comma_helper& operator+=(const value_type& x) {
m.push_back(x);
return *this;
}
Seq_T& m;
};
template<typename Seq_T>
comma_helper<Seq_T> initialize(Seq_T& x) {
return comma_helper<Seq_T>(x);
}
template<class Seq_T, class Scalar_T>
comma_helper<Seq_T>& operator,(comma_helper<Seq_T>& h, Scalar_T x) {
h += x;
return h;
}
int main() {