You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a reason why a value cane be unique_ptr but not shared_ptr? I'm getting the following error when trying to define a ramalhete_queue using shared_ptr as value type:
Static assertion failed due to requirement 'std::is_pointer<std::shared_ptr<Person>>::value': T must be a raw pointer type or a std::unique_ptr
The text was updated successfully, but these errors were encountered:
Yes, the reason is that the ramalhete_queue can only store raw pointers. For unique_ptr we can simply use release in push to get the raw pointer and take over ownership, and then create a new unique_ptr with that value in pop to hand over ownership again. For shared_ptr this does not work. A shared_ptr usually consists of two pointers, one to the control block, and one to the value. We can use shared_ptr::get to get a raw pointer to the value, but that pointer does not keep the value alive. Unfortunately the standard does not provide access to the control block, so there is no standard compliant way to do this (at least I am not aware of any).
Is there a reason why a value cane be unique_ptr but not shared_ptr? I'm getting the following error when trying to define a ramalhete_queue using shared_ptr as value type:
Static assertion failed due to requirement 'std::is_pointer<std::shared_ptr<Person>>::value': T must be a raw pointer type or a std::unique_ptr
The text was updated successfully, but these errors were encountered: