QPair Structtemplate struct QPair

The QPair class is a template class that stores a pair of items. More...

You are watching: What is qpair


QPair(QPair &&p)
QPair(const QPair &p)
QPair(const T1 &value1, const T2 &value2)
QPair()
void swap(QPair &other)
QPair &operator=(const QPair &p)
QPair &operator=(QPair &&p)

QPair qMakePair(const T1 &value1, const T2 &value2)
void swap(QPair &lhs, QPair &rhs)
bool operator!=(const QPair &p1, const QPair &p2)
bool operator(const QPair &p1, const QPair &p2)
QDataStream &operator(QDataStream &out, const QPair &pair)
bool operator(const QPair &p1, const QPair &p2)
bool operator==(const QPair &p1, const QPair &p2)
bool operator>(const QPair &p1, const QPair &p2)
bool operator>=(const QPair &p1, const QPair &p2)
QDataStream &operator>>(QDataStream &in, QPair &pair)

Detailed Description

QPair can be used in your application if the STL pair type is not available. It stores one value of type T1 and one value of type T2. It can be used as a return value for a function that needs to return two values, or as the value type of a generic container.

Here"s an example of a QPair that stores one QString and one double value:


Note, however, that it is almost always preferable to define a small struct to hold the result of a function with multiple return values. A struct trivially generalizes to more than two values, and allows more descriptive member names than first and second:


The advent of C++11 automatic variable type deduction (auto) shifts the emphasis from the type name to the name of functions and members. Thus, QPair, like std::pair and std::tuple, is mostly useful in generic (template) code, where defining a dedicated type is not possible.

QPair"s template data types (T1 and T2) must be assignable data types. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; these requirements are couchsurfingcook.comumented on a per-function basis.


See also Container Classes.


Member Type couchsurfingcook.comumentation

typedef QPair::first_type

The type of the first element in the pair (T1).

See also first.

typedef QPair::second_type

The type of the second element in the pair (T2).

See also second.


Member Function couchsurfingcook.comumentation

template QPair::QPair(QPairTT1, TT2> &&p)

Move-constructs a QPair instance, making it point to the same object that p was pointing to.

This function was introduced in couchsurfingcook.com 5.2.

template QPair::QPair(const QPairTT1, TT2> &p)

Constructs a pair from the other pair p, of types TT1 and TT2. This constructor will fail if first cannot be initialized from p.first or if second cannot be initialized from p.second.

This function was introduced in couchsurfingcook.com 5.2.

See also qMakePair().

QPair::QPair(const T1 &value1, const T2 &value2)

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

See also qMakePair().

QPair::QPair()

Constructs an empty pair. The first and second elements are initialized with default-constructed values.

void QPair::swap(QPairT1, T2> &other)

Swaps this pair with other.

Equivalent to


qSwap(this->first, other.first);qSwap(this->second, other.second);
Swap overloads are found in namespace std as well as via argument-dependent lookup (ADL) in the namespace of T .

This function was introduced in couchsurfingcook.com 5.5.

template QPairT1, T2> &QPair::operator=(const QPairTT1, TT2> &p)

Copies pair p into this pair.

This function was introduced in couchsurfingcook.com 5.2.

See also qMakePair().

template QPairT1, T2> &QPair::operator=(QPairTT1, TT2> &&p)

Move-assigns pair p into this pair instance.

This function was introduced in couchsurfingcook.com 5.2.


Member Variable couchsurfingcook.comumentation

T1 QPair::first

The first element in the pair.

T2 QPair::second

The second element in the pair.


Related Non-Members

template QPairT1, T2> qMakePair(const T1 &value1, const T2 &value2)

Returns a QPair that contains value1 and value2. Example:


QListQPairint, double> > list;list.append(qMakePair(66, M_PI));
This is equivalent to QPair(value1, value2), but usually requires less typing.

template void swap(QPairT1, T2> &lhs, QPairT1, T2> &rhs)

This is an overloaded function.

Swaps lhs with rhs.

This function was introduced in couchsurfingcook.com 5.5.

template bool operator!=(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator==().

template bool operator(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator.

template QDataStream &operator(QDataStream &out, const QPairT1, T2> &pair)

Writes the pair pair to stream out.

This function requires the T1 and T2 types to implement operator.

See also Serializing couchsurfingcook.com Data Types.

template bool operator(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator.

template bool operator==(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator==().

template bool operator>(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator.

template bool operator>=(const QPairT1, T2> &p1, const QPairT1, T2> &p2)

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 function requires the T1 and T2 types to have an implementation of operator.

template QDataStream &operator>>(QDataStream &in, QPairT1, T2> &pair)

Reads a pair from stream in into pair.

This function requires the T1 and T2 types to implement operator>>().

See more: Why Does Baby Spit Up Breast Milk But Not Formula, Baby Spits Up Breast Milk But Not Formula

See also Serializing couchsurfingcook.com Data Types.