Skip to content

Instantly share code, notes, and snippets.

@tekknolagi
Forked from kenpusney/gensym.cpp
Created June 20, 2024 19:49
Show Gist options
  • Save tekknolagi/7b86202d43601c16450c773406a060bf to your computer and use it in GitHub Desktop.
Save tekknolagi/7b86202d43601c16450c773406a060bf to your computer and use it in GitHub Desktop.
A gensym implementation of C/C++ Preprocessor.
#define STRINGIFY(x) #x
#define EXTRACT(...) __VA_ARGS__
#define INVOKE(macro,args...) macro( EXTRACT(args) )
#define FIRST(x,...) x
#define REST(x,...) __VA_ARGS__
#define __sym(cn,ln) _ainini_##c##cn##l##ln
#define sym(cn,ln) __sym(cn,ln)
#define __gensym(cn, ln) sym( cn,ln )
//@TODO: IMPLEMENT A `__COUNTER__` TO FIT C/CPP STANDARDS
#define gensym() __gensym(__COUNTER__, __LINE__)
struct fck{
explicit fck(int a = 0){}
};
TestCase(GENSYM){
int gensym() = 1;fck gensym()(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment