#include <iostream>
#include <vector>
using namespace std;
template<typename T>
struct Params : public std::vector<T>
{
template<typename V> // avoids fallback to language-defined behavior
inline Params<T>& operator,(const V& value)
{
this->push_back(value);
return *this;
}
};
void printParams(const Params<int>& params = Params<int>())
{
cout << "[";
for (size_t i = 0; i < params.size(); ++i)
{
cout << (i == 0 ? "" : ", ");
cout << params[i];
}
cout << "]" << endl;
}
int main()
{
// No params
printParams(); // []
// No params with explicit empty params
printParams(Params<int>()); // []
// Some params
printParams((Params<int>(), 1, 2, 3)); // [1, 2, 3]
// compile-time error: invalid conversion from `const char[4]` to `int`
// printParams((Params<int>(), 1, 2, 3, "error"));
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICNpbmNsdWRlIDx2ZWN0b3I+CiAgICB1c2luZyBuYW1lc3BhY2Ugc3RkOwogICAgIAogICAgdGVtcGxhdGU8dHlwZW5hbWUgVD4KICAgIHN0cnVjdCBQYXJhbXMgOiBwdWJsaWMgc3RkOjp2ZWN0b3I8VD4KICAgIHsKICAgICAgICB0ZW1wbGF0ZTx0eXBlbmFtZSBWPiAvLyBhdm9pZHMgZmFsbGJhY2sgdG8gbGFuZ3VhZ2UtZGVmaW5lZCBiZWhhdmlvcgogICAgICAgIGlubGluZSBQYXJhbXM8VD4mIG9wZXJhdG9yLChjb25zdCBWJiB2YWx1ZSkKICAgICAgICB7CiAgICAgICAgICAgIHRoaXMtPnB1c2hfYmFjayh2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiAqdGhpczsKICAgICAgICB9CiAgICB9OwogICAgIAogICAgdm9pZCBwcmludFBhcmFtcyhjb25zdCBQYXJhbXM8aW50PiYgcGFyYW1zID0gUGFyYW1zPGludD4oKSkKICAgIHsKICAgICAgICBjb3V0IDw8ICJbIjsKICAgICAKICAgICAgICBmb3IgKHNpemVfdCBpID0gMDsgaSA8IHBhcmFtcy5zaXplKCk7ICsraSkKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQgPDwgKGkgPT0gMCA/ICIiIDogIiwgIik7CiAgICAgICAgICAgIGNvdXQgPDwgcGFyYW1zW2ldOwogICAgICAgIH0KICAgICAKICAgICAgICBjb3V0IDw8ICJdIiA8PCBlbmRsOwogICAgfQogICAgIAogICAgaW50IG1haW4oKQogICAgewogICAgICAgIC8vIE5vIHBhcmFtcwogICAgICAgIHByaW50UGFyYW1zKCk7IC8vIFtdCiAgICAgCiAgICAgICAgLy8gTm8gcGFyYW1zIHdpdGggZXhwbGljaXQgZW1wdHkgcGFyYW1zCiAgICAgICAgcHJpbnRQYXJhbXMoUGFyYW1zPGludD4oKSk7IC8vIFtdCiAgICAgCiAgICAgICAgLy8gU29tZSBwYXJhbXMKICAgICAgICBwcmludFBhcmFtcygoUGFyYW1zPGludD4oKSwgMSwgMiwgMykpOyAvLyBbMSwgMiwgM10KICAgICAKICAgICAgICAvLyBjb21waWxlLXRpbWUgZXJyb3I6IGludmFsaWQgY29udmVyc2lvbiBmcm9tIGBjb25zdCBjaGFyWzRdYCB0byBgaW50YAogICAgICAgIC8vIHByaW50UGFyYW1zKChQYXJhbXM8aW50PigpLCAxLCAyLCAzLCAiZXJyb3IiKSk7CiAgICB9