|
Boost Users : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2006-11-03 21:29:07
Hi Ovanes,
> I need to define a map with int_<1...150>->Type1...150 pairs.
>
> Im source file I define:
>
> #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
> #define BOOST_MPL_LIMIT_MAP_SIZE 150
>
> #include <boost/mpl/map.hpp>
A word of caution: redefining BOOST_MPL_LIMIT_MAP_SIZE is not
recommended. Doing so globally will make you pay for what you probably
don't use (unless all present and future 'map' usages in your project
demand the 150-elements limit), and doing so within a translation unit
will lead to an ODR violation.
If you need to construct a sequence beyond the default size, use its
numbered form
(http://www.boost.org/libs/mpl/doc/refmanual/variadic-sequence.html).
> When compiling I get an error in the file:
> ...\boost\include\boost-1_33_1\boost\mpl\map.hpp on line: 36 fatal
> error C1083: Cannot open include file: 'boost/mpl/map/map150.hpp':
> No such file or directory
>
> Development environment is Visual C++ 8 Express Edition
>
> The help states:
[...]
What the BOOST_MPL_LIMIT_MAP_SIZE docs don't say is that there is a
default upper limit of 50 elements for the macro's value:
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_MAP_SIZE 50
#include <boost/mpl/map.hpp> // compiles
This upper limit is overridable as well, but since touching
BOOST_MPL_LIMIT_MAP_SIZE is not recommended anyway, I'll instead
demonstrate how to bump the number of map's numbered forms up to 150.
The simpliest way would be just this:
#include <boost/mpl/map/map50.hpp>
#include <boost/preprocessor/iterate.hpp>
namespace boost { namespace mpl {
# define BOOST_PP_ITERATION_PARAMS_1 \
(3,(51, 150, <boost/mpl/map/aux_/numbered.hpp>))
# include BOOST_PP_ITERATE()
}}
// use map150<....>
with the caveat that the extra 100 map templates are generated on the
fly using the preprocessor, which isn't ideal from the compilation
time standpoint.
Alternatively, you can pre-generate these extra templates once and for
all using the '$BOOST_ROOT/libs/mpl/preprocessed/preprocess_map.py'
script and the existing numbered map files in the
'$BOOST_ROOT/boost/mpl/map/' and
'$BOOST_ROOT/libs/mpl/preprocessed/map/' subdirectories as an example.
HTH,
-- Aleksey Gurtovoy MetaCommunications Engineering
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