[fusion][mpl] How to make a vector of a vector of types

Hi there, subject probably sounds a bit strange but here is what I'm trying to accomplish. The problem description goes like this: using namespace boost; using namespace boost::fusion; struct A; struct B; struct C; int main() { typedef vector< A, B, C > types; // how to translates typed into the following?? typedef vector< std::vector<A>, std::vector<B>, std::vector<C> > vector_of_types; return 0; } I'm looking for a generic approach to do this. To me it seems like it should be possible by taking parts of the MPL lib, like mpl::push_back, and parts of the fusion lib, like fusion::for_each. Any ideas? Thanks ahead, Christian

On 3/15/07, Christian Henning <chhenning@gmail.com> wrote:
Hi there, subject probably sounds a bit strange but here is what I'm trying to accomplish.
The problem description goes like this:
using namespace boost; using namespace boost::fusion;
struct A; struct B; struct C;
int main() { typedef vector< A, B, C > types;
// how to translates typed into the following??
typedef vector< std::vector<A>, std::vector<B>, std::vector<C> > vector_of_types;
return 0; }
You probably want to look at the MPL transform metafunction: http://www.boost.org/libs/mpl/doc/refmanual/transform.html Chris

Thanks Chris, good hints. Here is my solution: #include <vector> #include <boost/mpl/assert.hpp> #include <boost/mpl/equal.hpp> #include <boost/mpl/list.hpp> #include <boost/mpl/transform.hpp> #include <boost/type_traits/add_pointer.hpp> //using namespace boost::fusion; using namespace boost; using namespace boost::mpl; template <typename T> struct add_vector { typedef std::vector<T> type; }; struct A; struct B; struct C; int main() { typedef list< A, B, C > types; typedef list< std::vector<A>, std::vector<B>, std::vector<C> > vector_of_types; typedef transform1< types, add_vector<_1> >::type result; BOOST_MPL_ASSERT(( equal<vector_of_types,result> )); return 0; }
participants (2)
-
Chris Weed
-
Christian Henning