Template parameters and arguments
I have several questions while reading "C++ Templates: The Complete Guide/David Vandevoorde, Nicolai M. Josuttis"
Code:
template<int I> void f(int (&)[24/(4+I)]);
int main()
{
&f<4>;
}
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
2. what is the meaning/result of the statement in main
and how do I call function f (assuming I'd add an implementation to the template fuction decleration)
I failed to compile it on Dev-cpp 4.9.9.2 : gcc 3.4.2
though succeded with Comeau 4.3.3 online compiler -
which leads me to another question - what is a recommended C++ compiler
that supports the most of templates features?
Re: Template parameters and arguments
Quote:
Originally Posted by Guysl
Code:
template<int I> void f(int (&)[24/(4+I)]);
int main()
{
&f<4>;
}
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
2. what is the meaning/result of the statement in main
and how do I call function f (assuming I'd add an implementation to the template fuction decleration)
1. No idea.
2. It takes the address of an instance of the template function, thus forcing the compiler to create a function f that takes an int(&)[3] as argument.
Quote:
I failed to compile it on Dev-cpp 4.9.9.2 : gcc 3.4.2
though succeded with Comeau 4.3.3 online compiler -
which leads me to another question - what is a recommended C++ compiler
that supports the most of templates features?
Comeau is afaik known to be the compiler closest to the C++ standard.
Re: Template parameters and arguments
Seems the authors failed to express an useful example of language features.
Re: Template parameters and arguments
when compiled with Comeau's online compiler, got this message
Code:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++
"ComeauTest.c", line 5: warning: expression has no effect
&f<4>;
^
Re: Template parameters and arguments
Quote:
Originally Posted by Guysl
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
Yes, it is a reference to a an array of 3 integers.
Quote:
Originally Posted by Guysl
2. what is the meaning/result of the statement in main
Basically, it has no effects.
It is the expression of the address of a template instance of the template function f.
This template instance has the I parameter equal to int.