Home C++ Decisions Loops Input/Output Functions Stack and Heap References Arrays Searching and Sorting Recursion Pointers Character and Strings Structures Classes Inheritance Exceptions Templatess STL Modern C++ Misc Books ----

tuple


Contents

Introduction

A tuple is similar to a structure. The advantage is we can create the tuple on the fly wihtout creating a separate declaration. It is similar to a pair but can contain more number of elements.The elements can be of different types and once declared the size is fixed.

File: tuple1.cpp

Exercise

1) Plug the below code in https://cppinsights.io/ to see the warning. Convert the function to use "constexpr" and get rid of the warning. Observe the constant for the array dimension.

File: const_ex1.cpp
#include <iostream>


int sum( int x1, int y1 )
{
    return x1 * y1 ;
}

int main()
{

    int arr[  sum(3, 3) ] ;


    return 0;
}

















































Solutions

1)

File: const_ex1s.cpp