Last active
December 20, 2015 06:39
-
-
Save m-ou-se/6087660 to your computer and use it in GitHub Desktop.
Parameter Pack Crazyness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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