ARTICLE AD BOX
I would like to create a function that can count the number of times it is called at compile time. I was trying something like this, but it only works at runtime:
#include <iostream> static constinit size_t size = 0; constexpr size_t increment_value() { return ++size; } int main() { std::cout << "test: " << size << std::endl; // 0 should be 3 increment_value(); increment_value(); increment_value(); std::cout << "test: " << size << std::endl; // 3 }I understand that I need to use consteval or constexpr, but I can't wrap my head around it.
