Boost logo

Boost Users :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-11-02 13:39:52


"David Abrahams" <dave_at_[hidden]> wrote

> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:
>
>> "Terry G" <tjgolubi_at_[hidden]> wrote
>>
>>> I've just finished reading C++ Template Metaprogramming again.
>>> I just don't get it.
>>
>> Should probably not be your first book on template metaprogramming.
>
> Really? We designed the book to serve as a complete introduction.
>
>> Really, it's just like trying to learn STL without any idea what a
>> template is.
>
> It's not as though the book starts out assuming you know what a
> metafunction is. What introductory material do you think we missed
> and should have covered?

Well, it's all about approach to the problem. You present metaprogramming
as a systematic discipline. Andrei presents it as a number of tricks. You
define metafunction. Andrei just shows how to select between types and
implement typelist. For some people your approach may be more natural, but
I personaly prefer his as far as the introduction to the subject is
concerned. Once I get a good feel of what can be done, and why, then I am
ready to talk about systematic approach.

Another thing that IMO doesn't help understanding of the material, either in
the book or in the MPL docs, is the extensive usage of lambda. IMO it just
adds extra magic to the examples, making one feel that he doesn't really
understand how things work. I think examples with regular metafunction
objects would be much easier to understand, at least initially.

>>> Why would someone use a type container?
>>
>> For example, one could implement a generic tuple class (although I don't
>> think boost::tuple uses this approach, but probably fusion does?). Also
>> see
>> below...
>
> Of course, that begs the question of why someone would want a tuple.

To implement a relational library ;-)

>>> I'd really like a reference to an MPL primer or some case studies.
>>
>> IMO, you should really start with template metaprogramming itself, and
>> then
>> move to MPL. Try Alexandrescu's "Modern C++ design" -- it also contains
>> a
>> lot of examples why you would want to use a typelist.
>
> As great a book as "Modern C++ Design" is, it really surprises me to
> see it recommended as an introduction to template metaprogramming over
> "C++ Template Metaprogramming." MC++D is not about specifically TMP,
> and doesn't even attempt to describe what TMP is. It does contain
> numerous examples of basic TMP applied to traditional OO design
> patterns, which I think is the real point of that book, and IMO makes
> MC++D an ideal follow-on to C++TMP.

Not really, once I read you book I would like to use MPL, right ;-)

As for me personally, I read Alexandrescu first, then Czarnecki (chapter
10, I think), and then your book. If I had to start now, I would use same
order -- it works for me -- but I realize that it can be different for other
people.

To summarize -- I think your book is great for the intermediate to advanced
metaprogrammers, but as far as beginners are conserned, it may not always
work. As in the case with the OP.

Regards,
Arkadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net