Skip to content

Instantly share code, notes, and snippets.

@mtao
Last active March 19, 2018 14:47
Show Gist options
  • Save mtao/9e7202389e030d86434cb90311711427 to your computer and use it in GitHub Desktop.
Save mtao/9e7202389e030d86434cb90311711427 to your computer and use it in GitHub Desktop.
Implementation of the code pointed out in http://belkadan.com/blog/2018/03/My-Little-Optimization/. I wasn't aware that template <int... N>(&...name)[N] worked
#include <iostream>
#include <string_view>
template <size_t... N>
bool isInSet(const std::string_view s, const char (&...S)[N]) {
return (operator==(s,S) || ...);
}
int main(int argc, char * argv[]) {
if(argc < 1) {
return 1;
}
std::string str = argv[1];
bool str_in = isInSet(str,"Battler", "George", "Jessica", "Maria", "Beatrice");
std::cout << "is " << str
<< " in set? " << (str_in?"Yes":"No")
<< std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment