Search code examples
c++boosttuplesboost-fusion

Accessing 0th element from boost::fusion::tuple


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 ?


Solution

  • 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;
    }