Hacker News new | past | comments | ask | show | jobs | submit login

C++ uses value type to mean either a scalar object (int, tuple<double> etc) or a container that manages heap memory for you, e.g. a vector of a value type. If you stay in that world you can basically ignore memory management.



Staying away from std::unique_ptr<T> and std::unique_ptr<T[]> while using std::vector<T> sounds kind of silly. The last one is a generalized version of the first two. So claiming you don't use the first two is really misleading.


vector is a regular value type, unique_ptr isn't.


I'm not sure how you define "value type" (it certainly isn't C++ terminology; are you coming from C#?) but in any case, this is a distinction without a difference. You can replace every use of std::unique_ptr with std::vector and just switch a few method calls (like using .data() instead of .get()) and you'd achieve the same effects, just slower. I'm not sure what the point would be though, other than to be able to claim that you don't use smart pointers.


But std::shared_ptr is also a value type :)


It isn't. If you copy a value and change the copy, the original is unaffected.


C++ classes in general are value types. The fact that instances might share a common resource does not change that. See also https://learn.microsoft.com/en-us/cpp/cpp/value-types-modern....




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: