-
Anonymous
Является ли результат STD :: Ranges :: Сортировка четко определена для диапазонов типов, поддерживающих только partial_o
Сообщение
Anonymous »
Вот относительно короткий пример: < /p>
Код: Выделить всё
#include
#include
#include
#include
#include
#include
struct Foo {
std::optional oi;
Foo() : oi{} {}
Foo(int i) : oi{i} {}
friend bool operator==(Foo const&, Foo const&) {
// not even invoked by the example
assert(false);
return {};
}
friend std::partial_ordering operator(Foo const& a, Foo const& b) {
return a.oi.has_value() && b.oi.has_value()
? a.oi b.oi
: std::partial_ordering::unordered;
}
};
int main() {
std::vector v{3, 1, {}, 2, {}, 7, 6, 7, 9, 8, 10};
std::ranges::sort(v);
for (auto i : v) {
if (i.oi) {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79643866/is-the-result-of-stdrangessort-well-defined-for-ranges-of-types-supporting-o[/url]
1748527315
Anonymous
Вот относительно короткий пример: < /p>
[code]#include
#include
#include
#include
#include
#include
struct Foo {
std::optional oi;
Foo() : oi{} {}
Foo(int i) : oi{i} {}
friend bool operator==(Foo const&, Foo const&) {
// not even invoked by the example
assert(false);
return {};
}
friend std::partial_ordering operator(Foo const& a, Foo const& b) {
return a.oi.has_value() && b.oi.has_value()
? a.oi b.oi
: std::partial_ordering::unordered;
}
};
int main() {
std::vector v{3, 1, {}, 2, {}, 7, 6, 7, 9, 8, 10};
std::ranges::sort(v);
for (auto i : v) {
if (i.oi) {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79643866/is-the-result-of-stdrangessort-well-defined-for-ranges-of-types-supporting-o[/url]