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)); }
Comments
Post a Comment