CopperSpice API  1.7.2
QPair< T1, T2 > Class Template Reference

Stores a pair of items. More...

Public Typedefs

using first_type = T1
 
using second_type = T2
 

Public Methods

 QPair ()
 
 QPair (const QPair &other) = default
 
 QPair (const T1 &value1, const T2 &value2)
 
 QPair (QPair &&other) = default
 
QPair< T1, T2 > & operator= (const QPair< T1, T2 > &other) = default
 
QPair< T1, T2 > & operator= (QPair< T1, T2 > &&other) = default
 
void swap (QPair &other)
 

Public Members

T1 first
 
T2 second
 

Related Functions

These are not member functions

bool operator!= (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
bool operator< (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
QDataStreamoperator<< (QDataStream &out, const QPair< T1, T2 > &pair)
 
bool operator<= (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
bool operator== (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
bool operator> (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
bool operator>= (const QPair< T1, T2 > &p1, const QPair< T1, T2 > &p2)
 
QDataStreamoperator>> (QDataStream &in, QPair< T1, T2 > &pair)
 
uint qHash (const QPair< T1, T2 > &key)
 
QPair< T1, T2 > qMakePair (const T1 &value1, const T2 &value2)
 

Detailed Description

template<class T1, class T2>
class QPair< T1, T2 >

The QPair class is a class which stores a pair of items. It stores one value of type T1 and one value of type T2. QPair can be used as a return value for a method which returns two values or as the value type of a generic container.

The following is an example of a QPair which stores a QString and a double value.

The components are accessible as public data members called first and second.

pair.first = "pi";
pair.second = 3.14159265358979323846;

Constraints on type T

The QPair<T1, T1> should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.

Member Typedef Documentation

template<class T1 , class T2 >
QPair< T1, T2 >::first_type

The data type of the first element in the pair T1.

See also
first
template<class T1 , class T2 >
QPair< T1, T2 >::second_type

The data type of the second element in the pair T2.

See also
second

Constructor & Destructor Documentation

template<class T1 , class T2 >
QPair< T1, T2 >::QPair ( )
inline

Constructs an empty QPair.

template<class T1 , class T2 >
QPair< T1, T2 >::QPair ( const T1 &  value1,
const T2 &  value2 
)
inline

Constructs a pair and initializes the first element with value1 and the second element with value2.

See also
qMakePair()
template<class T1 , class T2 >
QPair< T1, T2 >::QPair ( const QPair< T1, T2 > &  other)
default

Copy constructs a new QPair from other.

template<class T1 , class T2 >
QPair< T1, T2 >::QPair ( QPair< T1, T2 > &&  other)
default

Move constructs a new QPair from other.

Method Documentation

template<class T1 , class T2 >
QPair< T1, T2 > & QPair< T1, T2 >::operator= ( const QPair< T1, T2 > &  other)
default

Copy assigns from other and returns a reference to this object.

template<class T1 , class T2 >
QPair< T1, T2 > & QPair< T1, T2 >::operator= ( QPair< T1, T2 > &&  other)
default

Move assigns from other and returns a reference to this object.

template<class T1 , class T2 >
void QPair< T1, T2 >::swap ( QPair< T1, T2 > &  other)

Swaps this pair with other.

Friends And Related Function Documentation

bool operator!= ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is not equal to p2, otherwise returns false. Two pairs compare as not equal if their first data members are not equal or if their second data members are not equal.

This method requires the T1 and T2 types to have an implementation of operator==().

bool operator< ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is less than p2, otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This method requires the T1 and T2 types to have an implementation of operator<().

QDataStream & operator<< ( QDataStream out,
const QPair< T1, T2 > &  pair 
)
related

Writes the pair pair to stream out. This method requires the T1 and T2 types to implement operator<<().

Refer to Serializing Data Types for additional information.

bool operator<= ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is less than or equal to p2, otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This method requires the T1 and T2 types to have an implementation of operator<().

bool operator== ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is equal to p2, otherwise returns false. Two pairs compare equal if their first data members compare equal and if their second data members compare equal.

This method requires the T1 and T2 types to have an implementation of operator==().

bool operator> ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is greater than p2, otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This method requires the T1 and T2 types to have an implementation of operator<().

bool operator>= ( const QPair< T1, T2 > &  p1,
const QPair< T1, T2 > &  p2 
)
related

Returns true if p1 is greater than or equal to p2, otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This method requires the T1 and T2 types to have an implementation of operator<().

QDataStream & operator>> ( QDataStream in,
QPair< T1, T2 > &  pair 
)
related

Reads a pair from stream in into pair. This method requires the T1 and T2 types to implement operator>>().

Refer to Serializing Data Types for additional information.

uint qHash ( const QPair< T1, T2 > &  key)
related

Returns the hash value for key. Types T1 and T2 must be supported by qHash().

QPair< T1, T2 > qMakePair ( const T1 &  value1,
const T2 &  value2 
)
related

Returns a QPair<T1, T2> that contains value1 and value2.

list.append(qMakePair(66, 3.14159));

This is equivalent to QPair<T1, T2>(value1, value2), but usually requires less typing.

Member Data Documentation

template<class T1 , class T2 >
QPair< T1, T2 >::first

The first element in a given pair.

template<class T1 , class T2 >
QPair< T1, T2 >::second

The second element in a given pair.