On Feb 1, 2020, at 09:59, David Kastrup <d...@gnu.org> wrote:
> 
> even with a reference parameter.  Of course this does not "really" give
> an indication about this being in-out, but neither does &variant.

That's an important point.  What indicates that a parameter is _not_ an 
out-parameter is "const".  You might happen to have that near enough to the 
call site to be helpful.

    const Foo& foo = ...;
    int mp = calc_midpoint (foo);

Where you don't have that, and you want to leave no doubt that a function does 
not modify your object, you can declare a separate const reference and pass 
that, or you can use a convenience function like std::as_const from C++17,

    Foo foo;
    string s = to_string (ly::as_const (foo));
    ...
    return calc_midpoint (foo); // might modify foo

I hope that that example makes as_const and "might modify foo" look like the 
result of an overabundance of caution.  I don't mean to suggest that as_const 
or comments should be dictated in situations like this anymore than I think 
that passing out-parameters as pointers should be dictated.
--
Dan


Reply via email to