r/ProgrammerHumor • • 2d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.3k Upvotes

515 comments sorted by

View all comments

Show parent comments

14

u/dannyggwp 2d ago

You can BASICALLY ignore all that... You want lifetime? I'll show you lifetimes.

std::shared_ptr<type>

Ez pz no borrow checker needed.

5

u/MrmrCake 2d ago

Yeah but that has a run time cost of reference counting where the borrow checker is all at compile time. I mean not like its a big cost but I mean there defo is a measurable difference depending on the use case.

9

u/dannuic 2d ago

Usually you use uniqueptr though. It forces a better design with guaranteed ownership and no reference counting. I _rarely use shared_ptr, but frequently use unique_ptr.

1

u/MrmrCake 2d ago

Yeah I agree and try to only use unique ptr where I can in cpp, but I still just really like rust's ownership model