Actually that was a pretty useless example. const needs to be evaluable at compile-time, so why did I bother creating a template function? lol..<br><br><div class="gmail_quote">On Wed, Aug 11, 2010 at 7:03 PM, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I think a more appropriate word for that would be "hide", or maybe "freeze".<br>
<br>Here's another alternative, if you can call it that :p :<br><br>import std.stdio;<br><br>auto freeze(alias dg)()<br>
{<br> return cast(const) dg();<br>}<br><br>void main() {<br> auto aa = freeze!(<div class="im"><br> {<br> int[int] aa_;<br> foreach (i; 0 .. 10)<br> aa_[i] = i * i;<br><br></div> return aa_;<br>
});<br>
<br> writeln(aa, " ", typeid(aa));<br>}<br><br>But that returns const(const(int)[int]).<br><br>I'm not sure if there's a way to hide a symbol, appart from introducing another scope with { }. That wouldn't work in this case, since you want a const type back. Perhaps using the "variant" type from Phobos could do the trick.. I haven't played with that yet.<div>
<div></div><div class="h5"><br>
<br><div class="gmail_quote">On Wed, Aug 11, 2010 at 6:01 PM, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>> Here delete doesn't clean the aa_, it just removes the aa_ name from the local namespace.<br>
<br>
</div>It's similar to the #undef directive of C.<br>
<br>
Bye,<br>
<font color="#888888">bearophile<br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>