C++:template
lastmod 2020-04-18created 2015-03-2015 edits
Template implementation
Suppose you have code like the following:
template <typename T1, typename T2>
class SomeClass
{
template <typename E>
void extraTypedMethod(E & e);
};
You can separate the implementation as follows.
template <typename T1, typename T2>
template <typename E>
void SomeClass<T1, T2>::extraTypedMethod(E & e)
{
// ...
}
Template template parameter
Variadic template
A new ... expression that lets a template take a variable number of type arguments.
Variadic CRTP
The Curiously-Recurring Template Pattern (CRTP) is a pleasant and common C++ coding idiom. This installment of Once, Weakly combines CRTP with variadic template template parameter packs to implement restricted numeric types suitable for implementing memory-mapped devices.
Template Trees for Modern C++ Interfaces
Modern C++ increasingly uses “Do What I Mean” (DWIM) interfaces that depend on interface selection based on secondary properties of types. Often, these interfaces make use of SFINAE techniques and/or static assertions that require the ability to compose complex compile time queries about types. This installment of Once, Weakly describes the implementation and use of a simple facility for compile time composition and evaluation of abstract syntax trees (ASTs) of template predicates.
See also
Favorite site
- Function template? Template function?
- C++ Templates: The Complete Guide 3
- [Recommended] C++ Template Note