I have a function which can be simplifed as:
template<typename T>
void my_function(T value_in)
{
static int my_number{};
// Do stuff with my_number and value_in
my_number++;
}
What I want is for my_number
to increment on each function call. This would work as I expect if this was not a templated function, however, the behavior of this is not as expected due to multiple functions being generated (at compile time? is generated the proper term?) based on T
's type when calling this function elsewhere in my project.
Currently, my solution is to do something like this:
int static_number_incrementer()
{
static int static_number{};
return static_number++;
}
template<typename T>
void my_function(T value_in)
{
int my_number = static_number_incrementer();
// Do stuff with my_number and value_in
}
This works, but I'm wondering if there is something more "built-in" that I can use in the original implementation of my_function
that doesn't require creating a second function?