www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.internals - DIP1000 simple scopebuffer

reply Walter Bright <newshound2 digitalmars.com> writes:
 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.
Oct 24 2016
next sibling parent reply Mathias Lang <mathias.lang sociomantic.com> writes:
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.
Oct 24 2016
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
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.
Oct 24 2016
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
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
Oct 24 2016
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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`?
Jan 16 2017
parent Walter Bright <newshound2 digitalmars.com> writes:
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.
Jan 16 2017