Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Make_tupleExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppMake_tupleExample1/CppMake_tupleExample1.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

#
#
# Type of compile
#
#

CONFIG(release, debug|release) {
  DEFINES += NDEBUG NTRACE_BILDERBIKKEL
}

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++

unix {
  QMAKE_CXXFLAGS += -Werror
}

#
#
# Boost
#
#

win32 {
  INCLUDEPATH += \
    ../../Libraries/boost_1_54_0
}

 

 

 

 

 

./CppMake_tupleExample1/main.cpp

 

#include <cassert>
#include <iostream>
#include <string>
#include <tuple>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
#pragma GCC diagnostic pop


int main()
{
  //C++11 std::make_tuple
  {
    std::tuple<int,double,std::string> t {
      std::make_tuple(1,1.1,"x")
    };

    assert(std::get<0>(t) == 1);
    assert(std::get<1>(t) == 1.1);
    assert(std::get<2>(t) == "x");

    std::get<0>(t) += 1;
    std::get<1>(t) += 1.1;
    std::get<2>(t) += "x";

    assert(std::get<0>(t) == 2);
    assert(std::get<1>(t) == 2.2);
    assert(std::get<2>(t) == "xx");

    //std::cout << t << '\n';
  }
  //Boost.Tuple
  {
    boost::tuple<int,double,std::string> t {
      boost::tuples::make_tuple(1,1.1,"x")
    };

    assert(t.get<0>() == 1);
    assert(t.get<1>() == 1.1);
    assert(t.get<2>() == "x");

    t.get<0>() += 1;
    t.get<1>() += 1.1;
    t.get<2>() += "x";

    assert(t.get<0>() == 2);
    assert(t.get<1>() == 2.2);
    assert(t.get<2>() == "xx");

    std::cout << t << '\n';
  }
}

/* Screen output

(2 2.2 xx)
Press <RETURN> to close this window...

*/

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml