Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) boost::make_tuple

 

boost::make_tuple is a Boost function that produces a boost::tuple. boost::make_tuple is similar to std::make_pair, except that boost::make_tuple produces a boost::tuple, where std::make_pair produces a std::pair.

 

#include <iostream>
#include <string>
 
#define BOOST_NO_CV_SPECIALIZATIONS
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
 
 
int main()
{
  boost::tuple<int,double,std::string> t = boost::make_tuple(123,3.14159,"Bilderbikkel");
 
  const int x1 = t.get<0>();
  const double x2 = t.get<1>();
  const std::string x3 = t.get<2>();
 
  boost::get<0>(t) = x1 + 1;
  boost::get<1>(t) = x2 + 1.0;
  boost::get<2>(t) = x3 + " was here";
 
  std::cout << t << std::endl;
}

 

Note the following:

  1. a boost::tuple is like an extended std::pair, with a maximum of ten elements
  2. similar to std::make_pair, for tuples you can use boost::make_tuple
  3. boost::get is used for getting and setting elements
  4. if you use C++ Builder 6.0, the #define is a workaround against the compile error tuple_basic.hpp: Multiple declaration for 'element<N,T>'

 

 

 

 

 

External links

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict