Last active
March 19, 2018 14:47
-
-
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
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
#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