Automatic generated move operations and raw pointer members

早过忘川 提交于 2019-12-04 20:13:25

I frequently need a "smart" pointer that is both copyable and movable, but has a well-defined moved-from state, so I wrote tidy_ptr which is a "dumb" smart pointer that does nothing special except zero itself on move. That type is copyable, so to get the semantics you want for your class you would still need to define the copy operations as deleted (or just use std::unique_ptr with a no-op deleter).

I've tried to convince the standards committee that observer_ptr, "the world's dumbest smart pointer", should have this behaviour, but the consensus was that it should behave just like a built-in pointer (except for zero-initialization in the constructor). I still think it should zero on move. That paper shows a non_owning_ptr which is an alias for unique_ptr with a no-op deleter, which does what you want.

Just use a std::unique_ptr with your own noop_deleter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!