Overload using nogc

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 20 23:47:19 PST 2014


"Jonathan Marler"  wrote in message 
news:huzhibjpuvqjxqnubsog at forum.dlang.org...

> Has the idea of function overloading via nogc been explored?
>
> void func() @nogc
> {
>      // logic that does not use GC
> }
> void func()
> {
>      // logic that uses GC
> }
> void main(string[] args) // @nogc
> {
>      // if main is @nogc, then the @nogc version of func
>      // will be called, otherwise, the GC version will be
>      func();
> }
>
> This could be useful for the standard library to expose different 
> implementations based on whether or not the application is using the GC.

I think in most cases either the @nogc version would use different types (or 
it's templated), and therefore you wouldn't need to overload on @nogc, or 
you would simply have only a @nogc version. 



More information about the Digitalmars-d mailing list