Ian Collins a écrit :
mosfet wrote:
>HI,
when trying to compile an embedded version of STL called ustl on win32
platform I get the following error :
/// Returns the minimum of \p a and \p b
template <typename T1, typename T2>
inline const T1 min (const T1& a, const T2& b)
{
return (a < b ? a : b);
}
There's nothing wrong with the above, maybe you have disabled templates?
>I think it comes from the fact template functions like this are not
standard C++.
Could someone confirm ?
What's non-standard about it?
I thought that now you cannot declare "global" templates without class
keyword.
When I look at MSDN doc here is whar I see :
The summary is optional.
The template declaration specifies a set of parameterized classes or
functions.
template < template-parameter-list declaration
Remarks
The template-parameter-list is a comma-separated list of template
parameters, which may be types (in the form class identifier, typename
identifier, or template < template-parameter-list class identifier) or
non-type parameters to be used in the template body. The syntax for a
template parameter is one of the following:
Copy Code
parameter-declaration
class identifier [ = typename ]
typename identifier [ = typename ]
template < template-parameter-list class [identifier][= name]
You can instantiate a class template much like you would instantiate a
normal class, but you must include the template arguments within angle
brackets (<>). These template arguments can be any type if the template
argument list contains the class or typename keyword, or a value of the
appropriate type if the argument is a non-type argument. No special
syntax is required to call a function template, although the angle
brackets and template arguments can be required if the template
parameters cannot be deduced from the arguments to the function.
The template-parameter-list is a list of parameters used by the template
function that specifies which parts of the following code will vary. For
example:
Copy Code
template< class T, int i class MyStack...
In this case, the template can receive a type (class T) and a constant
parameter (int i). The template will use type T and the constant integer
i upon instantiation. Within the body of the MyStack declaration, you
must refer to the T identifier.
A template declaration itself does not generate code; it specifies a
family of classes or functions, one or more of which will be generated
when referenced by other code.
Template declarations have global, namespace, or class scope. They
cannot be declared within a function.