cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

move constructor or use smart pointer

Open bac-ptit opened this issue 11 months ago • 1 comments

I have some question. Here is my code, it has question I want to ask everyone.

https://godbolt.org/z/3d3YzoW3h

My English is a bit poor, so if people have difficulty understanding what I write, I hope people can ignore it.

bac-ptit avatar Jan 18 '25 05:01 bac-ptit

Moves are usually pretty cheap/fast. With a container like std::vector it usually just has to swap a couple pointers and sizes regardless of how many elements are contained. Just do what makes the code simpler for now. If you encounter performance issues, you can use a profiler to identify the actual bottlenecks.

LB-- avatar Jan 19 '25 15:01 LB--