On 20.09.23 14:42, Ivan Solovev via Development wrote:
[...]
>  > O = compareThreeWay, following std::compare_three_way 
> (https://en.cppreference.com/w/cpp/utility/compare/compare_three_way)
>  > E = comparesEqual
>  >
>  > The vast majority of code will use operators to compare two objects.
>  > Code that somehow needs the concept spelled out can type it out as well.
>  > In contrast to `swap` we don’t need to be short here, given that the 
> operator-shorthand exists.
> 
> Nice suggestion, thanks! Works for me!

Yes, that would work for me, too.

>  > why do we need qEquals?
> 
> Actually, I have the same question. That's why I wrote that we might 
> decide to not provide (4) at all.
> We have deprecated qSwap() and explicitly recommend using
> 
>      using std::swap;
>      swap(lhs, rhs);
> 
> instead. So why should we act differently for comparison?

As a first approximation, it's convenience around the 
using+non-qualified call. And that convenience is substantial, just try 
to calculate the noexcept for that yourself to see why (qSwap() does it, 
in case you want to peek at the solution, as does C++17 with 
is_nothrow_swappable).

But, as mentioned in this thread some weeks ago, we're currently lacking 
public efficient API for "op== with Qt::CaseInsensitive". For the same 
reason we need equal^WcomparesEqual and can't rely solely on 
order^WcompareThreeWay, we need a standard way to have parametrized 
checks for equality. I was also mentioning fuzzy comparisons for FP 
types. Yes, we can again add QString::equals(), with the same problem 
for both non-generic and generic code as with the current 
QString{,View}::compare(). Or we use equal^WcomparesEqual overloads with 
additional arguments and a kernel for qComparesEqualMulti that does the 
moral equivalent of

        using Qt::equal;
        if constexpr (qxp::is_detected_v<equals_compatible_with, 
decltype(lhs), decltype(rhs), decltype(extraArgs)...)) { // for each 
subset of extraTypes...
            if (!equals(lhs, rhs, extraArgs...)) return false;
        } else {
            if (!equals(lhs, rhs)) return false;
        }
    }

Which means that a struct { QString s; double d; } that uses our 
framework will automatically be both Qt::CaseSensitive'ly and fuzzily 
comparable if it adds a trailing Args&&...args and uses our qEqualMulti.

This is all a bit bigger than some static method here and there can 
possibly solve.

Thanks,
Marc

-- 
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to