4 ms·
Which part of "recursion", "stack overflow" and "crash" did you not understand? Do you think std::list uses smart pointers?
by zvrba 10y ago
Which part of "recursion", "stack overflow" and "crash" did you not understand? Do you think std::list uses smart pointers?
- gpderetta 10y agoYou are getting downvoted, but you are completely right. When implementing node based containers it is perfectly alright to use raw pointers as the nodes in no way own their children or siblings but they are all collectively owned by the datastructure. You should of course use smart pointers for the automatic pointers that temporarily hold node references in functions that manipulate the datastructure.
- lorenzhs 10y agoThe downvotes are for snark, not incorrectness the of content, I'm fairly certain. Such aggressive replies are not appreciated on HN. I find that this makes HN a much more pleasant community than some others.
- zvrba 10y agoThe reply is that way because the OP didn't seem to acknowledge that using unique_ptr in this case has serious problems. He still insists on using unique_ptr, reasoning boiling down to "you should avoid writing code because you may create bugs". As if slowness or lurking crash caused by not writing code were not a bug in itself.
- lorenzhs 10y agoOh I know, using unique_ptr to implement linked list is a terrible idea. Having an element be owned by its predecessor is a very weird idea, not to mention that it wouldn't work at all for a doubly linked list.... I'm just saying that your comment could have been written in a nicer way.