http://d.puremagic.com/issues/show_bug.cgi?id=8616
Summary: Make pointers dereference with UFCS like they do with member functions Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: jmdavisp...@gmx.com --- Comment #0 from Jonathan M Davis <jmdavisp...@gmx.com> 2012-09-03 19:41:58 PDT --- As discussed here http://forum.dlang.org/post/spjfsyaqrcpboypgf...@forum.dlang.org pointers to structs and UFCS don't get along all that well at this point. UFCS dictates that the first function parameter be the type that the function is being called on, which means that for UFCS to work with a pointer, the function must take a pointer. struct S { auto func(int i) {...} } auto foo(S* s, int i) { ... } auto bar(S s, int i) { ... } S* s; s.foo(5); //compiles s.bar(7); //doesn't compile (*s).bar(8); //compiles The problem with this is that while it's consistent with UFCS in general, it's inconsistent with how member functions get called on pointers to structs. You can do S* s; s.func(12); as long as func is a member function, but if it's a free function, that only works if the free function takes an S* rather than an S. So, while calling a member function on a struct is the same whether you're dealing with a pointer or not S* s; S t; s.func(12); t.func(14); it's different when dealing with a free function and UFCS. S* s; S t; (*s).bar(); t.bar(); What this enhancement request proposes is that functions which take the struct as their first parameter rather than a pointer to the struct be considered in UFCS for pointers to that struct as long as there's no ambiguity. So, you could do S* s; S t; s.bar(); t.bar(); even though bar takes an S, not an S*. Presumably, if there's a conflict auto fiddly(S* s, float f) {...} auto fiddly(S s, float f) {...} S* s; S t; s.bar(); //fails to compile due to ambiguity t.bar(); //presumably compiles, since it would never use the S* version. then you'll get a compilation error, but as long as there isn't one, allowing for an S* to be used with UFCS just like S is would be useful and make it so that UFCS works with pointers to structs like member functions work with pointers to structs, which is the main reason for UFCS in the first place. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------