Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
October 24, 2016 DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
@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 Re: DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 Re: DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mathias Lang | 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 Re: DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mathias Lang | 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 Re: DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 Re: DIP1000 simple scopebuffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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.
|
Copyright © 1999-2021 by the D Language Foundation