...

/

Return Type Attributes: auto ref and inout

Return Type Attributes: auto ref and inout

You will learn about the auto ref and inout type of functions.

We'll cover the following...

auto ref functions

auto ref helps with functions like parenthesized() below. Similar to auto, the return type of an auto ref function is deduced by the compiler. Additionally, if the returned expression can be a reference, that variable is returned by a reference as opposed to being copied.

parenthesized() can be compiled if the return type is auto ref:

Press + to interact
import std.stdio;
auto ref string parenthesized(string phrase) {
string result = '(' ~ phrase ~ ')';
return result; // ← compiles
}
void main() {
writeln(parenthesized("hello"));
}

The ...