You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All arguments are forwarded. Unlike get/set/operator[] on sol::state or sol::table, value semantics are not used here. It is forwarding reference semantics, which do not copy/move unless it is specifically done by the receiving functions / specifically done by the user.
But this is not entirely correct. If you pass an object to a sol::function by const-reference, the object is copied!
The following table compares the behavior of function calls with table setters:
Type
function call
table setter
T&
reference
copy
const T&
copy
copy
(const) T*
reference
reference
T&&
move
move
While the table setter is consistent in its treatment of reference arguments, function calls treat const T& differently from T&. Looking at the source code, this seems to be done on purpose, but I'm not really sure I understand the rationale. I would have expected both to be passed by reference! Anyway, the document should reflect the actual behavior.
Here's a thing that recently bit me. https://sol2.readthedocs.io/en/latest/functions.html#functions-and-argument-passing says the following about function argument passing:
But this is not entirely correct. If you pass an object to a
sol::function
by const-reference, the object is copied!The following table compares the behavior of function calls with table setters:
While the table setter is consistent in its treatment of reference arguments, function calls treat
const T&
differently fromT&
. Looking at the source code, this seems to be done on purpose, but I'm not really sure I understand the rationale. I would have expected both to be passed by reference! Anyway, the document should reflect the actual behavior.Here's some code that demonstrates the behavior:
The text was updated successfully, but these errors were encountered: