Atmel CAVR-4 Manual De Usuario
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
CAVR-4
116
Feature descriptions
AVR® IAR C/C++ Compiler
Reference Guide
Templates and data memory attributes
For data memory attributes to work as expected in templates, two elements of the
standard C++ template handling have been changed—class template partial
specialization matching and function template parameter deduction.
standard C++ template handling have been changed—class template partial
specialization matching and function template parameter deduction.
In Extended Embedded C++, the class template partial specialization matching
algorithm works like this:
algorithm works like this:
When a pointer or reference type is matched against a pointer or reference to a template
parameter type, the template parameter type will be the type pointed to, stripped of any
data memory attributes, if the resulting pointer or reference type is the same.
parameter type, the template parameter type will be the type pointed to, stripped of any
data memory attributes, if the resulting pointer or reference type is the same.
Example
// We assume that far is the memory type of the default pointer.
template<typename> class Z;
template<typename T> class Z<T *>;
Z<int _ _near *> zn; // T = int _ _near
Z<int _ _far *> zf; // T = int
Z<int *> zd; // T = int
Z<int _ _huge *> zh; // T = int _ _huge
In Extended Embedded C++, the function template parameter deduction algorithm
works like this:
works like this:
When function template matching is performed and an argument is used for the
deduction; if that argument is a pointer to a memory that can be implicitly converted to
a default pointer, do the parameter deduction as if it was a default pointer.
deduction; if that argument is a pointer to a memory that can be implicitly converted to
a default pointer, do the parameter deduction as if it was a default pointer.
When an argument is matched against a reference, do the deduction as if the argument
and the parameter were both pointers.
and the parameter were both pointers.
Example
template<typename T> void fun(T *);
fun((int _ _near *) 0); // T = int
fun((int *) 0); // T = int
fun((int _ _far *) 0); // T = int
fun((int _ _huge *) 0); // T = int _ _huge
Note that line 3 above gets a different result than the analogous situation with class
template specializations.
template specializations.