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>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With