<div class="gmail_quote">On 28 January 2012 17:03, Robert Clipsham <span dir="ltr"><<a href="mailto:robert@octarineparrot.com">robert@octarineparrot.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 28/01/2012 14:50, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This has come up lots of times before.. I just wanted to effectively +1<br>
this request.<br>
<br>
I have some templates, and some reasonably complex functions I use<br>
strictly via CTFE to produce enums and evaluate conditions within the<br>
templates.<br>
When I build my code, I notice that the CTFE functions, which are never<br>
referenced in any runtime code, are still present in the object file.<br>
Additionally, one of these functions requires I import std.string, which<br>
is only used in CTFE code, and is otherwise a pointless import.<br>
<br>
I'd certainly like to be able to mark these functions CTFE to be sure no<br>
runtime code will ever be generated for them, and also, what can I do<br>
about CTFE imports? I don't want that import in my binary...<br>
</blockquote>
<br></div></div>
There are a couple of things you can do. The first is to make the imports function local, the second is:<br>
<br>
<a href="http://www.digitalmars.com/d/archives/digitalmars/D/Incremental_compilation_with_DMD_96138.html#N96337" target="_blank">http://www.digitalmars.com/d/<u></u>archives/digitalmars/D/<u></u>Incremental_compilation_with_<u></u>DMD_96138.html#N96337</a><br>
<br>
You'll notice that thread mentions a pragma(ctfe) patch for DMD, that's another option, though would require a patched compiler. I can't seem to find a link to that patch, a bit of googling should help though.<br>
<br>
Another idea I've just had:<br>
<br>
T myComplexFuntion()<br>
{<br>
if (__ctfe)<br>
{<br>
// Implement here<br>
}<br>
else<br>
{<br>
assert(0);<br>
}<br>
}<br>
<br>
This should allow the function to be inlined to assert(0); if it's called at runtime, so while it will still exist in the binary, it won't introduce lots of additional bloat.</blockquote><div><br></div><div>Sweet, I'll do that for now. </div>
<div>You mean static if() right?</div></div>