Recently, I learned about non-type reference parameters like template<auto& t>
.
Then I find that t
can be modified at run-time:
#include <iostream>
template<auto& N>
struct X{
int operator()() { return N; }
};
int a = 2;
int main()
{
std::cin >> a; //stdin: 5
auto temp = X<a>();
std::cout << temp() << '\n';
}
The output is 5
, not 2
. Does it mean temp
is instantiated at run-time?
I will try to answer my own question. If anywhere wrong, please correct me, thx! Other answers also welcome!