digitalmars.D.learn - UFCS for types?
- simendsjo (11/11) Mar 31 2012 Is is possible to use UFCS for types to simulate static members?
- James Miller (20/31) Apr 01 2012 As far as I know UFCS just rewrites `a.f(b,c)` to `f(a,b,c)`, so
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' }
Mar 31 2012
On 31 March 2012 21:37, simendsjo <simendsjo gmail.com> wrote:Is is possible to use UFCS for types to simulate static members? struct S { =C2=A0 =C2=A0static void f(); } void ext(S)() { =C2=A0 =C2=A0S.f(); } void main() { =C2=A0 =C2=A0ext!S(); // ok =C2=A0 =C2=A0S.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 =3D 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
Apr 01 2012