Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "template" and constant expressions

Reply
Thread Tools

"template" and constant expressions

 
 
Noah Roberts
Guest
Posts: n/a
 
      04-28-2011
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.
--
http://crazycpp.wordpress.com
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-28-2011
On 04/29/11 10:15 AM, Noah Roberts wrote:
> template< bool b>
> struct whatnot
> {
> template< typename T>
> void call();
> };
>
>
> template< typename T>
> struct fun()


This isn't valid C++, typo?

--
Ian Collins
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      04-29-2011
Noah Roberts wrote:

> 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.
 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      04-29-2011
On 29 avr, 00:40, Ian Collins <(E-Mail Removed)> wrote:
> On 04/29/11 10:15 AM, Noah Roberts wrote:
>
> > template< *bool b>
> > struct whatnot
> > {
> > * * template< *typename T>
> > * * void call();
> > };

>
> > template< *typename T>
> > struct fun()

>
> 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.

--
Michael


 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      04-29-2011
On 4/28/2011 3:15 PM, Noah Roberts wrote:
> 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.

--
http://crazycpp.wordpress.com
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      04-29-2011

"Noah Roberts" <(E-Mail Removed)> wrote in message
news:4dbae414$0$2685$(E-Mail Removed)...
> On 4/28/2011 3:15 PM, Noah Roberts wrote:
>> 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.
>
> --

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
constexpr references and constant expressions Inconnu C++ 1 11-16-2011 05:10 PM
pointers to constant characters and constant pointers to characters sam_cit@yahoo.co.in C Programming 4 12-14-2006 11:10 PM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM
Why constant ints in switch case expressions? Brian J. Sayatovic Java 22 07-09-2003 09:39 PM



Advertisments