Created
February 25, 2020 17:12
-
-
Save DavidLudwig/28643091f8dbd8499c315fa2e46f00b5 to your computer and use it in GitHub Desktop.
This file contains 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
constexpr bool constexpr_strequal(const char * a, const char * b) | |
{ | |
// Assume that NULL != NULL | |
if (!a || !b) { | |
return false; | |
} | |
// If pointers are equal, values are equal | |
if (a == b) { | |
return true; | |
} | |
// Scan through individual characters | |
const char * pa = a; | |
const char * pb = b; | |
while (true) { | |
if (*pa != *pb) { | |
// A discrepency was detected | |
return false; | |
} | |
if (!(*pa)) { | |
// Strings have been terminated | |
break; | |
} | |
// Advance character-pointers | |
++pa; | |
++pb; | |
} | |
// If we get here, the strings' contents should be equal | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment