Topic: template specialization introduces dependency ?
Author: Bernhard Merkle <bernhard.merkle@googlemail.com>
Date: Thu, 26 Mar 2009 21:44:55 CST Raw View
Hi all,
I try to do some dependency analysis of meta template programming
code.
Now consider the usual Factorial example: and I have two questions:
1. Is there is a dependency between a template specialization and the
general template ?
e.g. from Factorial<0> to Factorial<N> ?
I think yes, it is a specializes relationship/dependency. also without
the general template, the specialized version is invalid.
template <int N>
struct Factorial
{
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0>
{
enum { value = 1 };
};
2. Now when invoking the template, which dependency get created (at
compile time)
int x = Factorial<4>::value; // == 24
int y = Factorial<0>::value; // == 1
I think x is dependent on Factorial<N> (and then in the second step
only on Factorial<0>
and y is dependent on Factorial<0>.
Though it is a compile time dependency, it should be detected by
dependency analysis tools.
comments welcome,
thanks,
Bernhard.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]