$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Beth Jacobson (bethj_at_[hidden])
Date: 2006-11-03 16:25:24
Jeremy Day wrote:
> All,
> 
> I have been following this discussion and I would like to just add a 
> general point.  I have been trying to grok template metaprogramming off 
> and on for a while now, and I think that the leap from object-oriented 
> programming to template metaprogramming is a good deal larger than the 
> leap from procedural programming to object-oriented programming.
That's been my experience, too. Template metaprogramming is like an 
alternate universe where the 'normal' rules no longer apply. For 
example, take something like this:
template <typename X>
X divide_em(X x, X y)
{
   if (typeid(x) == typeid(std::string))
     return x;
   else
     return x/y;
}
std::cout << divide_em<std::string>("one", "two");
It's hard at first to understand why this code doesn't work. It takes a 
real paradigm shift to see it not as an executable would (x is a string, 
so take the 'if' path and ignore the 'else' path), but as the compiler 
would (construct a function whose last line divides two strings).
I'm afraid I can't comment on MPL, either the book or the library. I'd 
assumed that there wasn't much point in even looking at it until I was 
completely comfortable with metaprogramming. Reading this thread has 
made me question that assumption. Is MPL appropriate for metaprogramming 
newbies?