Skip to content

Instantly share code, notes, and snippets.

@DavidLudwig
Created February 25, 2020 17:12
Show Gist options
  • Save DavidLudwig/28643091f8dbd8499c315fa2e46f00b5 to your computer and use it in GitHub Desktop.
Save DavidLudwig/28643091f8dbd8499c315fa2e46f00b5 to your computer and use it in GitHub Desktop.
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