Using this to not store the permutations is not saving space.
Actually, it saves a quarter of a meg ;-)
Which is eight times as much memory as my first computer had!
Using this to not store the permutations is not saving space.
I seriously hope you're jocking.
Using this to not store the permutations is not saving space.
Rather, doing the permutation thing is brain damaged. And don't even get me started on checking the match. I'm sure I've seen it on the daily WTF.
Thus, not storing them is not about saving space but rather doing things right.
if(name == "person mcperson" || name == "Person Mcperson" || name == "Person McPerson"
|| name == "PERSON MCPERSON" || name == "person MCPERSON" || name == "PERSON mcperson" || ...etc... )
{
//...
}
std::string name = "Person McPerson";
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if(name == "person mcperson")
{
//...
}
Actually, it saves a quarter of a meg ;-)
Which is eight times as much memory as my first computer had!
if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")
[quote name='bls61793' timestamp='1342363560' post='4959267']
if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")
switch(name){
case "Tiffany":
case "tiffany":
case "Tiffany McClure":
...
break;
default:
...
}
Close enough?
Some languages allow this:
switch(name){
Close enough?
case "Tiffany":
case "tiffany":
case "Tiffany McClure":
...
break;
default:
...
}
[quote name='King Mir' timestamp='1342470870' post='4959728']
Some languages allow this:
switch(name){
Close enough?
case "Tiffany":
case "tiffany":
case "Tiffany McClure":
...
break;
default:
...
}
Which is why I said "some languages" and not "c++ and some languages"[/quote]Ah, I thought your "some languages" was a not-so-subtle "hint hint", referring to C++ itself (What with the topic being about C++, and the "Close enough?" comment).
[quote name='Servant of the Lord' timestamp='1342471896' post='4959736']
C++ switch statements only work with some data types (mostly ints) - not with std::strings. Even so, that's pretty ugly syntax.
Why do you think switches are ugly?[/quote]
Not switches, per se, but using switches (which are typically meant to branch logic) to imitate the use of AND logic (which is what && is for).
In some situations it may be the best solution, but in general I prefer to use if() when I mean logical IF, and && when I mean logical AND.