Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-06-26 08:17:01


Andrei Alexandrescu wrote:
> STL does reduce the amount of code you write quite
> drastically, and it would be hard to convince me
> otherwise because I know that from direct and
> extensive experience. But why compare mpl with stl
> instead of concretely discussing on mpl as it stands.

May be because there is a direct relationship between these two libraries?

Here's how I would write a code that finds the element of maximum size in a
sequence using (extended) STL facilities (something we use here at work):

    long size_of(something const&);
    std::vector<something> s;
    // ...
    assert(!s.empty());
    long max_size = *stl::max_element(
        stl::transformed_seq(s,std::ptr_fun(size_of))
        );

Here is a compile-time equivalent of the above implemented with MPL:

    typedef mpl::list4<int,char,char[50],double> types;
    // ...
    typedef mpl::max_element<
          mpl::transformed_seq< types, mpl::size_of<_> >
>::type::type max_size;
    BOOST_STATIC_ASSERT(max_size::value == 50);

Does it ring a bell?

/Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk