[Qt-creator] Proposal: Adding std::(experimental::)optional

Giuseppe D'Angelo dangelog at gmail.com
Thu Aug 25 20:25:10 CEST 2016


On Wed, Aug 24, 2016 at 1:57 PM, Eike Ziller <Eike.Ziller at qt.io> wrote:
> - "optional<IEditor*> EditorManager::currentEditor() const” makes it explicit that not having a current editor is a reasonable expectation, and that you have to check this condition before doing anything with the potential IEditor instance.
> - On the other hand, IEditor instances without an IDocument are not allowed, so if you are checking the return value of “IDocument *IEditor::document() const”, you should do that only as part of a QTC_ASSERT/QTC_GUARD style sanity check.

Playing devil's advocate here: what's the point of using an optional
pointer? Pointers already have an optional value -- the null pointer
constant. That seems totally redundant. Ideally one would use
optional<IEditor&>, which doesn't compile for other reasons, but
would have the semantics you describe.

Cheers,
-- 
Giuseppe D'Angelo



More information about the Qt-creator mailing list