Question

Normally I would access a regular tuple element (say 0) in the following way

mytuple->get<0>();

However if the tuple is of the type boost::fusion::tuple how do I access the 0th element

More Detail

I have something like this

typedef boost::fusion::tuple<double,double,double,std::string,double,double,int, 
                            double,double,double,double,int,  
                            double,double,double,double,double,
                            double,double,double,double,double,
                            double,double,double,double> tuple_def; 

typedef boost::shared_ptr<tuple_def> my_tuple_def;

Now I am using it as follows

shared_tuple_def btuple = boost::make_shared<tuple_def>(boost::fusion::make_tuple(323,0,0,"A",0,0,0,
                                                                                  0,0,0,0,0,
                                                                                  0,0,0,0,0,
                                                                                  0,0,0,0,0,
                                                                                  0,0,0,0));

How do I access the 0th element which is 323 ?

Was it helpful?

Solution 2

You could use boost::fusion::get

int main()
{
    shared_tuple_def btuple = boost::make_shared<tuple_def>
    (
        boost::fusion::make_tuple
        (
            323, 0, 0, "A", 0, 0, 0,
            0, 0, 0, 0, 0,
            0, 0, 0, 0, 0,
            0, 0, 0, 0, 0,
            0, 0, 0, 0
        )
    );
    std::cout << boost::fusion::get<0>(*btuple) << std::endl;
}

OTHER TIPS

You can use boost::fusion::get or boost::fusion::at:

#define FUSION_MAX_VECTOR_SIZE 26
#include <string>
#include <iostream>
#include <boost/fusion/tuple.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/mpl/int.hpp>
typedef boost::fusion::tuple<double,double,double,std::string,double,double,int, 
                            double,double,double,double,int,  
                            double,double,double,double,double,
                            double,double,double,double,double,
                            double,double,double,double> tuple_def; 

typedef boost::shared_ptr<tuple_def> shared_tuple_def;

int main() {
    shared_tuple_def btuple =
        boost::make_shared<tuple_def>(
            boost::fusion::make_tuple(
                323,0,0,"A",0,0,0,
                0,0,0,0,0,
                0,0,0,0,0,
                0,0,0,0,0,
                0,0,0,0));

    std::cout << boost::fusion::get<0>(*btuple) << "\n";
    std::cout << boost::fusion::at<boost::mpl::int_<0> >(*btuple) << "\n";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top