RFC: moving forward with @nogc Phobos

Daniel N via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 29 04:35:22 PDT 2014


On Monday, 29 September 2014 at 10:49:53 UTC, Andrei Alexandrescu 
wrote:
> Back when I've first introduced RCString I hinted that we have 
> a larger strategy in mind. Here it is.
>
> The policy is a template parameter to functions in Phobos (and 
> elsewhere), and informs the functions e.g. what types to 
> return. Consider:
>
> auto setExtension(MemoryManagementPolicy mmp = gc, R1, R2)(R1 
> path, R2 ext)
> if (...)
> {
>     static if (mmp == gc) alias S = string;
>     else alias S = RCString;
>     S result;
>     ...
>     return result;
> }
>

How about having something like ResourceManagementPolicy.infer, 
which under the hood could work something like below... you could 
combine it with your original suggestion, with an overridable 
MemoryManagementPolicy(just removed it to make the example 
shorter)

auto setExtension(R1, R2)(R1 path, R2 ext)
if (...)
{
     static if(functionAttributes!(__traits(parent, setExtension)) 
& FunctionAttribute.nogc)
       alias S = RCString;
     else
       alias S = string;
     ...
     return result;
}

Daniel N


More information about the Digitalmars-d mailing list