- array[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
// operator<=>により、以下の演算子が使用可能になる (C++20)
template <class T, size_t N>
bool operator<(const array<T, N>& x, const array<T, N>& y); // C++11
template <class T, size_t N>
constexpr bool operator<(const array<T, N>& x, const array<T, N>& y); // C++20
}arrayにおいて、左辺が右辺より小さいかの判定を行う。
型Tが<比較可能であること。その<が全順序関係を持っていること。
lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());- lexicographical_compare[link /reference/algorithm/lexicographical_compare.md]
- begin()[link begin.md]
- end()[link end.md]
size() に対して線形時間。
#include <iostream>
#include <array>
int main ()
{
std::array<int, 3> x = {1, 2, 3};
std::array<int, 3> y = {4, 5, 6};
if (x < y) {
std::cout << "less" << std::endl;
}
else {
std::cout << "greater equal" << std::endl;
}
}less
- C++11
- Clang: ??
- GCC: 4.7.0 [mark verified]
- ICC: ??
- Visual C++: 2008 (std::tr1) [mark verified], 2010 [mark verified], 2012 [mark verified]
- P1023R0
constexprcomparison operators forstd::array - P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出