c++ - Doubly Linked List Using std::unique_ptr -


anyone suggest implementation? tried @ home other day , discovered move semantics difficult establish prior link or simple linked list. easy if making tree using std::unique_ptr. of course std::shared_ptr makes easy implementation of question copy/assign. how it?

since question has been reopened, i'll post comment think answer:

if mean using only unique_ptr, impossible, since in doubly linked list have two pointers pointing each element, , cannot both unique_ptrs. (that contradict unique part somehow...)

to clarify, let's consider list of 3 elements: a <-> b <-> c here a contain unique_ptr next, pointing b , therefore owning b. c have unique_ptr prev, poiting b - , owning it, too. 2 unique_ptrs owning same object against unique_land's law, , have put evil efforts in achieve due unique_ptr's move-only properties.

the alternative list next pointers unique_ptrs, while last pointers plain old c-pointers - don't see problems there, don't think wanted.

but if had thing "half unique list" in mind, provide code , tell us, have problems - we'll gladly :)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -