Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-04-14 20:24:13

Joel de Guzman wrote:
> ----- Original Message -----
> From: "Vesa Karvonen" :
> > Joel de Guzman:
> > >If knowledge of 'fold' et al is required to write an MPL
> > >algorithm, then it contradicts its primary goal.
> >
> > I'm not sure about what you are talking about here. I thought that the
> > of MPL is to facilitate template metaprogramming. One of the things
> > by MPL (in order to facilitate template metaprogramming) is a sequence
> > abstraction and a set of algorithms (higher order functions) for
> > manipulating sequences. I don't see how this would contradict the goal
> > MPL.
> Exactly! The keyword here is "facilitate".

Let's not make unfounded statements here, even implicit ones. I am pretty
sure that someone familiar with the library will write
'gen_linear_hierarchy' much more faster using MPL facilities than any C++
metaprogramming expert using "C++ only" (or, FWIW, Loki), and her version
will work on much greater number of compilers. If this doesn't fall under
your definition of "facilitate", then we are talking in different

> > >Now you are saying that one needs to learn FP (specifically higher
> > >order functions) to write an MPL algorithm?
> >
> > No, I don't think that it is strictly necessary to learn about higher
> > functions in order to write algoritms using the MPL, but I can't see why
> > someone would want to waste time writing the same pattern matching +
> > recursion patterns over and over again.
> True **IFF** the time required to learn how to use MPL's version of fold
> correctly is less than the time spent when writing an algorithm from
> scratch using the tried and true pattern matching + recursion patterns.

There is very little special semantics one need to learn about "MPL's
version of fold". The basic usage is exactly the same as in most FP
languages, and matches the semantics of 'std::accumulate' as well - it takes
a sequence, an initial state, a binary metufunction-class, and returns the
result of sequential application of the metafunction-class to each element
of the sequence and the previous state. "Tried and true pattern matching +
recursion patterns" is unfamiliar to most C++ programmers that have never
been exposed to template metaprogramming before.

> > >I thought that
> > >the reason why there was the concept of mutators, erase, replace
> > >etc. was to make it more familiar to the typical STL programmer.
> >
> > Some of the terminology used in MPL is borrowed from STL, which borrowed
> > some of the terminology from functional programming languages. AFAIK the
> > idea is to make it easier for STL programmers to understand MPL. This
> > not imply that the MPL primitives would be any less functional.
> >
> > 'erase' and 'replace' are reasonable names for functions in a functional
> > setting. Even in FP languages some list manipulation functions may have
> > names that one might confuse to be imperative.
> I have this itch to ask for examples. However, if there are indeed FP
> languages that uses imperative sounding names, is this a justification?

So, given your hypothetical (or real) "pure" FP language translated to
compile-time C++, how do you replace all float's in some type sequence by


Boost list run by bdawes at, gregod at, cpdaniel at, john at