Skip to content

Instantly share code, notes, and snippets.

@termoose
Created April 10, 2015 10:02
Show Gist options
  • Save termoose/4eb507c9f4817d4d8b9f to your computer and use it in GitHub Desktop.
Save termoose/4eb507c9f4817d4d8b9f to your computer and use it in GitHub Desktop.
Variadic templates
void Add() { }
void Add(std::string data)
{
vector.push_back(data);
}
template<typename... Args>
void Add(std::string first, Args... args)
{
vector.push_back(first);
vector.push_back(args...);
}
@orbekk
Copy link

orbekk commented Apr 10, 2015

void Add2(std::initializer_list<string> items) {
  vector.insert(items.begin(), items.end());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment