Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

It should be changed to pass by value, and then use std::move to move it into the children array. The reason is that if the argument is a temporary, you are making an unnecessary copy of that temporary, when you could just transfer ownership.

This also gives callers the flexibility to std::move into your argument, transferring ownership.

A good rule of thumb is, if you are going to unconditionally take ownership of an object, accept it by value.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: