How to create a container of noncopyable elements

后端 未结 3 1899
梦谈多话
梦谈多话 2021-01-18 11:44

Is there a way use STL containters with non-copyable elements?

something like this:

class noncopyable
{
    noncopyable(noncopyable&);
    const          


        
3条回答
  •  再見小時候
    2021-01-18 12:22

    Another option is to use the Boost Pointer Container library. This acts much like a standard container of std::auto_ptrs would, were such a thing possible: it retains exclusive ownership of its elements, and it cannot be copied. It also has less overhead than a standard container of shared_ptrs.

提交回复
热议问题