Boost logo

Boost :

Subject: Re: [boost] [mpl][docs]why use list?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-03-23 06:40:25


On 03/21/09 11:31, Steven Watanabe wrote:

Thank you Steven for your response.

> AMDG
>
> Larry Evans wrote:

[snip]

>> Is there any reason to prefer list over of vector?
>
> Usually vector is better. The maximum size of a vector is 50
> on compilers that don't support typeof.

Unfortunately, following the directions on:

http://www.boost.org/doc/libs/1_38_0/libs/mpl/doc/refmanual/limit-vector-size.html

I created vector_max.cpp which had an 80 element vector
preceded by this at the top of the file:
-{--cut here--
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_VECTOR_SIZE 80
#include <boost/mpl/vector.hpp>
-}--cut here--

However, compilation resulted in:

-{--compilation--

/home/evansl/download/gcc/4.4-20090109/install/bin/g++ -c -Wall
-ftemplate-depth-100 -O0 -fno-inline
-I/home/evansl/prog_dev/boost-svn/ro/boost-trunk vector_max.cpp -o
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/sandbox/build/gcc4_4/variadic-templates/libs/mpl/sandbox/vector_max.o
-MMD
In file included from vector_max.cpp:10:
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/boost/mpl/vector.hpp:36:73:
error: boost/mpl/vector/vector80.hpp: No such file or directory
In file included from
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
                  from
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/boost/mpl/aux_/sequence_wrapper.hpp:164,
                  from
 
/home/evansl/prog_dev/boost-svn/ro/boost-trunk/boost/mpl/vector.hpp:54,

-}--compilation--

Does anyone know what I might be doing wrong?

> Also, it is possible for memoization to reduce the number of
> template instantiations when iterating over lists with identical
> tails, iterators into distinct vectors always have different types.

Thank you. This is what I needed to know. In summary.

   vector is better for modification at end.

   list may be better for traversal over many lists with similar tails.
   This list advantage is true for compilar using memoization.

This information would have been useful to me while developing the
variadic template version of mpl because, IIRC, I started trying to
emulate the mpl list, but couldn't see any reason to continue. As a
result, the mpl-vt.zip in vault only has the package template which is
used to implement both the vector and list templates.

So, I'd recommend adding this justification for list to the docs.
[snip]


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