<div class="gmail_extra">On Sun, Apr 22, 2012 at 4:24 AM, Gor Gyolchanyan <span dir="ltr"><<a href="mailto:gor.f.gyolchanyan@gmail.com" target="_blank">gor.f.gyolchanyan@gmail.com</a>></span> wrote:<br><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Voldemort types (coined by Andrei Alexandrescu) are types, which can't<br>
be named. Like so:<br>
<br>
auto getMisteriousData(int i)<br>
{<br>
    struct Mysterious<br>
    {<br>
        int i;<br>
    }<br>
<br>
    return Mysterious(i);<br>
}<br>
<br>
The only way to use mysterious structure is to either do this:<br>
<br>
auto m = getMysteriousData(12);<br>
<br>
or<br>
<br>
ReturnTypeOf!getMysteriousData m;<br>
<br>
Here's a very handsome use case of this setup:<br>
<br>
class Set(T)<br>
{<br>
public:<br>
    auto opIndex(T datum_)<br>
    {<br>
        struct Command<br>
        {<br>
        public:<br>
            alias _datum this;<br>
<br>
            bool contains() @property<br>
            {<br>
                return (_datum in _set) !is null;<br>
            }<br>
<br>
            void add()<br>
            {<br>
                _set._data[_datum] = false;<br>
            }<br>
<br>
            void remove()<br>
            {<br>
                _set._data.remove(_datum);<br>
            }<br>
<br>
        private:<br>
            Set _set;<br>
            T _datum;<br>
        }<br>
    }<br>
<br>
private:<br>
   bool[T] _data;<br>
}<br>
<br>
this will allow you do use Set class like this:<br>
<br>
auto s = new Set!int;<br>
assert(!s[6].contains);<br>
s[6].add();<br>
assert(s[6].contains);<br>
s[6].remove();<br>
assert(!s[6].contains);<br>
<br>
This will get even better if the voldemort Command structure, returned<br>
by opIndex would include the same pattern, allowing to chain the<br>
parameters and actions in any way desirable.<br>
<span><font color="#888888"><br>
--<br>
Bye,<br>
Gor Gyolchanyan.<br>
</font></span></blockquote></div><br></div><div class="gmail_extra">That's really neat.  We need to start making a catalog of interesting stuff you can do in D.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
Regards,</div><div class="gmail_extra">Brad Anderson</div>