I have an issue with clang-tidys recommendation
Clang-tidy: arg is passed by value and only used once; consider moving it.
So the code is essentially this:
struct S{
kinda_heavy obj;
S(kinda_heavy heavy):obj(heavy){}
void do_stuff();
};
I'm expecting the caller to use an x-value argument.
S app = S(get_kinda_heavy());
Or maybe the caller will use it like
{
auto env = get_kinda_heavy();
S s{env};
s.do_stuff();
}
I'm under the impression no copying of env will take place here under normal circumstances, i.e the caller will understand if a copy is being made or not.
I'm hoping CTidys comment isn't applicable to me.
My reason for asking is I don't want to sprinkle my code with hints that aren't useful for the reader nor the compiled code.
Clarification for me: I think I'm asking; under what circumstance is this a zero copy operation?
Of course, the kinda_heavy has both move and copy CTOR and assignment.
S(kinda_heavy /*&&*/ heavy):obj(sd::move(heavy)){}S s{env};does a copy, you have to useS s{std::move(env)};.Foo&&style parameter everywhere, and I added unaryoperator+to copy my Foo, and unaryoperator~to move my Foo. I thought it was helpful, and made the code more succinct. But outside of the privacy of my home computer, it would get me arrested by the operator overload abuse police.