开发者

accessing members of boost:: tuple

开发者 https://www.devze.com 2023-02-02 06:25 出处:网络
I am trying to implement a vector like vector< boost::tuple<int,int,int> >day; I want to acess tuple\'s first element to check a condition.

I am trying to implement a vector like vector< boost::tuple<int,int,int> >day; I want to acess tuple's first element to check a condition. can someone please开发者_运维百科 tell me how to do it? I am new to boost. Thanks in advance.


#include <boost/tuple/tuple.hpp>
#include <iostream>
#include <vector>

int main()
{
    std::vector< boost::tuple<int, int, int> > v;
    v.push_back(boost::make_tuple(1, 2, 3));
    std::cout << boost::get<0>(v[0]) << std::endl;
    std::cout << boost::get<1>(v[0]) << std::endl;
    std::cout << boost::get<2>(v[0]) << std::endl;
}


First tupple has a set of types:
Edit (Fixed your post) But using abstract type here to demonstrate how it works better.

std::vector<boost::tuple<A, B, C> >   day;

// Load data into day;

Now you can extract that parts of the tupple using the get method.

A&   aPart = day[0].get<0>();
B&   bPart = day[0].get<1>();
C&   cPart = day[0].get<2>();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号