Skip to content

Instantly share code, notes, and snippets.

@rsms
Created August 4, 2014 21:30
Show Gist options
  • Save rsms/a5fa779736ea4932be91 to your computer and use it in GitHub Desktop.
Save rsms/a5fa779736ea4932be91 to your computer and use it in GitHub Desktop.
constexpr basename
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