Talk:cpp/language/variable template
The 'struct matrix_constants' example code has no static keyword; however, the 'struct limits' example does. So is the static keyword optional?
74.192.23.50 08:17, 18 November 2014 (PST)
- Thanks for pointing this out. The keyword is not optional, the examples in the standard have an error, mentioned here. I'll update --Cubbi (talk) 08:29, 18 November 2014 (PST)
Thanks for clarifying. However, the page also says:
A definition of a static data member template may be provided outside the class definition.
which someone may misinterpret as meaning the definition outside the class definition is optional; however, according to tests run with clang3.5 on the code here:
https://gist.github.com/cppljevans/15d77d217e90e4a6c09a
it's *only* optional if a reference is not made to the template variable.
- Sounds like you've encountered 17848. Besides, "may be provided" is direct quote from [temp.static] --Cubbi (talk) 14:39, 21 November 2014 (PST)
Good point! However, even though that's what the standard says, the standard is not perfect. The page could clarify what "may be provided" by citing other parts of the standard, such as 9.4.2p3:
The member shall still be defined in a namespace scope if it is odr-used (3.2)
and then an informal description of odr-used, such as the one here:
HTH.
--74.192.23.50 07:23, 22 November 2014 (PST)
- I've just added a link to static data members page, which gets into details --Cubbi (talk) 08:13, 22 November 2014 (PST)
[edit] i literal
What does this literal mean? There is complex header, if you want to represent complex numbers, also custom literals starting with underscore are bad practice. If this i is custom literal - then it should be marked somewhere as custom, but not implemented in this listingYanpas (talk) 05:23, 4 March 2016 (PST)
- it is the operator""i from
<complex>
--Cubbi (talk) 06:02, 4 March 2016 (PST) - The example is the same as the one in the standard. IMHO it is not a good example. --D41D8CD98F (talk) 07:24, 4 March 2016 (PST)
[edit] Shouldn't declaration be variable-declaration?
In the Explanation section: A variable template may be introduced by a template declaration at namespace scope, where declaration declares a variable.
Shouldn't it be variable-declaration ?
ticotico (talk) 07:46, 4 June 2020 (PDT)
- I guess that why variable-declaration is not used is that there is no syntax element called variable-declaration.
- Function declarations and variable declarations may not be distinguished syntactically:
using foo_t = int(); using bar_t = int; template<class> extern bar_t bar_for; // declares a variable template template<class> extern foo_t foo_for; // declares a function template