Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++14 variable template with default template parameter?

C++14 will allow variable templates:

template <typename T> constexpr T pi = T(3.1415926535897932385);

Now consider the following case:

template <typename T = double> constexpr T pi = T(3.1415926535897932385);

Question: how do I get pi with the default parameter ?

pi; // Option 1 (I hope...)
pi<>; // Option 2
like image 744
Vincent Avatar asked Oct 19 '25 04:10

Vincent


1 Answers

Based on n3651 I would say pi<>;. In the current standard template argument deduction, which being able to do pi is a form of, only applies to functions. Since the paper mentions absolutely nothing about TAD it is unlikely they would use it.

like image 112
aaronman Avatar answered Oct 21 '25 18:10

aaronman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!