Is it possible to "overload" based on visibility?

Steven Schveighoffer schveiguy at
Fri Sep 25 14:21:59 UTC 2020

On 9/25/20 10:12 AM, 60rntogo wrote:
> On Friday, 25 September 2020 at 13:15:27 UTC, Steven Schveighoffer wrote:
ou can use auto ref to alleviate that:
>> int x()(auto ref Foo f) // needs to be a template for auto ref to work
> That's a good point, thanks. Since we are on that topic, how would that 
> differ from the following?
> int x(in Foo f)

in does not mean "take by reference", it means "scope const"

> And going further, if instead of int I wanted to return something that 
> might also be expensive to copy, what would be the best way to declare 
> the function?

It depends on if you want to return a copy. If you want to return a 
reference if the source is a reference, use auto ref on the return as 
well. But if you still want to protect the internal data, it would have 
to be const.


More information about the Digitalmars-d-learn mailing list