[Issue 9088] static static

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 29 05:16:02 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9088


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich at gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-11-29 05:15:58 PST ---
For functions: I think this might be the job of the compiler/linker. If there
are multiple static function definitions that are identical they should be
merged, there's no need for the user to do the job of the compiler/linker.

As for template-shared variables, they are possible without bloating the global
(module) scope by using templates, for example:

template Wrap()
{
    int globX;

    struct Foo(T)
    {
        alias globX x;
    }
}

alias Wrap!().Foo Foo;

void main()
{
    Foo!(int) f1;
    Foo!(float) f2;

    f1.x = 10;
    assert(f2.x == 10);
}

You could probably implement some kind of helper mixin that could implement
this automatically.

Here's the same trick with function templates:

import std.stdio;

template Wrap()
{
    dchar[] table = ['a', 'b', 'c'];
    immutable val = 10;

    int foo(T)() if (is(T == char) || is(T == dchar) || is(T == wchar))
    {
        writeln(&table);
        return 0;
    }
}

alias Wrap!().foo foo;

void main()
{
    alias foo!char fooChar;
    alias foo!dchar fooDChar;

    // both print the same address
    fooChar();
    fooDChar();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list