PAIR IN C++Pair is a term used to combine two values, which may be of various data kinds. Pair offers a technique to keep two disparate objects together in storage. Essentially, we use it to store tuples. A pair container is a straightforward container that is specified in the header and contains two data elements or objects.
Syntax for pair in C++: Example: A program for pair in C++; Output 200 J Pair Initialization:A pair can also be initialized. You can use the following syntax to initialize pair. Syntax: Various approaches to pair initialization:The make pair() function can also be used to initialize a pair. Pair declaration may also use the following syntax: Example: Output JavaTpoint 2.23 Note: If the pair's first value is not initialized, it is initialized automatically.Example: Output 00 Member Functions1) make_pair(): Without explicitly defining the types, a value pair can be created using this template function. Syntax: Example: Output 200 J JavaTpoint 1.23 JavaTpoint is super 4.56 2) swap: The contents of two pair objects are switched with the use of this function. Pairs must belong to the same category. Syntax: Example: Output content before swapping: Contents of pair1 = P 1Contents of pair2 = Q 2 content after swapping: Contents of pair1 = Q 2Contents of pair2 = P 1 3) tie(): This tie() method works the same as tuples work. To unpack the tuple (or pair in this case) values into independent variables, it produces a tuple of lvalue pointers to its parameters. Here are two variations of the tie, one with and one without "ignore", just like in tuples. The keyword "ignore" prevents a certain tuple element from being unpacked. Pairs only have two arguments, but tuples can have numerous arguments. Therefore, unpacking needs to be dealt with explicitly in the case of pairs. Syntax: Example: Output 10 12 16 12 16 18 p |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India