Easy way to make vector triplet in CPP

What would be an easy way to construct a vector triplet of ints in CPP?

i.e instead of a pair of 2 ints ,

std::vector<std::pair<int, int> > vec;

I want 3 int's tied together as one element of the vector.

I realized one way would be to make 2 sub-nested pairs, but this method gets messy. I am not aware of all the details of CPP, therefore please recommend an easier way if available. Thank you.


No need to over-engineer.

struct Triplet
  int  one_, two_, three_;

vector<Triplet> triplets;

std::vector<std::tuple<int,int,int>> myvec;

Check out boost tuple http://www.boost.org/doc/libs/1_49_0/libs/tuple/doc/tuple_users_guide.html

You can easily create Pairs, triples, quadruples, up to n-uples!

In C++11, there is std::array, see here. In C++03, I would probably define a struct of 3 ints and make a vector of those.

Need Your Help

Alternative to "PDO::lastInsertId" / "mysql_insert_id"

php mysql auto-increment lastinsertid mysql-insert-id

I always hear that using "lastInsertId" (or mysql_insert_id() if you're not using PDO) is evil. In case of triggers it obviously is, because it could return something that's totally not the last ID...