new discovery: import only if available

Rainer Schuetze r.sagitario at gmx.de
Fri Jun 21 11:47:15 PDT 2013



On 21.06.2013 14:41, Adam D. Ruppe wrote:
> OMG guys this finishes the druntime extension problem!
>
>
> Try it yourself, open up dmd2/src/druntime/import/object.di and find
> template RTInfo.
>
> Change it to this:
>
> template RTInfo(T)
> {
>      static if(__traits(compiles, { import druntime.extensions; auto a
> =  druntime.extensions.    RTInfo!T; })) {
>          import druntime.extensions;
>           enum RTInfo = druntime.extensions.RTInfo!T;
>      } else
>          enum RTInfo = cast(void*)0x12345678;
> }

I guess you should move the "static if" outside of the template to avoid 
having it evaluated for every type. This can be pretty expensive as it 
includes a file search every time if it fails.

>
> It triggered! Boom, we have the potential for *project-wide*
> modifications to RTInfo without modifying druntime. Combine this with
> the other techniques I've talked about for rtinfo and we have it all.
>
> You wouldn't necessarily have to add it specifically to the command line
> btw, you could put it in a file called druntime/extensions.d in your
> import directory as well, especially since it is a template.

I was considering something similar, maybe this could even be extended 
to allow combining multiple extensions to work side-by-side.

I'm unsure though if this is too brittle with respect to linking 
something together that might be compiled with or without these extensions.


More information about the Digitalmars-d mailing list