I found this working code in a metaprogramming book -
template<unsigned long N>
struct binary
{
static unsigned const value = binary<N/10>::value *2 + N%10;
};
template<>
struct binary<0>
{
static unsigned const value = 0;
};
int main()
{
unsigned x = binary<101010>::value;
cout << x;
}
My question is: where is the memory allocated for value? Is it highlighted on the data segment?
In addition, the book says that this code leads to a cascade of template instances, which computes the result similarly to recursion. Does this mean that a new one is allocated for each instance of the template in the data segment unsigned?
source
share