Talk:Template (C++)

message: "Tips for Using Templates" is not encyclopedia-like, anyone object to removing that section? -Wootery 17:01, 21 November 2006 (UTC)
thread_title:  Removing 'Tips' section 

message: While this article is not particularly well written, the subject of templates is particularly important in many circumstances and should not be removed.  —Preceding unsigned comment added by 136.165.3.236 (talk) 15:59, 25 September 2007 (UTC)
thread_title:  Question about removal 

message: I think when one lists stuff so he should use list (or tree) ;) Xchmelmilos (talk) 18:47, 11 March 2008 (UTC)
thread_title:  Added little list 

message: I'm not a grammar king but sentences like: "compilers historically generate somewhat esoteric" and "many compilers historically have very poor support" seem to mix tenses incorrectly - the use of the word "historically" especially seems to jar. Either compilers still do xyz or they don't. Based on my experience of current C++ compilers both sentences are either out of date or irrelevant, depending on what exactly they're supposed to be saying.  —Preceding unsigned comment added by Jonhanson (talk • contribs) 21:12, 20 March 2008 (UTC)
thread_title:  Odd mixing of tenses 

message: The current C++ standard does not allow partial specialization of function templates.  Only class templates can be partially specialized.  The article is somewhat misleading in this regard, but technically not incorrect ("such and such is called partial specialization").  —Preceding unsigned comment added by 71.97.78.127 (talk) 15:19, 26 September 2008 (UTC)
thread_title:  Partial Specialization of Function Templates 

message: I am afraid that your contributions may have to be removed, qualifying as original research. I am not unfamiliar with max/min taking arguments of different types, but even the "promote" solution has its problems, the most glaring one being 
int j = max(-1, 0u);
which has implementation-defined behaviour, equivalent to: int j = static_cast<int>(UINT_MAX); decltype 10:55, 23 January 2009 (UTC)
thread_title:  Function template edits by anonymous editor 

message: // Induction 
template <int N> struct Factorial {
  const int value = N * Factorial<N - 1>::value;
};
// Base cases via template specialization:
template <>
struct Factorial<0> {
  const int value = 1;
};
template <>
struct Factorial<1> {
  const int value = 1;
};
I think this example is slightly wrong, "value" should be "static const int value", otherwise it does not compile. Can anybody confirm that, or is it just my compiler? --StCz (talk) 15:20, 1 March 2009 (UTC)
replies: text: You're right. Another possibility is to use unnamed enums, which avoids the problem with static const members and the One Definition Rule (they can only be used where an integral constant expression is required). Anyway, nice find! decltype 18:43, 1 March 2009 (UTC)
thread_title:  C++ factorial example incorrect 

message: What do the keywords ::value and ::type mean? --Abdull (talk) 16:35, 23 January 2010 (UTC)
replies: text: They are not keywords. In the example code, Factorial<N - 1>::value refers to the static const data member value of a particular specialization of the Factorial template. Since the definition of the promote template is not shown, it is impossible to tell what promote<T,U>::type refers to, so this example should not really be there. It's original research, too. However, type would typically be a typedef. For example: template<typename T, typename U> struct promote { typedef T type; }; So promote<double, int>::type would be equivalent to double, for example. decltype (talk) 17:06, 23 January 2010 (UTC)
thread_title:  Template keywords 

message: Are Templates Turing complete: in principle would it be possible to perform arbitrary computations during the compiling (rather than just by executing the program afterward)? Alternatively, is the phase of unravelling templates always guaranteed to halt (as it presumably is for macros)? Cesiumfrog (talk) 23:56, 31 January 2011 (UTC)
thread_title:  turing 

message: The "generic programming" article has become a long list of language mechanisms for templates/generics-- perhaps it would be better to move such language technical descriptions here.  — Preceding unsigned comment added by Brianbjparker (talk • contribs) 00:55, 6 August 2011 (UTC)
thread_title:  some overlap with "Generic programming" article 

message: Several if not all of the disadvantages listed were arguably true 15 years ago, but no longer defensible. (I personally nixed the extensive use of templates in a large project ca. 1995. Today that would be unwise.) The whole section is just a collection of unattributed opinions. Despite the putative "fundamental drawbacks," most of the volume of work done by the standards committees and developers over the last few years has been devoted to templates and their use. The standard template library is now thoroughly incorporated into the language and into recognized best practices. Re-working the section would be a big job, digging up historical documents about problems with templates and how the C++ community addressed them. I say delete the section.  Jive Dadson (talk) 01:48, 13 August 2012 (UTC)
thread_title:  Advantages/disadvantages out of date 

message: The reference to Boost enable_if is out of date. It still exists of course, but enable_if has been incorporated into a new and extensive sub-library of the Standard Template Library (STL), along with many other features of Boost. The whole subject of C++ templates is big, and in a state of flux. There are many additions coming with the new C++11 standard, which as of today Aug. 13, 2012, has been published but is not yet not fully implemented in many compilers. 
The lead says there are two kinds of templates. C++11 adds another for typedefs. (For technical reasons, the committee selected the keyword "auto.")
I think this article needs to be purged of technical info and opinion, and reduced to links and references. Jive Dadson (talk) 01:58, 13 August 2012 (UTC)
thread_title:  More out-of-date stuff 

message: This code is incorrect
    #include <iostream>
 
    int main()
    {
       // This will call max <int> (by argument deduction)
       std::cout << max(3, 7) << std::endl;
       // This will call max<double> (by argument deduction)
       std::cout << max(3.0, 7.0) << std::endl;
       // This type is ambiguous, so explicitly instantiate max<double>
       std::cout << max<double>(3, 7.0) << std::endl;
       return 0;
   }
max should be replaced by std::max
J.A.Belloc (talk) 13:13, 25 December 2012 (UTC)
thread_title:  Incorrect code under "Function Templates" 

message: In the section Function template there's the following text:
* a type parameter does not need to be a class, it may also be a basic type like int or double.
Which is uncorrect, ‘double’ is not a valid type for a template non-type parameter, the only correct non-type parameters are integrals.--Pau.Montequi (talk) 17:09, 9 December 2013 (UTC)
replies: text: Note that it's talking about type parameters, not non-type parameters. It's saying that the T in template<class T> doesn't have to be a class (in an instantiation of the template). It can, of course, be double. Perhaps you could suggest different wording if you think it's unclear. (The wording has been changed a little since your comment, but not in any significant way.) --Zundark (talk) 09:31, 5 July 2018 (UTC)
thread_title:  Function template error 

message: So, pros of templates is that templates gives to a C++ programmer a compile-time way of coding without knowing of all classes specification in advance.  — Preceding unsigned comment added by RippleSax (talk • contribs) 14:37, 27 November 2015 (UTC)
thread_title:  Pros of templates 

message: A section on portability is to be desired. I saw many years ago advice such as "avoid templates if you ever want to deploy your code to a micro controller." Is this even remotely true today? Avindratalk / contribs 20:02, 19 November 2020 (UTC)
replies: text: This article describes some standard features of C++ templates, which are supported by most compilers today. Some compilers (such as g++) have non-standard extensions to the C++ language which are not portable. Jarble (talk) 18:16, 31 August 2021 (UTC)
thread_title:  Portability