lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use a pointer for the output parameter of Lily_lexer::scan_word (iss


From: Dan Eble
Subject: Re: Use a pointer for the output parameter of Lily_lexer::scan_word (issue 577440044 by address@hidden)
Date: Sat, 1 Feb 2020 11:08:06 -0500

On Feb 1, 2020, at 09:59, David Kastrup <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]