0

Is it possible to implement a compile time counter? I want something like this (The initial value should be 0):

int main () {
  constexpr int a = next ();
  constexpr int b = next ();
  constexpr int c = next ();

  static_assert (a == 0 && b == a+1 && c == b+1, "");
}
  • 1
    I am not aware of anything like that in the C++ standard. gcc, though, does offer a [`__COUNTER__`](https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html#Common-Predefined-Macros) preprocessor macro. – Sam Varshavchik Jun 01 '16 at 12:37
  • 1
    http://b.atch.se/posts/constexpr-counter/ but I am not sure I would use it in any non-toy project – Slava Jun 01 '16 at 12:38

0 Answers0