[Development] C++11 decltype magic with a container?

Thiago Macieira thiago.macieira at intel.com
Wed May 22 17:15:59 CEST 2013


On quarta-feira, 22 de maio de 2013 17.04.21, Stephen Kelly wrote:
> > 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.

The operator exists and there's nothing preventing it from existing. The 
problem is that the operator exists but can't be used.

> > Then the problem is in QPair.
> 
> It's a general problem/limitation in the decltype trick really which affects
> any container.

You need to add enable_if to all those containers to make sure they export 
their requirement to the outside. This is not a QVariant problem, it's a 
container problem.

> > 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.

It does. You need to make sure that there's an enable_if in the function 
you're trying to detect. You can't detect if the function compiles.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130522/b73fc350/attachment.sig>


More information about the Development mailing list