[Development] Making QScopedPointer scoped (again)
Peter Kümmel
syntheticpp at gmx.net
Tue Sep 3 21:20:20 CEST 2013
>> Adding a move contructor to QScopedPointer makes no sense, because moving
>> means 'escaping the scope', which breaks the fundamental point of
>> QScopedPointer. QScopedPointer is different to std::unique_ptr and should
>> remain so.
I have to agree with Steven. After allowing moving, the semantic is
different to the naming: after this change we could write in the docs
"QScopedPointer sometimes deletes when it leaves the scope."
Which makes it obvious that "QScopedPointer" is the wrong name for such a behavior.
It is of great benefit that you never had to think about if QScopedPointer(5.1)
will delete when leaving scope.
>
> I disagree. The fact that you can exit the scope explicitly is perfectly fine.
>
> I would even go further and add conversions operators for STL compatibility:
>
> inline QScopePointer<T>::QScopePointer(std::unique_ptr<T> other)
> inline QScopePointer<T>::operator std::unique_ptr<T>()
>
The main point is that in Qt is nothing like std::unique_ptr, so when it is
needed and we can't use std::unique_ptr, we have to introduce a QUniquePointer.
This is better than to add features to classes which are contradictorily to their naming.
Peter
More information about the Development
mailing list