c++ - Non-copyable elements in vector -


i have non-copyable class (i.e. copy constructor & assignment operator marked 'delete'). keep these in std::vector.

it raii class storing pointer or reference not looking for.

my knowledge of new initialiser lists & move constructors limited, possible?

yes can have std::vector<notcopyable> if notcopyable movable:

struct notcopyable {     notcopyable() = default;     notcopyable(const notcopyable&) = delete;     notcopyable& operator = (const notcopyable&) = delete;      notcopyable(notcopyable&&) = default;     notcopyable& operator = (notcopyable&&) = default; };  int main() {     std::vector<notcopyable> v;     notcopyable nc;      v.push_back(notcopyable{});     v.emplace_back();     v.push_back(std::move(nc)); } 

live example.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -