3 ms·
In c++ it also seems likely that with this approach you could invoke some pretty expensive copy constructors if some of the parameters have those.
by asveikau 6y ago
In c++ it also seems likely that with this approach you could invoke some pretty expensive copy constructors if some of the parameters have those.
- nikki93 6y agoIf it's a prvalue there is no copying involved. Here's an example where one of the 'parameters' has an 'expensive' copy constructor but it isn't invoked at all: https://godbolt.org/z/94ehvx https://godbolt.org/z/94ehvx However, if you use an lvalue expression then yes, the copy constructor is invoked (in `bar` here), and you can avoid that by using an xvalue expression (in `baz`, using `std::move`): https://godbolt.org/z/MnKnWM https://godbolt.org/z/MnKnWM Basically it doesn't depend on being passed through a struct as much as on the parameter itself. You'd see the same behavior if the `C` struct was passed as a regular parameter.