A const idiom + a different 'delete'
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Aug 11 10:03:41 PDT 2010
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 <bearophileHUGS at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100811/593530b2/attachment.html>
More information about the Digitalmars-d
mailing list