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..
On Wed, Aug 11, 2010 at 7:03 PM, Andrej Mitrovic <andrej.mitrov...@gmail.com > wrote: > I think a more appropriate word for that would be "hide", or maybe > "freeze". > > Here's another alternative, if you can call it that :p : > > import std.stdio; > > auto freeze(alias dg)() > { > return cast(const) dg(); > } > > void main() { > auto aa = freeze!( > > { > int[int] aa_; > foreach (i; 0 .. 10) > aa_[i] = i * i; > > return aa_; > }); > > writeln(aa, " ", typeid(aa)); > } > > But that returns const(const(int)[int]). > > 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. > > > On Wed, Aug 11, 2010 at 6:01 PM, bearophile <bearophileh...@lycos.com>wrote: > >> > Here delete doesn't clean the aa_, it just removes the aa_ name from the >> local namespace. >> >> It's similar to the #undef directive of C. >> >> Bye, >> bearophile >> > >