template<class F, class S, class T>
Corrade::Containers::Triple class new in Git master

A tuple of three values.

Like Pair, but for three elements. Also a lightweight alternative to a three-element std::tuple that guarantees usability in 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 Triple. 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::make_tuple(), there's also triple(). The following two lines are equivalent:

auto a = Containers::Triple<float, int, bool>{35.0f, 7, true};
auto b = Containers::triple(35.0f, 7, true);

Similarly to a Pair, access to the triple elements is done using first(), second() and third() member functions, direct access to the members isn't provided. This is done in order to future-proof the design and have extra flexibility in how the internals are defined.

C++17 structured bindings

If Corrade/Containers/StructuredBindings.h is included, the class can be used in C++17 structured bindings. While the get<i>() overloads are defined inside Triple itself, a separate header is used for the std::tuple_size and std::tuple_element template specializations, as those may require #include <utility> on some STL implementations. Example:

#include <Corrade/Containers/StructuredBindings.h>



auto [first, second, third] = Containers::triple(42, false, 3.14f);

STL compatibility

Instances of Triple are implicitly copy- and move-convertible to and from a three-element std::tuple if you include Corrade/Containers/TripleStl.h. The conversion is provided in a separate header to avoid overhead from an unconditional #include <tuple>. Additionally, the triple(T&&) overload also allows for such a conversion. Example:

#include <Corrade/Containers/TripleStl.h>



std::tuple<float, int, bool> a{35.0f, 7, true};
Containers::Triple<float, int, bool> b{a};

std::tuple<bool, int*, bool> c(Containers::triple(false, &b.second(), true));

auto d = Containers::triple(std::tuple<char, double, bool>{'p', 3.14, true});
    // d is Containers::triple<char, double, bool>

Public types

using FirstType = F
First type.
using SecondType = S
Second type.
using ThirdType = T
Second type.

Constructors, destructors, conversion operators

Triple(Corrade::DefaultInitT) explicit constexpr noexcept(…)
Construct a default-initialized triple.
Triple(Corrade::ValueInitT) explicit constexpr noexcept(…)
Construct a value-initialized triple.
Triple(Corrade::NoInitT) explicit noexcept
Construct a triple without initializing its contents.
Triple() constexpr noexcept(…)
Default constructor.
Triple(const F& first, const S& second, const T& third) constexpr noexcept(…)
Constructor.
Triple(const F& first, const S& second, T&& third) constexpr noexcept(…)
Triple(const F& first, S&& second, const T& third) constexpr noexcept(…)
Triple(F&& first, const S& second, const T& third) constexpr noexcept(…)
Triple(const F& first, S&& second, T&& third) constexpr noexcept(…)
Triple(F&& first, const S& second, T&& third) constexpr noexcept(…)
Triple(F&& first, S&& second, const T& third) constexpr noexcept(…)
Triple(F&& first, S&& second, T&& third) constexpr noexcept(…)
template<class OtherF, class OtherS, class OtherT, class = typename std::enable_if<std::is_constructible<F, const OtherF&>::value&& std::is_constructible<S, const OtherS&>::value&& std::is_constructible<T, const OtherT&>::value>::type>
Triple(const Triple<OtherF, OtherS, OtherT>& other) explicit constexpr noexcept(…)
Copy-construct a triple from another of different type.
template<class OtherF, class OtherS, class OtherT, class = typename std::enable_if<std::is_constructible<F, OtherF && >::value&& std::is_constructible<S, OtherS && >::value&& std::is_constructible<T, OtherT && >::value>::type>
Triple(Triple<OtherF, OtherS, OtherT>&& other) explicit constexpr noexcept(…)
Move-construct a triple from another of different type.
template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::from(std::declval<const U&>()))>
Triple(const U& other) noexcept(…)
Copy-construct a triple from external representation.
template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::from(std::declval<U && >()))>
Triple(U&& other) noexcept(…)
Move-construct a triple from external representation.
template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::to(std::declval<const Triple<F, S, T>&>()))>
operator U() const &
Copy-convert the triple to external representation.
template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::to(std::declval<Triple<F, S, T> && >()))>
operator U() &&
Move-convert the triple to external representation.

Public functions

auto operator==(const Triple<F, S, T>& other) const -> bool constexpr
Equality comparison.
auto operator!=(const Triple<F, S, T>& other) const -> bool constexpr
Non-equality comparison.
auto first() & -> F& constexpr
First element.
auto first() && -> F constexpr
auto first() const & -> const F& constexpr
auto second() & -> S& constexpr
Second element.
auto second() && -> S constexpr
auto second() const & -> const S& constexpr
auto third() & -> T& constexpr
Third element.
auto third() && -> T constexpr
auto third() const & -> const T& constexpr

Function documentation

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple(Corrade::DefaultInitT) explicit constexpr noexcept(…)

Construct a default-initialized triple.

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 Triple(ValueInitT) or the Triple(NoInitT) variant instead.

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple(Corrade::ValueInitT) explicit constexpr noexcept(…)

Construct a value-initialized triple.

Trivial types are zero-initialized, default constructor called otherwise. This is the same as the default constructor.

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple(Corrade::NoInitT) explicit noexcept

Construct a triple 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 Triple constructor.

For trivial types is equivalent to Triple(DefaultInitT).

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple() constexpr noexcept(…)

Default constructor.

Alias to Triple(ValueInitT).

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple(const F& first, const S& second, const T& third) constexpr noexcept(…)

Constructor.

template<class F, class S, class T>
Corrade::Containers::Triple<F, S, T>::Triple(const F& first, const S& second, T&& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(const F& first, S&& second, const T& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(F&& first, const S& second, const T& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(const F& first, S&& second, T&& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(F&& first, const S& second, T&& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(F&& first, S&& second, const T& third) 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, class T>
Corrade::Containers::Triple<F, S, T>::Triple(F&& first, S&& second, T&& third) 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, class T> template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::from(std::declval<const U&>()))>
Corrade::Containers::Triple<F, S, T>::Triple(const U& other) noexcept(…)

Copy-construct a triple from external representation.

template<class F, class S, class T> template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::from(std::declval<U && >()))>
Corrade::Containers::Triple<F, S, T>::Triple(U&& other) noexcept(…)

Move-construct a triple from external representation.

template<class F, class S, class T> template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::to(std::declval<const Triple<F, S, T>&>()))>
Corrade::Containers::Triple<F, S, T>::operator U() const &

Copy-convert the triple to external representation.

template<class F, class S, class T> template<class U, class = decltype(Implementation::TripleConverter<F, S, T, U>::to(std::declval<Triple<F, S, T> && >()))>
Corrade::Containers::Triple<F, S, T>::operator U() &&

Move-convert the triple to external representation.

template<class F, class S, class T>
F Corrade::Containers::Triple<F, S, T>::first() && 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, class T>
const F& Corrade::Containers::Triple<F, S, T>::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, class T>
S Corrade::Containers::Triple<F, S, T>::second() && 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, class T>
const S& Corrade::Containers::Triple<F, S, T>::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, class T>
T Corrade::Containers::Triple<F, S, T>::third() && 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, class T>
const T& Corrade::Containers::Triple<F, S, T>::third() 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, class T> template<class F, class S, class T>
Triple<typename std::decay<F>::type, typename std::decay<S>::type, typename std::decay<T>::type> triple(F&& first, S&& second, T&& third) constexpr

Make a triple.

Convernience alternative to Triple::Triple(const F&, const S&, const T&) and overloads. The following two lines are equivalent:

auto a = Containers::Triple<float, int, bool>{35.0f, 7, true};
auto b = Containers::triple(35.0f, 7, true);

template<class F, class S, class T> template<class T>
auto triple(T&& other)

Make a triple from external representation.

template<class F, class S, class T> template<class F, class S, class T>
Utility::Debug& operator<<(Utility::Debug& debug, const Triple<F, S, T>& value)

Debug output operator.