Consider this code snippet,
template<bool b>
struct other
{
static const bool value = !b;
};
template<bool b>
struct test
{
static const bool value = b || other<b>::value;
};
int main()
{
bool value = test<true>::value;
}
Do compilers instantiate other<true>
in situations such as the above, when instantiating seems completely unnecessary? Or just because I've written the syntax other<b>::value
, compilers must instantiate it regardless of the fact that it contributes absolutely nothing to the calculation of the value of test<true>::value
?
I would like to hear, a) what is required by the Standard, and b) what is actually implemented by the various compilers? Relevant sections from the Standard would be appreciated.
other<b>::value
and whether it is convertible tobool
at all and makes sense. For doing soother<b>
needs to be instantiated. What if its type would yield to an overloadedop||
being called? The initializer would be invalid then. – Mercury