UFCS for types?

James Miller james at aatch.net
Sun Apr 1 17:39:46 PDT 2012


On 31 March 2012 21:37, simendsjo <simendsjo at gmail.com> wrote:
> Is is possible to use UFCS for types to simulate static members?
>
> struct S {
>    static void f();
> }
>
> void ext(S)() {
>    S.f();
> }
>
> void main() {
>    ext!S(); // ok
>    S.ext(); // Error: no property 'ext' for type 'S'
> }

As far as I know UFCS just rewrites `a.f(b,c)` to `f(a,b,c)`, so
probably not, since `S.ext()` would be re-written to `ext(S)`, which
obviously makes no sense. Its pretty much just syntatic sugar with a
few disambiguation rules.

Basically you're asking for UFCS for template parameters, but that
would introduce too many ambiguities, especially considering things
like alias parameters:

    ext(alias T, U)(U a);
    int foo = 1;
    foo.ext() //does the alias T get the value, or the U a?

If you just remember that UFCS is just for functions, not templates,
or rather its Uniform Function-Call Syntax, not Uniform
Template-Instantiation Syntax (UTIS?). Because even ext(T)(); is just
sugar for:

    template ext(T) {
       void ext();
    }

--
James Miller


More information about the Digitalmars-d-learn mailing list