<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 31, 2016 at 10:43 PM, Stefan Koch via Digitalmars-d-announce <span dir="ltr"><<a href="mailto:digitalmars-d-announce@puremagic.com" target="_blank">digitalmars-d-announce@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Tuesday, 30 August 2016 at 22:01:45 UTC, tsbockman wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
On Monday, 29 August 2016 at 08:39:56 UTC, Stefan Koch wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
I just came up with a nifty little patch that makes it possible to ensure that a function is _only_ used at ctfe.<br>
Or the opposite.<br>
<br>
static assert(__ctfe, "This function is not supposed to be called outside of ctfe");<br>
and static assert(!__ctfe, "This function is not supposed to be called during ctfe");<br>
<br>
similarly you can use static if (__ctfe).<br>
<br>
Is it worth trying to get it into master ?<br>
</blockquote>
<br>
Yes, please. I've often wished I could use `__ctfe` in a `static if`.<br>
</blockquote>
<br></div></div>
Sorry. It I overlooked a something rather important. static __ctfe is currently not possible and it's rather expensive to make it possible.<br>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Surely changing the current implementation slightly could still work if we made a library implementation like:</div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">========</div><div class="gmail_extra">// ? module std.exception.enforce_ctfe;</div><div class="gmail_extra"><br></div><div class="gmail_extra">void main() {</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ctfefunc();</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">string ctfefunc() {</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>static if (assertCTFE!true) {</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>throw new Exception("asdf");</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>}</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>return `import std.stdio; writeln("ctfe generated this");`;</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">template assertCTFE(bool b) {</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>enum assertCTFE = __traits(compiles, _checkCTFE());</div><div class="gmail_extra">}</div><div class="gmail_extra">void _checkCTFE() {</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>import std.uuid;</div><div class="gmail_extra"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>enum id = new UUID("8AB3060E-2cba-4f23-b74c-b52db3bdfb46");</div><div class="gmail_extra">}</div><div><br></div></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">the _checkCTFE() function is just a function that does something we're not allowed to do at CTFE, but current implementation does not respect __traits(compiles, ....);</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">As far as I can tell that is a bug. Thoughts?</div><div class="gmail_extra"><br></div></div>