3 ms·
You have a problem. You've decided to use C++ templates. Now you have two problems.
by rikthevik 17y ago
You have a problem.
You've decided to use C++ templates.
Now you have two problems.
- tomjen3 17y agoTemplates are useful when you need to use the standard containers. When you start doing metaprogramming beyound that, guys like me start to get very nervous.
- hazzen 17y agoI like to make a very important distinction with templates in C++, categorizing uses into three classes: 1) "Java" generics. That is, anything you could do with generics in Java. No one should have an issue using templates like this. 2) Non-recursive "typedef" programming. That is, uses like "::value_type" in the STL containers. These are incredibly useful to have around when writing generic algorithms, but their overuse leads to unparseable code to some set of C++ programmers. Use with caution, but still use. 3) Recursive templates and other subtle uses I haven't covered with the above two. Try very, very, very hard to avoid. That makes the "will my coworkers understand this code?" question very easy to answer.
- dons 17y ago4) Implementing Turing-complete type level languages :-)
- keveman 17y agoWhere would you place expression templates that help designers to embed simple domain specific languages in C++? The end user doesn't have to know much about templates, but this approach leads to high performance AND very concise and expressive code.