Re: Is template metaprogramming allowed by the standard?
Peter <pilarp@poczta.onet.pl> wrote:
It's going to be a very general question, but here it goes: is template metaprogramming a serious programming technique, used in real-life code? Is there anything in C++ standard that guarantees its validity and/or portability (at least to some extent) or is template metaprogramming merely a curiosity, an unexpected side effect of adding templates to language definition and everything about it is either undefined or implementation defined?
Btw, define "template metaprogramming".
Would you consider the following "template metaprogramming", or would
you consider it something else?
Consider what happens here:
std::vector<size_t> v(10, 20);
You are constructing a vector with 10 elements, each having the value 20.
But how does the compiler know you are wanting to do that? The question
raises because std::vector has a constructor taking two iterators, which
is declared effectively as:
template<typename Iter>
std::vector<ValueType>::vector(Iter begin, Iter end);
That vector creation earlier matches that declaration perfectly. Yet still,
somehow, the compiler doesn't try to call this, and instead calls the
correct constructor (ie. the one that takes a number and a value to
initialize the vector with).
std::vector achieves this via template trickery. Would you consider
this "template metaprogramming"? It certainly is non-trivial trickery
using templates.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---