If QString in Qt6 could be { QArrayData *d; ushort *b; int s }, then it supersedes QStringView in all aspects: - QString(u"hello world", 5) /* { d=.., b=.., s=5 } */ - still has a superpower of COW, etc - QString::fromRawData(u"hello world", 5) /* { d=nullptr, b=.., s=5 } */ - explicitly means "no owning, deep-copy when necessary"
then we could get rid of QStringRef (or typedef it to QString) and do something like: private: QString(QArrayData *dd, ushort *unicode, int size) { if (dd) { dd->ref(); } d = dd; b = unicode; s = size; } /* not that trivial, of course, just to describe the idea */ public: QString QString::left(int n) const { return QString(d, b, n); } QString QString::leftRef(int n) const { return QString(nullptr, b, n); } > That said, QStringView is as much about > > - slim interface type vs. thick, fat, storage type > - interop with 3rd-party and native code So as QString now... i.e. DWORD dwBufferSize = 0; if (::GetUserProfileDirectory(token, NULL, &dwBufferSize) == 0 && dwBufferSize != 0) { QVarLengthArray<wchar_t> userDirectory(dwBufferSize); if (::GetUserProfileDirectory(token, userDirectory.data(), &dwBufferSize) == 0) { QString dirName = QString::fromRawData(userDirectory.constData(), dwBufferSize); // still unsafe, but it is clearly documented for years and nothing has really changed for its users anyways return QDir().exists( dirName.rightRef(dirName.lastIndexOf(QLatin1Char('\\')))); } } Regards, Konstantin
_______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development