std::tuple_element() and std::tuple_size() in C++ with Examples Last Updated : 10 Jul, 2021 Comments Improve Suggest changes Like Article Like Report A tuple is an object that can hold a number of elements. The elements can be different data types. The elements of tuples are initialized as arguments in the order in which they will be accessed. The functions- tuple_element() and tuple_size() are only defined for elements using tuple_like interface. tuple_element():The C++ function tuple_element(array) provides compile-type indexed access to the type of the elements of the array using a tuple-like interface. Syntax- template< size_t I, class T, size_t N > struct tuple_element<I, array<T, N> >; Parameters- T − type for which the tuple element is obtained. I − index of the element. N − the size of the array. Example-Below is the C++ program to implement the concept of tuple_element(array)- C++ // C++ program to implement // the above approach #include <array> #include <iostream> #include <tuple> #include <type_traits> using namespace std; // Driver code int main() { // Define array array<int, 3> data{ 3, 5, 10 }; // Type of element at index 0 using type = std::tuple_element<0, decltype(data)>::type; // Compare type with int // returns true cout << std::is_same<type, int>::value << '\n'; // Compare type with char // returns false cout << std::is_same<type, char>::value << '\n'; } Output1 0 tuple_size():The C++ function tuple_size(array) returns the total number of elements present in the array. Syntax- template< class T, size_t N > class tuple_size< array<T, N> > : integral_constant<size_t, N> { }; Parameters- T − type for which the tuple size is obtained. Example-Below is the C++ program to implement the concept of tuple_size()- C++ // C++ program to implement // the above approach #include <array> #include <iostream> using namespace std; // Driver code int main() { // Array of size 6 array<int, 6> a; // Find size using tuple_size cout << tuple_size<decltype(a)>::value; return 0; } Output6 Comment More infoAdvertise with us Next Article std::tuple_element() and std::tuple_size() in C++ with Examples analystayush Follow Improve Article Tags : C++ CPP-Functions cpp-tuple Practice Tags : CPP Similar Reads std::is_constructible template in C++ with Examples The std::is_constructible template of C++ STL is present in the <type_traits> header file. The std::is_constructible template of C++ STL is used to check whether the given type T is constructible type with the set of arguments or not. It return the boolean value true if T is of constructible t 2 min read not1 and not2 function templates in C++ STL with Examples These are functions which takes unary and binary function object(functors) and returns complement of that function objects. It can be usable in competitive programming to get complement of binary and unary functions. These functions are very useful when writing code for complement function is harder 3 min read Set of Tuples in C++ with Examples What is a tuple?A tuple is an object that can hold a number of elements. The elements can be of different data types. The elements of tuples are initialized as arguments in the order in which they will be accessed. Operations on tuple:1. get(): get() is used to access the tuple values and modify the 4 min read unordered set of tuples in C++ with Examples What is a tuple? A tuple in C++ is an object which is used to group elements together. In a tuple, elements can be of the same data type or different data types. The elements of tuples are initialized as in the order in which they will be accessed. Functions associated with a tuple: 1. make_tuple(): 6 min read Map of list and forward_list in C++ STL with Examples Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. Lists are sequence containers that allow non-contiguous memory allocation. As compared to vector, the list has slow traversal, 5 min read Multiset of Tuples in C++ with Examples What is a tuple? A tuple in C++ is an object which binds a group of elements together. The elements can be similar as well as different data types. The elements of tuples are initialized as in the order in which they will be accessed. Syntax: tuple<data_type1, data_type2, dataType3, ....> myTu 5 min read Deque of Tuples in C++ with Examples What is deque? In C++, a deque is a sequence container and it is also known by the name, double-ended queue. As the name implies, a deque allows insertion and deletion from both ends. Although a deque is similar to a vector, deques are more efficient compared to vectors. In vectors, contiguous stora 8 min read Set of List and Forward List in C++ with examples Sets Sets are a type of associative container in which each element has to be unique because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, though it is possible to remove and add the modified value of that element. Functions used wit 4 min read 2D Vector of Tuples in C++ with Examples What is Vector? In C++, a vector is similar to dynamic arrays with the ability to resize itself automatically. Vector elements are stored in contiguous memory locations so that they can be accessed and traversed using iterators. Functions associated with a vector: begin(): Returns an iterator pointi 6 min read multiset size() in C++ STL with Examples The multiset::size() is a built-in function in C++ STL which returns the number of elements in the multiset container. Syntax: multiset_name.size() Parameters: The function does not accept any parameters. Return Value: The function returns the number of elements in the multiset container. Below prog 2 min read Like