Time to kill T() as (sometimes) working T.init alias ?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 11 05:01:44 PST 2012


On 12/11/12 2:19 AM, monarch_dodra wrote:
> On Tuesday, 11 December 2012 at 03:09:53 UTC, Dan wrote:
>> On Tuesday, 11 December 2012 at 01:47:38 UTC, Walter Bright wrote:
>>> On 12/10/2012 10:40 AM, Dan wrote:
>>>> For something as simple as this would you introduce COW?
>>>
>>> Yes.
>>
>> Any D examples showing the pattern in action with structs? I did not
>> see anything in the index of TDPL on COW except one reference
>> regarding strings. If it is a better approach I would like to know
>> more about how it is done and the trade-offs. Some of the responses
>> refer to having to check on every access, so is that not tough to manage?
>>
>> Thanks
>> Dan
>
> Here is a example of using COW for a simple object that wraps
> nothing more than an int:
[snip]

Walter and I discussed that it should be possible to automate the 
dupIfNeeded() (I call it ensureUnique()) calls like this:

* If a method is const or immutable, leave as is
* For all other methods, insert a ensureUnique() automatically in the 
prolog code

For this to work, the state must be private and all primitives must be 
implemented via methods (as opposed to free functions).


Andrei


More information about the Digitalmars-d mailing list