Last active
August 22, 2018 11:54
-
-
Save topin89/b013b1ea511372ded164a0366550fc07 to your computer and use it in GitHub Desktop.
C++ static counter (non standart, works for gcc, vc++, clang, icc)
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
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 | |
#include <iostream> | |
void multiprint(){ | |
static constexpr size_t base = __COUNTER__; | |
#define i (__COUNTER__ - base - 1) | |
std::cout << i << std::endl; | |
std::cout << i << std::endl; | |
std::cout << i << " " << i <<std::endl; | |
std::cout << i << " " << i << " " << i << " " << i << " " << i << " " <<std::endl; | |
#undef i | |
} | |
void multiprint2(){ | |
static constexpr size_t base = __COUNTER__; | |
#define i (__COUNTER__ - base - 1) | |
std::cout << i << std::endl; | |
std::cout << i << " " << i << " " << i << " " << i << " " << i << " " <<std::endl; | |
std::cout << i << std::endl; | |
std::cout << i << " " << i <<std::endl; | |
#undef i | |
} | |
int main() | |
{ | |
multiprint(); | |
multiprint2(); | |
std::cout << "Hello, world!\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment