[Development] C++11 decltype magic with a container?
Stephen Kelly
stephen.kelly at kdab.com
Wed May 22 17:04:21 CEST 2013
On Wednesday, May 22, 2013 07:41:12 Thiago Macieira wrote:
> On quarta-feira, 22 de maio de 2013 11.07.44, Stephen Kelly wrote:
> > QSpiRelationArray::value_type is QSpiRelationArrayEntry which, being a
> > QPair, does have a operator==(), so the decltype gives the result that
> > the
> > std::find should work.
>
> In other words, QPair has an operator==, but it can't be used because it
> won't compile. Your code detects that it exists, but can't be sure that it
> works?
Correct. The compiler sees that operator==() exists, but it doesn't look into
the implementation to see that it contains t1 == other.t1, and therefore it
doesn't check if T1::operator==() exists.
> Then the problem is in QPair.
It's a general problem/limitation in the decltype trick really which affects
any container.
> You need to modify all operator== in classes with templates to make sure
> they are enable_if for the case where its template(s) is(are) comparable.
See my initial email. Now that we've stepped back it might make more sense to
you.
Thanks,
--
Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130522/f5e789f3/attachment.sig>
More information about the Development
mailing list