#include <Corrade/Containers/Pair.h>
template<class F, class S>
Pair class new in Git master
Pair of values.
An alternative to std::constexpr
contexts even in C++11. On the other hand, to simplify both the implementation and usage semantics, the type doesn't support references — wrap them in a Reference in order to store them in a Pair. Such type composition allows you to both rebind the reference and update the referenced value and the intent is clear.
Similarly to other containers and equivalently to std::
auto a = Containers::Pair<float, int>{35.0f, 7}; auto b = Containers::pair(35.0f, 7);
Unlike with std::
There's also a three-element variant, called a Triple.
STL compatibility
Instances of Pair are implicitly copy- and move-convertible to and from std::#include <utility>
. Additionally, the pair(T&&) overload also allows for such a conversion. Example:
#include <Corrade/Containers/PairStl.h> … std::pair<float, int> a{35.0f, 7}; Containers::Pair<float, int> b{a}; std::pair<bool, int*> c(Containers::pair(false, &b.second())); auto d = Containers::pair(std::pair<char, double>{'p', 3.14}); // d is Containers::pair<char, double>
Public types
- using FirstType = F
- First type.
- using SecondType = S
- Second type.
Constructors, destructors, conversion operators
-
Pair(Corrade::
DefaultInitT) explicit constexpr noexcept(…) - Construct a default-initialized pair.
-
Pair(Corrade::
ValueInitT) explicit constexpr noexcept(…) - Construct a value-initialized pair.
-
Pair(Corrade::
NoInitT) explicit noexcept(…) - Construct a pair without initializing its contents.
- Pair() constexpr noexcept(…)
- Default constructor.
- Pair(const F& first, const S& second) constexpr noexcept(…)
- Constructor.
- Pair(const F& first, S&& second) constexpr noexcept(…)
- Pair(F&& first, const S& second) constexpr noexcept(…)
- Pair(F&& first, S&& second) constexpr noexcept(…)
-
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::from(std::Pair(const T& other) noexcept(…)
declval<const T&>()))> - Copy-construct a pair from external representation.
-
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::from(std::Pair(T&& other) noexcept(…)
declval<T && >()))> - Move-construct a pair from external representation.
-
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::to(std::operator T() const &
declval<const Pair<F, S>&>()))> - Copy-convert the pair to external representation.
-
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::to(std::operator T() &&
declval<Pair<F, S> && >()))> - Move-convert the pair to external representation.
Public functions
- auto operator==(const Pair<F, S>& other) const -> bool constexpr
- Equality comparison.
- auto operator!=(const Pair<F, S>& other) const -> bool constexpr
- Non-equality comparison.
- auto first() & -> F&
- First element.
- auto first() && -> F
- auto first() const & -> const F& constexpr
- auto second() & -> S&
- Second element.
- auto second() && -> S
- auto second() const & -> const S& constexpr
Function documentation
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(Corrade:: DefaultInitT) explicit constexpr noexcept(…)
Construct a default-initialized pair.
Trivial types are not initialized, default constructor called otherwise. Because of the differing behavior for trivial types it's better to explicitly use either the Pair(ValueInitT) or the Pair(NoInitT) variant instead.
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(Corrade:: ValueInitT) explicit constexpr noexcept(…)
Construct a value-initialized pair.
Trivial types are zero-initialized, default constructor called otherwise. This is the same as Pair().
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(Corrade:: NoInitT) explicit noexcept(…)
Construct a pair without initializing its contents.
Enabled only for trivial types and types that implement the NoInit constructor. The contents are not initialized. Useful if you will be overwriting both members later anyway or if you need to initialize in a way that's not expressible via any other Pair constructor.
For trivial types is equivalent to Pair(DefaultInitT).
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair() constexpr noexcept(…)
Default constructor.
Alias to Pair(ValueInitT).
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(const F& first,
const S& second) constexpr noexcept(…)
Constructor.
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(const F& first,
S&& second) constexpr noexcept(…)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(F&& first,
const S& second) constexpr noexcept(…)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
Corrade:: Containers:: Pair<F, S>:: Pair(F&& first,
S&& second) constexpr noexcept(…)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::from(std:: declval<const T&>()))>
Corrade:: Containers:: Pair<F, S>:: Pair(const T& other) noexcept(…)
Copy-construct a pair from external representation.
template<class F, class S>
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::from(std:: declval<T && >()))>
Corrade:: Containers:: Pair<F, S>:: Pair(T&& other) noexcept(…)
Move-construct a pair from external representation.
template<class F, class S>
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::to(std:: declval<const Pair<F, S>&>()))>
Corrade:: Containers:: Pair<F, S>:: operator T() const &
Copy-convert the pair to external representation.
template<class F, class S>
template<class T, class = decltype(Implementation::PairConverter<F, S, T>::to(std:: declval<Pair<F, S> && >()))>
Corrade:: Containers:: Pair<F, S>:: operator T() &&
Move-convert the pair to external representation.
template<class F, class S>
F Corrade:: Containers:: Pair<F, S>:: first() &&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
const F& Corrade:: Containers:: Pair<F, S>:: first() const & constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
S Corrade:: Containers:: Pair<F, S>:: second() &&
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
const S& Corrade:: Containers:: Pair<F, S>:: second() const & constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class F, class S>
template<class F, class S>
Pair<typename std:: decay<F>::type, typename std:: decay<S>::type> pair(F&& first,
S&& second) constexpr
Make a pair.
Convernience alternative to Pair::
auto a = Containers::Pair<float, int>{35.0f, 7}; auto b = Containers::pair(35.0f, 7);
template<class F, class S>
template<class T>
auto pair(T&& other)
Make a pair from external representation.
template<class F, class S>
template<class F, class S>
Utility:: Debug& operator<<(Utility:: Debug& debug,
const Pair<F, S>& value)
Debug output operator.