std::vector<std::string> strSeq;This can be better written using the standard template library:
const int MAX_STRSEQ_SIZE = 31;
for (int i = 0; i < MAX_STRSEQ_SIZE; ++i)
strSeq.push_back("0123456789");
std::vector<std::string> strSeq;Although this isn't really any shorter than the original for loop, I believe it reads better.
const int MAX_STRSEQ_SIZE = 31;
std::fill_n(std::back_inserter(strSeq), MAX_STRSEQ_SIZE,
"0123456789");
Lets review std::fill_n():
template<typename ForwardIter, typename Size, typename T>std::fill_n takes three arguments: ForwardIter, Size, and T. ForwardIter is designed to take an iterator pointing to where to begin filling. However, since std::fill_n assumes there is room in the container we use std::back_inserter() to adapt the assignment operator into a push_back on our container. Size is how many of T to assign and T is the value to assign.
fill_n(ForwardIter begin, Size n, const T& value);
No comments:
Post a Comment