SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Pair< T1, T2 > Class Template Reference

A simple container for storing two values as a pair. More...

#include <Pair.hpp>

Public Member Functions

 Pair ()=default
 Default constructor.
 Pair (const Pair &other)=default
 Copy constructor.
 Pair (const T1 &first, const T2 &second)
 Constructor with initial values.
 Pair (Pair &&other) noexcept
 Move constructor.
Pairoperator= (const Pair &other)=default
 Copy assignment operator.
Pairoperator= (Pair &&other) noexcept
 Move assignment operator.
void swap (Pair &other) noexcept
 Swaps the contents of this Pair with another Pair.

Public Attributes

T1 first
T2 second

Detailed Description

template<typename T1, typename T2>
class Sleak::Pair< T1, T2 >

A simple container for storing two values as a pair.

This class provides a way to store two values together as a single unit. It is similar to std::pair and can be used in similar situations, such as storing key-value pairs, coordinates, or any other data that needs to be grouped together.

Example Use Cases:

  • Storing key-value pairs in a map or hash table.
  • Representing coordinates (x, y) or (latitude, longitude).
  • Returning multiple values from a function.

Implementation Details:

  • Stores two values of potentially different types.
  • Provides access to the values through first and second members.
  • Implements comparison operators for lexicographical ordering.
  • Offers a makePair function for convenient creation of Pair objects.

Definition at line 30 of file Pair.hpp.

Constructor & Destructor Documentation

◆ Pair() [1/4]

template<typename T1, typename T2>
Sleak::Pair< T1, T2 >::Pair ( )
default

Default constructor.

◆ Pair() [2/4]

template<typename T1, typename T2>
Sleak::Pair< T1, T2 >::Pair ( const T1 & first,
const T2 & second )
inline

Constructor with initial values.

Parameters
firstThe initial value for the first member.
secondThe initial value for the second member.

Definition at line 47 of file Pair.hpp.

◆ Pair() [3/4]

template<typename T1, typename T2>
Sleak::Pair< T1, T2 >::Pair ( const Pair< T1, T2 > & other)
default

Copy constructor.

Parameters
otherThe Pair object to copy from.

◆ Pair() [4/4]

template<typename T1, typename T2>
Sleak::Pair< T1, T2 >::Pair ( Pair< T1, T2 > && other)
inlinenoexcept

Move constructor.

Parameters
otherThe Pair object to move from.

Definition at line 61 of file Pair.hpp.

Member Function Documentation

◆ operator=() [1/2]

template<typename T1, typename T2>
Pair & Sleak::Pair< T1, T2 >::operator= ( const Pair< T1, T2 > & other)
default

Copy assignment operator.

Parameters
otherThe Pair object to copy from.
Returns
A reference to the assigned Pair object.

◆ operator=() [2/2]

template<typename T1, typename T2>
Pair & Sleak::Pair< T1, T2 >::operator= ( Pair< T1, T2 > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe Pair object to move from.
Returns
A reference to the assigned Pair object.

Definition at line 79 of file Pair.hpp.

◆ swap()

template<typename T1, typename T2>
void Sleak::Pair< T1, T2 >::swap ( Pair< T1, T2 > & other)
inlinenoexcept

Swaps the contents of this Pair with another Pair.

Parameters
otherThe Pair object to swap with.

Definition at line 92 of file Pair.hpp.

Member Data Documentation

◆ first

template<typename T1, typename T2>
T1 Sleak::Pair< T1, T2 >::first

Definition at line 33 of file Pair.hpp.

◆ second

template<typename T1, typename T2>
T2 Sleak::Pair< T1, T2 >::second

Definition at line 34 of file Pair.hpp.