(C++) StdTupleExample1

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) StdTupleExample1

 

C++11STLQt
CreatorLubuntu

 

std::tuple example 1 is a std::tuple example.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppStdTupleExample1/CppStdTupleExample1.pro

 


include(../../ConsoleApplication.pri) #Or use the code below # QT += core # QT += gui # CONFIG   += console # CONFIG   -= app_bundle # TEMPLATE = app # CONFIG(release, debug|release) { #   DEFINES += NDEBUG NTRACE_BILDERBIKKEL # } # QMAKE_CXXFLAGS += -std=c++1y -Wall -Wextra -Weffc++ # unix { #   QMAKE_CXXFLAGS += -Werror # } SOURCES += main.cpp

 

 

 

 

 

./CppStdTupleExample1/main.cpp

 


#include <cassert> #include <string> #include <tuple> #include <typeinfo> int main() {   typedef std::tuple<int,double,std::string> Tuple;   static_assert(std::tuple_size<Tuple>::value == 3,"Tuple has size 3");   static_assert(std::is_same<std::tuple_element<0,Tuple>::type,int>(),"First element is int");   static_assert(std::is_same<std::tuple_element<1,Tuple>::type,double>(),"Second element is double");   static_assert(std::is_same<std::tuple_element<2,Tuple>::type,std::string>(),"Third element is std::string");   Tuple t = std::make_tuple(123,3.14159,"Bilderbikkel");   const int x1 = std::get<0>(t);   const double x2 = std::get<1>(t);   const std::string x3 = std::get<2>(t);   std::get<0>(t) = x1 + 1;   std::get<1>(t) = x2 + 1.0;   std::get<2>(t) = x3 + " was here";   assert(std::get<0>(t) == 124);   assert(std::get<1>(t) == 4.14159);   assert(std::get<2>(t) == "Bilderbikkel was here"); }