C++14 will allow the creation of variables that are templated. The usual example is a variable 'pi' that can be read to get the value of the mathematical constant π for various types (3 for int
; the closest value possible with float
, etc.)
Besides that we can have this feature just by wrapping a variable within a templated struct or class, how does this mix with type conversions? I see some overlapping.
And other than the pi
example, how would it work with non-const
variables? Are there any usage examples to understand how to make the most of such a feature and what its purpose is?
Best Answer
Yes, but that would be gratuitous syntactic salt. Not healthy for the blood pressure.
pi<double>
conveys the intent better thanpi<double>::value
. Short and to the point. That's enough of a reason in my book to allow and encourage this syntax.