I recently watched a video from Microsoft explaining some of the new features of C ++ 17, and I was intrigued to find a C ++ 14 function (and maybe even before that?) That allows you to use the address of a global variable as a constant expression for template argument.
This allows you to use the following code:
#include <iostream>
int g_iTest = 5;
template <int* Addr>
struct S {
static int TestAdd( int iTest ) {
*Addr = iTest + *Addr;
return *Addr;
}
};
int main() {
S<&g_iTest> s;
std::cout << s.TestAdd( 5 ) << std::endl;
}
10. , , , , . , , extern int g_iTest, ?
?