"template" and constant expressions

N

Noah Roberts

template < bool b >
struct whatnot
{
template < typename T>
void call();
};


template < typename T >
struct fun()
{
bool const what = a_metafunction<T>::value;

whatnot<what>::call<T>();
// or....
// whatnot<what>::template call<T>();
}

MSVC accepts either. Which is correct? What has me confused is that
"what" is not a dependent name, but on the other hand it's a constant
expression that IS dependent. If what was a type I'd be certain the
second expression should be used.
 
M

Marc

Noah said:
template < typename T >
struct fun()
{
bool const what = a_metafunction<T>::value;

whatnot<what>::call<T>();
// or....
// whatnot<what>::template call<T>();
}

MSVC accepts either. Which is correct? What has me confused is that
"what" is not a dependent name, but on the other hand it's a constant
expression that IS dependent. If what was a type I'd be certain the
second expression should be used.

You still want "template" there. Whether "what" is a type or a value
doesn't change the fact that the compiler needs the extra information.
 
M

Michael Doubez

This isn't valid C++, typo?

Neither is:
whatnot<what>::call<T>();

Since whatnot<>::call<> is not a static member function.

Concerning the original question, 'what' is value-dependent because is
(§14.6.2.3) "a constant with integral or enumeration type and is
initialized with an expression that is [value-dependent] a name
declared with a dependent type". That makes whatnot<what> value-
dependent.

I expect that the '::template' form is the proper one. In fact, as I
understand it, if it wasn't the proper form, the compiler should not
allow it.
Either way, IMO this is an extension of the compiler. At least
regarding the current standard; IIRC C++0x no longer requires
'typename' and may be 'template' to be used only in the proper place.
 
N

Noah Roberts

template < bool b >
struct whatnot
{
template < typename T>
void call();
};


template < typename T >
void fun()
{
bool const what = a_metafunction<T>::value;

whatnot<what>::call<what>();
// or....
// whatnot<what>::template call<what>();
}

Comeau only eats the latter so I'll assume that what is a dependent name
as well.
 
P

Paul

Noah Roberts said:
Comeau only eats the latter so I'll assume that what is a dependent name
as well.

--
You can't call a nonstatic member function without an object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top