Tagged Metaprogramming
Template Metaranting
Posted on by Idorobots
Here's another post in the series, this time it's C++ vs. the D programming language.
Let's talk about templates. If you've ever tried templates in C++ you surely as hell recall the pages and PAGES of compiler errors and seemingly random placement of typename
keyword. Trust me, there are EVEN WORSE problems with templates in C++... Consider the following:
struct Foo {
template<int N>
void bar() {}
template<int N>
struct Bar {};
};
template<typename T>
void f() {
T foo;
foo.template bar<0>(); // Line 12
typename T::template Bar<0> b; // Line 13
}
int main() {
f<Foo>();
}