std::unique_ptr<T> getT();ObserverPointer<T> getT();
C++ (Qt)struct CIem { typedef std::weak_ptr<CItem> TItemPtr; ... private: TItemPtr m_parent; std::vector<std::shared_ptr<CItem>> m_children; std::shared_ptr<CItem> m_self; // not null for root};
C++ (Qt)#include <experimental/memory> int main(){ using namespace std; using namespace std::experimental; auto u = make_unique<int>(42); int* p = u.get(); unique_ptr<int> a{p}; // Compiled. delete p; // Compiled. observer_ptr<int> o{u.get()}; unique_ptr<int> b{o}; // Not compiled. delete o; // Not compiled.}
C++ (Qt)TreeItemRef item = treeView->Root().childAt(0); item.SetName("test"); // синтаксис или "семантика" (?) ссылки if (CheckSomething(item)) DeleteItem(item); if (!item.IsNull()) item.SetName("done"); if (item.Lock()) {...}
C++ (Qt)if (item.Lock()) {...}
C++ (Qt)// int indextreeView->RemoveChildAt(index);
C++ (Qt)template<class T>struct CItemRef {...// data std::shared_ptr<T> m_shared; std::weak_ptr<T> m_weak; T * m_raw; };typedef CItemRef<TreeItem> TreeItemRef;