libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Pair< A, B > Class Template Reference

Typed pair container wrapping std::pair. More...

#include <pair.h>

Public Types

using FirstType = A
 Type of the first element.
 
using SecondType = B
 Type of the second element.
 

Public Member Functions

 Pair ()=default
 Default constructor. Value-initializes both elements.
 
 Pair (const A &a, const B &b)
 Constructs a pair from two values.
 
 Pair (A &&a, B &&b)
 Constructs a pair by moving two values.
 
 Pair (const std::pair< A, B > &p)
 Constructs from an existing std::pair.
 
 Pair (std::pair< A, B > &&p)
 Constructs from an existing std::pair (move overload).
 
 Pair (const Pair &other)=default
 Copy constructor.
 
 Pair (Pair &&other) noexcept=default
 Move constructor.
 
 ~Pair ()=default
 Destructor.
 
Pairoperator= (const Pair &other)=default
 Copy assignment operator.
 
Pairoperator= (Pair &&other) noexcept=default
 Move assignment operator.
 
Afirst ()
 Returns a mutable reference to the first element.
 
const Afirst () const
 Returns a const reference to the first element.
 
Bsecond ()
 Returns a mutable reference to the second element.
 
const Bsecond () const
 Returns a const reference to the second element.
 
void setFirst (const A &a)
 Sets the first element.
 
void setSecond (const B &b)
 Sets the second element.
 
const std::pair< A, B > & toStdPair () const
 Returns a const reference to the underlying std::pair.
 
void swap (Pair &other) noexcept
 Swaps contents with another pair.
 
template<std::size_t I>
autoget () &
 Structured bindings support: element access by index.
 
template<std::size_t I>
const autoget () const &
 Structured bindings support: element access by index.
 
template<std::size_t I>
auto && get () &&
 Structured bindings support: element access by index.
 

Static Public Member Functions

static Pair make (A a, B b)
 Factory function to create a Pair.
 

Friends

bool operator== (const Pair &lhs, const Pair &rhs)
 Returns true if both pairs have identical contents.
 
bool operator!= (const Pair &lhs, const Pair &rhs)
 Returns true if the pairs differ.
 
bool operator< (const Pair &lhs, const Pair &rhs)
 Lexicographic less-than comparison.
 

Detailed Description

template<typename A, typename B>
class Pair< A, B >

Typed pair container wrapping std::pair.

Provides a Qt-inspired API over std::pair with consistent naming conventions matching the rest of libpromeki. Simple value type — no PROMEKI_SHARED_FINAL.

Supports structured bindings via std::tuple_size/std::tuple_element specializations.

Template Parameters
AFirst element type.
BSecond element type.

Constructor & Destructor Documentation

◆ Pair() [1/4]

template<typename A , typename B >
Pair< A, B >::Pair ( const A a,
const B b 
)
inline

Constructs a pair from two values.

Parameters
aFirst element.
bSecond element.

◆ Pair() [2/4]

template<typename A , typename B >
Pair< A, B >::Pair ( A &&  a,
B &&  b 
)
inline

Constructs a pair by moving two values.

Parameters
aFirst element (moved).
bSecond element (moved).

◆ Pair() [3/4]

template<typename A , typename B >
Pair< A, B >::Pair ( const std::pair< A, B > &  p)
inline

Constructs from an existing std::pair.

Parameters
pThe std::pair to copy from.

◆ Pair() [4/4]

template<typename A , typename B >
Pair< A, B >::Pair ( std::pair< A, B > &&  p)
inline

Constructs from an existing std::pair (move overload).

Parameters
pThe std::pair to move from.

Member Function Documentation

◆ get() [1/3]

template<typename A , typename B >
template<std::size_t I>
auto & Pair< A, B >::get ( ) &
inline

Structured bindings support: element access by index.

Template Parameters
IElement index (0 for first, 1 for second).
Returns
Reference to the requested element.

◆ get() [2/3]

template<typename A , typename B >
template<std::size_t I>
auto && Pair< A, B >::get ( ) &&
inline

Structured bindings support: element access by index.

Template Parameters
IElement index (0 for first, 1 for second).
Returns
Reference to the requested element.

◆ get() [3/3]

template<typename A , typename B >
template<std::size_t I>
const auto & Pair< A, B >::get ( ) const &
inline

Structured bindings support: element access by index.

Template Parameters
IElement index (0 for first, 1 for second).
Returns
Reference to the requested element.

◆ make()

template<typename A , typename B >
static Pair Pair< A, B >::make ( A  a,
B  b 
)
inlinestatic

Factory function to create a Pair.

Parameters
aFirst element.
bSecond element.
Returns
A new Pair.

◆ setFirst()

template<typename A , typename B >
void Pair< A, B >::setFirst ( const A a)
inline

Sets the first element.

Parameters
aThe new value for the first element.

◆ setSecond()

template<typename A , typename B >
void Pair< A, B >::setSecond ( const B b)
inline

Sets the second element.

Parameters
bThe new value for the second element.

◆ swap()

template<typename A , typename B >
void Pair< A, B >::swap ( Pair< A, B > &  other)
inlinenoexcept

Swaps contents with another pair.

Parameters
otherThe pair to swap with.

◆ toStdPair()

template<typename A , typename B >
const std::pair< A, B > & Pair< A, B >::toStdPair ( ) const
inline

Returns a const reference to the underlying std::pair.

Returns
The wrapped std::pair.

The documentation for this class was generated from the following file: