Advertisement
Tkap1

Untitled

Jul 26th, 2023
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #define foreach__(a, index_name, element_name, array) if(0) finished##a: ; else for(auto element_name = &(array).elements[0];;) if(1) goto body##a; else while(1) if(1) goto finished##a; else body##a: for(int index_name = 0; index_name < (array).count && (bool)(element_name = &(array)[index_name]); index_name++)
  2. #define foreach_(a, index_name, element_name, array) foreach__(a, index_name, element_name, array)
  3. #define foreach(index_name, element_name, array) foreach_(__LINE__, index_name, element_name, array)
  4.  
  5. #define foreach_raw__(a, index_name, element_name, array) if(0) finished##a: ; else for(auto element_name = (array).elements[0];;) if(1) goto body##a; else while(1) if(1) goto finished##a; else body##a: for(int index_name = 0; index_name < (array).count && (void*)&(element_name = (array)[index_name]); index_name++)
  6. #define foreach_raw_(a, index_name, element_name, array) foreach_raw__(a, index_name, element_name, array)
  7. #define foreach_raw(index_name, element_name, array) foreach_raw_(__LINE__, index_name, element_name, array)
  8.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement