Boost logo

Boost Users :

From: Hicham Mouline (hicham_at_[hidden])
Date: 2008-06-01 13:38:47


1) I now managed to produce the cartesian product of 3 mpl
sequences applying my custom metafunction to the resulting triplets,
however it takes like 40seconds to compile. I doubt this is the optimal
way to write the cartesian product metafunction. (code compiles as-is,

2) By the way, cartesian product hasn't been deemed generic enough to be
in the MPL?

3) what would be the equivalent of mpl::pair for 3 or more? boost::tuple or

Your help is very appreciated, thank you,

#include <iostream>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/vector/vector0.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/size.hpp>
#include <boost/variant.hpp>
template <typename inter, typename extra, typename integ> class curve {};

template <typename inter, typename extra, typename integ>
struct curve_metafunction {
        typedef curve<inter,extra,integ> type;

template<typename T> struct pair_with : boost::mpl::pair<T,boost::mpl::_>

template<typename pair> struct triple_with :
  curve_metafunction < typename pair::first,
                       typename pair::second,

template<typename Sequence1,typename Sequence2>
struct sequence_product :

template<typename SequencePair, typename Sequence>
struct seq_seqpair_product :

template<typename Sequence1,typename Sequence2,typename Sequence3>
struct seq_product : seq_seqpair_product<
sequence_product<Sequence1,Sequence2>::type, Sequence3 >

typedef boost::mpl::vector<constant, linear, polynomial, cubic_spline>
typedef interpolator_types extrapolator_types;
typedef boost::mpl::vector<simpson> integrator_types;

typedef seq_product<interpolator_types,
extrapolator_types,integrator_types>::type curve_types;

struct type_printer {
 template <typename T> void operator()( T )
  std::cout<< typeid(T).name() <<std::endl;

int main()
        std::cout<< boost::mpl::size<curve_types>::type::value <<std::endl;
        boost::mpl::for_each<curve_types>( type_printer() );

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Steven Watanabe
Sent: 31 May 2008 20:51
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] variant<> number of template arguments


Hicham Mouline wrote:
> It seems make_variant_over is also limited by BOOST_VARIANT_LIMIT_TYPES.
> This macro is 20 on 2 platforms (linux-i386-gcc-4.1.2-boost-1.34.1 and
> win-i386-vs2005- boost-1.35.0)
> <snip>
> If I add type19, making the mpc vector have 21 types, compilation fails...

The limit of variant and the limit of mpl::vector happen to be the same.
For more types, try using the numbered form of mpl vector which can
handle up to 50 arguments.

#include <boost/mpl/vector/vector30.hpp>

typedef boost::mpl::vector21<...> types;

In Christ,
Steven Watanabe

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at