Skip to content

Instantly share code, notes, and snippets.

@m-ou-se
Last active December 20, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-ou-se/6087660 to your computer and use it in GitHub Desktop.
Save m-ou-se/6087660 to your computer and use it in GitHub Desktop.
Parameter Pack Crazyness
query("hello");
// executes q("hello");
query("delete where x =", x);
// executes q("delete where x = % ", x);
query("delete where x =", x, "and a = 5");
// executes q("delete where x = % and a = 5", x);
query("delete where x =", x, "and a =", y);
// executes q("delete where x = % and a = % ", x, y);
// Possible implementation to allow query(string, T, string, U, string, V, ... etc.) for any T,U,V,...
template<typename... T>
void query((std::string, T)... x, std::string y = {}) {
std::string s = join_with(" % ", first_value(x...)..., y);
q(s, second_value(x...)...);
}
// Update:
// Using option 3:
template<typename... T>
void query(<std::string, T>... ... x, std::string y = {}) {
std::string s = join_with(" % ", first_value(x...)..., y);
q(s, second_value(x...)...);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment