[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings

Thiago Macieira thiago.macieira at intel.com
Tue Oct 20 01:02:38 CEST 2015


On Tuesday 20 October 2015 00:51:58 Olivier Goffart wrote:
> On Monday 19. October 2015 23:26:45 Marc Mutz wrote:
> > This particular mistake is easy to prevent statically, though:
> > 
> >    QStringView(QString &&) = delete;
> 
> No.
> 
> We want this to work:
> 
>  if (isValidIdentifier(myVariant.toString()))
> 
> with isValidIdentifier taking a QStringView and toString returning a 
> temporary.

That can be mitigated by overloading isValidIdentifier with a QString &&. That 
is:

	bool isValidIdentifier(QString &&id);
	bool isValidIdentifier(const QStringView &id);

The first one can delegate to the second, as inside it the id parameter is 
lvalue, not rvalue. That is:

	bool isValidIdentifier(QString &&id) 
	{ return isValidIdentifier(QStringView(id)); }

Note that this overload is not necessary for existing APIs where a const 
QString& overload is already present, as that will bind to the rvalue just 
fine.

So is there any case where we'd want a QString&& overload instead of a const 
QString &?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list