Created
August 4, 2014 21:30
-
-
Save rsms/a5fa779736ea4932be91 to your computer and use it in GitHub Desktop.
constexpr basename
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 const char* _cx_basename(const char* dp, const char* p) { | |
return *p == '\0' ? dp : *p == '/' ? basename(p+1, p+1) : basename(dp, p+1); | |
} | |
constexpr const char* cx_basename(const char* s) { return _cx_basename(s,s); } | |
cx_basename(__FILE__) // == "bar.cc" when __FILE__ == "/foo/bar.cc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment