Created
February 20, 2016 20:14
-
-
Save tfc/4678e733cdfecffaf11a to your computer and use it in GitHub Desktop.
__SHORT_FILE__ Macro
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
#include <stdio.h> | |
using cstr = const char * const; | |
static cstr constexpr past_last_slash(cstr str, cstr last_slash) | |
{ | |
return | |
*str == '\0' ? last_slash : | |
*str == '/' ? past_last_slash(str + 1, str + 1) | |
: past_last_slash(str + 1, last_slash); | |
} | |
static cstr constexpr past_last_slash(cstr str) { return past_last_slash(str, str); } | |
#define __SHORT_FILE__ ({constexpr cstr sf__ {past_last_slash(__FILE__)}; sf__;}) | |
int main() | |
{ | |
puts(__SHORT_FILE__); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ah. right. that's c++14 only. and yes, more a matter of style