|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2008-07-20 09:38:58
on Sun Jul 20 2008, Zeljko Vrba <zvrba-AT-ifi.uio.no> wrote:
> No, I have not used MPL. Yes, I've read the introduction and
> motivation (the example with dimensional algebra), and it seems like a
> rather niche application. Heck, I've even tried to read the MPL book
> and the question mark in my head just got bigger, not smaller. It is
> a reference book about manipulating typelists, but it does not say
> what typelists are good for.
"C++ Template Metaprogramming" is not intended to be a reference book
about manipulating typelists at all. Did you start reading from the
beginning of the book, or did you skip to chapter 3 or so? The
introduction lays some important conceptual foundations about what
metaprogramming is all about. Typelists (not even a term we use in the
book) are merely one means to reaching the many ends of metaprogramming.
> I haven't been able to find a use for MPL myself. From my POV, it's a
> black magic used by library writers to provide "nice" library
> interfaces,
That's a reasonable point of view to take if you don't want to do
template metaprogramming and just want to be a consumer of its benefits.
However, if you're trying to use fusion beyond the most basic
operations, well, you're doing template metaprogramming. Understanding
MPL provides a good foundation for understanding fusion, and in fact
fusion uses enough MPL idioms that it would be very difficult to learn
any other way.
> and which spits out hundreds (or megabytes if the user is unlucky) of
> error messages if the user does something wrong.
Welcome to C++ template instantiation. The same goes for just about any
template library (e.g. STL).
> And the basic question remains unanswered for me: How does MPL (or
> fusion for that matter) help in making more maintainable code? More
> maintainable as in:
>
> - less lines of code
> - code that is easier to understand
> - code that is easier to inspect at runtime with a debugger
> - code that can be modified by a C++ developer who does not know every dark
> corner of the template language
> - code that is written faster (i.e. takes less time to get a successful
> compilation) and works correctly the first time it is written
Did you look at the binary number example in the first pages of our
book? It addresses many of the above questions.
> How are fusion/MPL useful to an *application* programmer, not a
> library developer?
Ah. Well, some people think every application programmer should think
of himself as a library developer. If you're writing code that will be
re-used by your colleagues, or even by yourself, that code is
essentially library code.
However, you do have a point: fusion, MPL, and templates in general are
useful for building flexible, generalized components that can be
configured for different applications without loss of efficiency. If
you are building one-off code, you probably don't have much use for them.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
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