// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*- // vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi #ifndef CTL_PAIR_H_ #define CTL_PAIR_H_ #include "utility.h" namespace ctl { template struct pair { using first_type = T1; using second_type = T2; T1 first; T2 second; constexpr pair() : first(), second() { } constexpr pair(const T1& x, const T2& y) : first(x), second(y) { } constexpr pair(const pair& p) : first(p.first), second(p.second) { } template constexpr pair(U1&& x, U2&& y) : first(ctl::forward(x)), second(ctl::forward(y)) { } template constexpr pair(const pair& p) : first(p.first), second(p.second) { } constexpr pair(pair&& p) : first(ctl::move(p.first)), second(ctl::move(p.second)) { } template constexpr pair(pair&& p) : first(ctl::move(p.first)), second(ctl::move(p.second)) { } pair& operator=(const pair& other) { first = other.first; second = other.second; return *this; } pair& operator=(pair&& other) noexcept { first = ctl::move(other.first); second = ctl::move(other.second); return *this; } template pair& operator=(const pair& other) { first = other.first; second = other.second; return *this; } template pair& operator=(pair&& other) { first = ctl::move(other.first); second = ctl::move(other.second); return *this; } void swap(pair& other) noexcept { using ctl::swap; swap(first, other.first); swap(second, other.second); } }; template constexpr pair make_pair(T1&& t, T2&& u) { return pair(ctl::forward(t), ctl::forward(u)); } // Comparison operators template constexpr bool operator==(const pair& lhs, const pair& rhs) { return lhs.first == rhs.first && lhs.second == rhs.second; } template constexpr bool operator!=(const pair& lhs, const pair& rhs) { return !(lhs == rhs); } template constexpr bool operator<(const pair& lhs, const pair& rhs) { return lhs.first < rhs.first || (!(rhs.first < lhs.first) && lhs.second < rhs.second); } template constexpr bool operator<=(const pair& lhs, const pair& rhs) { return !(rhs < lhs); } template constexpr bool operator>(const pair& lhs, const pair& rhs) { return rhs < lhs; } template constexpr bool operator>=(const pair& lhs, const pair& rhs) { return !(lhs < rhs); } template void swap(pair& lhs, pair& rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); } } // namespace ctl #endif // CTL_PAIR_H_