Thread overview
DIP1000 simple scopebuffer
Oct 24, 2016
Walter Bright
Oct 24, 2016
Mathias Lang
Oct 24, 2016
Walter Bright
Oct 25, 2016
Walter Bright
Jan 16, 2017
Nordlöw
Jan 16, 2017
Walter Bright
October 24, 2016
@safe struct ScopeBuffer
{
  private:
    int[10] buffer;

  public:
    ref int opIndex(size_t i) return
    {
        return buffer[i];
    }
}

Yes, a real one would be more complex, but that's the basic idea. The ref returns are tied to the instance of the ScopeBuffer.
October 24, 2016
On Monday, 24 October 2016 at 21:02:05 UTC, Walter Bright wrote:
> @safe struct ScopeBuffer
> {
>   private:
>     int[10] buffer;
>
>   public:
>     ref int opIndex(size_t i) return
>     {
>         return buffer[i];
>     }
> }
>
> Yes, a real one would be more complex, but that's the basic idea. The ref returns are tied to the instance of the ScopeBuffer.

Could you provide an usage example of something that doesn't compile currently, and will compile with your P.R. ?
The snippet you pasted already compiles, and doesn't use `scope` at all.
October 24, 2016
On 10/24/2016 3:16 PM, Mathias Lang wrote:
> The snippet you pasted already compiles, and doesn't use `scope` at all.

What Dicebot asked for was an example of a scopebuffer.
October 24, 2016
On 10/24/2016 3:16 PM, Mathias Lang wrote:
> Could you provide an usage example of something that doesn't compile currently,
> and will compile with your P.R. ?
> The snippet you pasted already compiles, and doesn't use `scope` at all.

http://www.digitalmars.com/d/archives/digitalmars/D/internals/DIP1000_discussion_and_testing_3.html#N63
January 16, 2017
On Monday, 24 October 2016 at 21:02:05 UTC, Walter Bright wrote:
>     ref int opIndex(size_t i) return

How does this differ from an opIndex() qualified as `return scope`?
January 16, 2017
On 1/16/2017 2:29 AM, Nordlöw wrote:
> On Monday, 24 October 2016 at 21:02:05 UTC, Walter Bright wrote:
>>     ref int opIndex(size_t i) return
>
> How does this differ from an opIndex() qualified as `return scope`?

Scope refers to the value, ref refers to the address of the container of the value.