03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

106 CHAPTER 4. GENERIC PROGRAMMING<br />

template <br />

class vector<br />

{<br />

...<br />

};<br />

That will do the trick. Pay attention to put a space between the closing ‘¿’; otherwise the<br />

compiler will take two subsequent ‘¿’ as shift operator ‘¿¿’ and becomes pretty confused. 14<br />

This also works <strong>for</strong> classes with multiple parameters, <strong>for</strong> instance:<br />

template <br />

class vector<br />

{<br />

...<br />

};<br />

We can also specialize <strong>for</strong> all pointers:<br />

template <br />

class vector<br />

{<br />

...<br />

};<br />

Whenever the set of types is expressible by a Type Pattern we can apply partial specialization<br />

on it.<br />

Partial template specialization can be combined with regular template specialization from § 4.6.1<br />

— let us call it ‘Complete Specialization’ <strong>for</strong> distinction. In this case, the complete specialization<br />

is prioritized over the partial one. Between different partial specializations the most specific is<br />

selected. In the following example:<br />

template <br />

class vector<br />

{<br />

...<br />

};<br />

template <br />

class vector<br />

{<br />

...<br />

};<br />

the second specialization is more specific than the first one and picked when matches. In this<br />

sense a complete specialization is always more specific than a partial one.<br />

4.6.4 Partially Specializing Functions<br />

The C ++ standard committee distinguishes between explicit specialization as in the first paragraph<br />

of § 4.6.2 and implicit specialization. An example <strong>for</strong> implicit specialization is the following<br />

computation of a value’s magnitude:<br />

14 In the next (new depending on publication date) standard, closing ‘¿’ without intermediate spaces. Some<br />

compilers — e.g., VS 2008 already support the conglutinated notation today.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!