Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeRAD Studio

Learn How to Use C++ Default Template Arguments for Function Templates On Windows

Default template arguments are specified in the parameter lists after the = sign. Defaults can be specified for any kind of template parameter (type, non-type, or template), but not to parameter packs.

If the default is specified for a template parameter of a primary class template, each subsequent template parameter must have a default argument, except the very last one may be a template parameter pack. In a function template, a parameter pack may be followed by more type parameters only if they have defaults or can be deduced from the function arguments.

When templates were originally added to the C++ language, explicit function template arguments were not a valid construct. Function template arguments always had to be deducible from the call expression. As a result, there seemed to be no compelling reason to allow default function template arguments because the default would always be overridden by the deduced value.

The impossibility of setting default template arguments for function templates has been limiting the programming style for a long time. In C++11, such default arguments can be used.

Default template arguments for function templates example

Find out more about C++ default template arguments for function templates and more modern C++ features in the Embarcadero DocWiki.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
CodeDatabaseDelphiRAD Studio

Quickly Learn How Easy It Is To Bind DataSets To Visual Controls In Delphi With LiveBindings

C++CodeRAD Studio

Learn How To Use C++ Incomplete Return Types In Windows Development

C++Delphi

Create Beautiful Windows Applications With Visually Stunning VCL Styles For Delphi And C++

CodeDelphiRAD Studio

Master A Powerful Way To Execute Multiple SQL Commands In Delphi With This Windows Sample

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES