Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.
A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.
Document number: N3651
Date: 2013-04-19
Variable Templates (Revision 1)
by Gabriel Dos Reis
Excerpt:
C++ has no notation for parameterized constants as direct as for functions or classes. For instance, we would like to represent the mathematical constant with precision dictated by a floating point datatype
template<typename T> constexpr T pi = T(3.1415926535897932385);and use it in generic functions, e.g. to compute the area of a circle with a given radius:
template<typename T> T area_of_circle_with_radius(T r) { return pi<T> * r * r; }The types of variable templates are not restricted to just builtin types; they can
be user defined types. ...This report proposes a simple extension to C++: allow variable templates. It makes definitions and uses of parameterized constants much simpler, leading to simplified and more uniform programming rules to teach and to remember.
Add a Comment
Comments are closed.