Non-recursive method:
class CTest
{
public:
template<typename... Args>
void AddStringsToVector(const std::string &first, const Args&... args)
{
m_stringsvec.push_back(First);
int dummy[] = { 0, (m_stringsvec.push_back(args), 0)...};
(void) dummy;
for (const auto &s : m_stringsvec) {
std::cout << i << std::endl;
}
}
private:
std::vector<std::string> m_stringsvec;
};
The real material is:
int dummy[] = { 0, (m_stringsvec.push_back(args), 0)...};
(foo(), 0)the comma operator is used. This is the first part (the work we want) and evaluate how 0.
With a variational extension it becomes (m_stringsvec.push_back(args), 0)....
.
++ 17 :
template<typename... Args>
void AddStringsToVector(const std::string &first, const Args&... args)
{
m_stringsvec.push_back(First);
(m_stringsvec.push_back(args), ...);
for (const auto &s : m_stringsvec) {
std::cout << i << std::endl;
}
}