ideas
ideas copied to clipboard
Стандартизировать макрос __COUNTER__
Стандартизировать макрос __COUNTER__
Что бы не городить такое https://github.com/madmurphy/zen.h/blob/master/zen.h
Полезные ссылки: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros
В репозитории, на который вы дали ссылку, написано:
There are two main reasons for implementing a novel counter for the C preprocessor other than the built-in (and non-standard) COUNTER. The first reason is that COUNTER is not flexible: when two or more headers use it, the values that this yields are not predictable. The second and most important reason is that COUNTER is not reusable and gets increased every time it is invoked, making the storage of its yielded values within the preprocessor environment virtually impossible.
Это уже несколько причин его не стандартизировать.
Ничто не мешает сделать нечто что будет увеличиваться при его чтении, но на уровне компиляции. Типа std::source_location::counter()
__COUNTER__
у многих компиляторов есть из коробки. Но в стандарте ничего подобного нет.