使用例子:
template<typename T>
inline void INSERT_ELEMENTS(T& coll, int first, int last)
{
for (int i = first; i <= last; ++i)
{
coll.insert(coll.end(), i);
}
}
template<typename T>
inline void PRINT_ELEMENTS(const T & coll, const string& optcstr = "")
{
cout << optcstr;
for (auto elem : coll)
{
cout << elem << ' ';
}
cout << endl;
}
int main()
{
vector<int>a;
INSERT_ELEMENTS(a, 1, 6);
PRINT_ELEMENTS(a);
partial_sum(a.cbegin(), a.cend(), ostream_iterator<int>(cout, " "));
cout << endl;
partial_sum(a.cbegin(), a.cend(), ostream_iterator<int>(cout, " "),multiplies<int>());
cout << endl;
}