Home > Enterprise >  What kind of type should r-value reference parameter be in doxygen? [in] or [in, out]?
What kind of type should r-value reference parameter be in doxygen? [in] or [in, out]?

Time:01-16

/**
 * @param[?] u
 */
T func(U&& u);

The parameter u may be modified by func, while the modified status should be ignored seeing it's an r-value reference.

I haven't found any information about that, including the Doxygen Manual.

CodePudding user response:

You should not think in terms of "it's a reference, so that means X". You should think in terms of what u means to the function and what the function is doing with it. Merely moving from u is not enough to declare it an [inout] parameter. [inout] or [out] should be used when the function is deliberately setting a value to it that the user is expected to use. If you move from a rvalue-reference parameter, the user's parameter has no value anymore. That's kind of the antithesis of an "output".

Indeed, an rvalue reference parameter cannot be bound to an lvalue argument (directly). This means that a user can't just call func(some_variable); they have to explicitly move into it: func(std::move(some_variable));. That spelling doesn't feel like an output value; it's transferring something into the function. It would be a weird interface indeed if the user were expecting some_variable to have a new value, especially since func(some_type()); would effectively discard the "output" value.

  •  Tags:  
  • Related