|
Boost : |
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2002-06-19 20:23:28
Dave, I like your names better than mine.
Here is how the parts that confused you are used. Note that I'm using my
current naming scheme, for now.
#define BOOST_PP_BOUND 100 // this is not a range
#include BOOST_PP_SET_UBOUND()
What this does is abstract the depth of upper bound of the next iteration.
BOOST_PP_SET_UBOUND() yields a different filename depending on the depth of the
iteration. Whatever file that is evaluates BOOST_PP_BOUND and assigns that
value to a upper bound macro used internally at any given depth. The file then
undefines BOOST_PP_BOUND for reuse. This is an actual *assignment of the value*
not a lazy-evaluation reference. For a very trivial example: (note that I
tabbed it out more than I normally would to make the directives clear.)
// file.hpp
#if !defined(BOOST_PP_IS_ITERATING)
#ifndef FILE_HPP // normal file begins here
#define FILE_HPP
#include <boost/preprocessor/comma_if.hpp>
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repeat.hpp>
template<int> struct test; // no def
template<> struct test<0>; // no def
#define BOOST_PP_BOUND 1
#include BOOST_PP_SET_LBOUND()
#define BOOST_PP_BOUND 100
#include BOOST_PP_SET_UBOUND()
#define BOOST_PP_FILENAME_1 "file.hpp"
#include BOOST_PP_ITERATE()
#endif // end of normal file
#else // this part get iterated over
#line BOOST_PP_LINE(__LINE__, file.hpp) // for debugging
#define C BOOST_PP_FILE_ARG() // temporary
#define ABC(n, nil) BOOST_PP_COMMA_IF(n) class T ## n
template<> struct test<C> {
template<BOOST_PP_REPEAT(C, ABC, nil)>
struct args { /* whatever */ };
};
#undef ABC
#undef C
#endif
This produces:
template<> struct test<1> {
template<class T0>
struct args { };
};
template<> struct test<2> {
template<class T0, class T1>
struct args { };
};
// etc. up to 100
Does that help? (BTW, this took me 5 seconds to preprocess up to 100).
Paul Mensonides
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk