combining mpl sequences

Hi, I have a templatized mpl-vector template< class T > class containers : public mpl::vector< std::vector< T > , std::list< T > , std::deque< T >
{ };
and a mpl-vector holding some types: typedef mpl::vector< float , double , long double >::type my_types; Is there a simple way to build a mpl vector which contains the elements of the first vector with template arguments of the second vector, hence mpl:vector< std::vector< float > , std::vector< double > , std::vector< long double > , std::list< float > , std::list< double > , std::list< long double > , std::deque< float > , std::deque< double > , std::deque< long double >
I can do this manually with mpl::insert_range typedef mpl::insert_range< mpl::vector0<> , mpl::end< mpl::vector0<> >::type , containers< mpl::at< my_types , mpl::int_<0> >::type >
::type first;
typedef mpl::insert_range< first , mpl::end< first >::type , containers< mpl::at< my_types , mpl::int_<1> >::type >
::type second;
typedef mpl::insert_range< second , mpl::end< second >::type , containers< mpl::at< my_types , mpl::int_<2> >::type >
::type all_containers;
But this way is not very elegant. Does some has any hints how to do this automatically? Best regards, Karsten

On Sun, Sep 5, 2010 at 3:10 AM, Karsten Ahnert
Hi,
I have a templatized mpl-vector
template< class T > class containers : public mpl::vector< std::vector< T > , std::list< T > , std::deque< T >
{ };
and a mpl-vector holding some types:
typedef mpl::vector< float , double , long double >::type my_types;
Is there a simple way to build a mpl vector which contains the elements of the first vector with template arguments of the second vector, hence
mpl:vector< std::vector< float > , std::vector< double > , std::vector< long double > , std::list< float > , std::list< double > , std::list< long double > , std::deque< float > , std::deque< double > , std::deque< long double >
I can do this manually with mpl::insert_range
typedef mpl::insert_range< mpl::vector0<> , mpl::end< mpl::vector0<> >::type , containers< mpl::at< my_types , mpl::int_<0> >::type >
::type first;
typedef mpl::insert_range< first , mpl::end< first >::type , containers< mpl::at< my_types , mpl::int_<1> >::type >
::type second;
typedef mpl::insert_range< second , mpl::end< second >::type , containers< mpl::at< my_types , mpl::int_<2> >::type >
::type all_containers;
But this way is not very elegant. Does some has any hints how to do this automatically?
Try:
typedef copy

Try:
typedef copy
all_containers;
copy was a good hint:). I only had to introduce a custom inserter: template< class T > class containers : public mpl::vector< std::vector< T > , std::list< T > , std::deque< T >
{ };
typedef mpl::vector< float , double , long double >::type my_types; typedef mpl::copy < my_types , mpl::inserter < mpl::vector0<> , mpl::insert_range < mpl::_1 , mpl::end< mpl::_1 > , containers< mpl::_2 > >
::type all_containers;
which solved my problem. Best regards, Karsten

At Sun, 05 Sep 2010 12:10:17 +0200, Karsten Ahnert wrote:
Hi,
I have a templatized mpl-vector
template< class T > class containers : public mpl::vector< std::vector< T > , std::list< T > , std::deque< T >
{ };
and a mpl-vector holding some types:
typedef mpl::vector< float , double , long double >::type my_types;
Is there a simple way to build a mpl vector which contains the elements of the first vector with template arguments of the second vector, hence
mpl:vector< std::vector< float > , std::vector< double > , std::vector< long double > , std::list< float > , std::list< double > , std::list< long double > , std::deque< float > , std::deque< double > , std::deque< long double >
I can do this manually with mpl::insert_range
typedef mpl::insert_range< mpl::vector0<> , mpl::end< mpl::vector0<> >::type , containers< mpl::at< my_types , mpl::int_<0> >::type >
::type first;
typedef mpl::insert_range< first , mpl::end< first >::type , containers< mpl::at< my_types , mpl::int_<1> >::type >
::type second;
typedef mpl::insert_range< second , mpl::end< second >::type , containers< mpl::at< my_types , mpl::int_<2> >::type >
::type all_containers;
But this way is not very elegant. Does some has any hints how to do this automatically?
You're already most of the way there. If you can break it down into
three similar steps, you can write a single step as a metafunction:
template
{}; Then you can fold that step across your types: typedef typename mpl::fold< my_types, mpl::vector<>, stepmpl::_,mpl::_ >::type all_containers; This produces a sequence with a different ordering than the one in your "hence" clause, but it's the same ordering as you'd get in your own all_containers above. HTH, -- Dave Abrahams BoostPro Computing http://www.boostpro.com

You're already most of the way there. If you can break it down into three similar steps, you can write a single step as a metafunction:
template
struct step : mpl::insert_range< PrevResult , mpl::end< PrevResult >::type , containers< MyType > {};
Then you can fold that step across your types:
typedef typename mpl::fold< my_types, mpl::vector<>, stepmpl::_,mpl::_ >::type all_containers;
This produces a sequence with a different ordering than the one in your "hence" clause, but it's the same ordering as you'd get in your own all_containers above.
Thanks, this starts to become fun. I also found another way with copy and inserters. Cheers, Karsten
participants (3)
-
Cory Nelson
-
David Abrahams
-
Karsten Ahnert