Как создать шаблон

Как создать шаблон принимающий переменное количество параметров, плюс к этому у параметров тоже переменное количество параметров.

struct S {
    int x;
    std::string s;
    S(int x, std::string s): x(x),s(s) {}
}

int main(){
list<S> l;

l.push_many(( 1,"a" ), ( 2, "b" ), ( 3, "c" ));

}


Ответы (1 шт):

Автор решения: user7860670

Тут пригодится библиотека boost.assign

#include <boost/assign/list_inserter.hpp>

#include <list>
#include <string>

struct
Item
{
    int m_x;
    ::std::string m_s;
    Item(int x, ::std::string s): m_x{x}, m_s{s} {}
};

int
main()
{
    ::std::list<Item> items{};
    ::boost::assign::push_back(items)(1, "a")(2, "b")(3, "c");
    return 0;
}

online compiler

→ Ссылка