[Interest] QVariant compare operator

Allan Sandfeld Jensen kde at carewolf.com
Sun Apr 19 14:21:39 CEST 2020


On Sonntag, 19. April 2020 14:23:56 CEST André Pönitz wrote:
> On Sun, Apr 19, 2020 at 01:28:32PM +0200, Allan Sandfeld Jensen wrote:
> > On Sonntag, 19. April 2020 13:05:05 CEST André Pönitz wrote:
> > > On Sat, Apr 18, 2020 at 09:44:40PM -0300, Thiago Macieira wrote:
> > > > On Saturday, 18 April 2020 12:57:55 -03 Giuseppe D'Angelo via Interest
> > 
> > wrote:
> > > > > I guess that's the reason for dropping the comparisons in 6.0 and,
> > > > > eventually, reintroduce it in 7.0. With the hope that we've learned
> > > > > the
> > > > > lesson and proceed at _specifying_ the behaviour before implementing
> > > > > it.
> > > > 
> > > > Indeed, and implement the QVariant comparator on top of each
> > > > underlying
> > > > type's spaceship operator. That way, we could order elements of the
> > > > same
> > > > type. For mismatched types, QVariant can return
> > > > std::partial_ordering::unordered.
> > > > 
> > > > We can't do that right now because we can't rely on C++20. In fact, no
> > > > current compiler supports the spaceship operator. So that has to be Qt
> > > > 7.
> > > 
> > > How comes the spaceship operator comes into play here?
> > > 
> > > It's syntactical sugar and in some cases an optimization, but has no
> > > concepual powers exceeding those of operator<().
> > 
> > It has the concept of weak ordering, it isn't just returning true or
> > false,
> > but an enum of a specific type, which so we can report two elements as
> > incomparable if they are not of comparable types.
> 
> I don't think we need "incomparable" here.
> 
> QVariant(TypeA) and QVariant(TypeB) can be ordered for different TypeA and
> TypeB based e.g. on alphabetical order of their .typeName().
> 
> If wanted, this can be refined to make e.g. all integral types comparable.
> 
What about non-integral types? QVariants can't really be anything but weakly 
ordered as I see it, as some of the things it contains are either non-
comparable or weakly ordered themselves.

'Allan





More information about the Interest mailing list