[GSoC Proposal] Statically Checked Measurement Units

Cristi Cobzarenco cristi.cobzarenco at gmail.com
Wed Mar 30 08:03:34 PDT 2011


Hmmm, the only problem with this is that we would have to require the
library users to do this to their functions. Thanks for the suggestion but
I'll stick with .mangleof sorting.
(Cristi Cobzarenco)
Pofile: http://www.google.com/profiles/cristi.cobzarenco


On 30 March 2011 16:49, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:

> Maybe OT, but here's some hackish wizardry you can do with classes:
>
> class Test
> {
>    int value;
>
>    this(int x)
>    {
>        value = x;
>    }
> }
>
> ref Test foo(Test t ...)
> {
>    return tuple(t)[0];
> }
>
> void main()
> {
>    auto result = foo(4);
>    assert(result.value == 4);
> }
>
> The Tuple is used to trick DMD into escaping the local `t` reference.
> This won't work with structs. And `t` should be constructed on the
> stack, but it seems the destructor gets called only after the exit
> from main. The docs do say that construction of classes in variadic
> arguments depend on the implementation.
>
> I asked on the newsgroups whether Typesafe Variadic Functions
> automatically calling a constructor was a good thing at all. Read
> about this feature here under "Typesafe Variadic Functions":
> http://www.digitalmars.com/d/2.0/function.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110330/a1cf7abc/attachment.html>


More information about the Digitalmars-d mailing list