Search code examples
dscoping

What are scope functions in Dlang?


From https://github.com/MartinNowak/io/blob/master/src/std/io/package.d:

size_t write(const scope ubyte[] buf) scope;

What is the meaning of the second scope keyword?


Solution

  • It applies the scope qualifier to the hidden this parameter.

    Generally speaking, any keyword after the function applies to this, but otherwise has the same result as if it was on any other parameter. For example, a const at the end means the this reference is const.