On Saturday 16 October 2010 17:03:51 Tomek Sowiński wrote: > What's the status quo on member functions defined outside the type? > > import std.array; > > void main() { > int[] arr = [1,2]; > > // compiles, should it? > int a = __traits(getMember, arr, "front"); > > // compiles (called popFront), should it? > __traits(getMember, arr, "popFront"); > > // doesn't compile > // __traits(getMember, arr, "popFront")(); > } > > > I'd appreciate if someone told apart bugs from features.
Uniform function syntax doesn't change the member functions of a type. It just allows you to call functions as if they were member functions. And how could it be otherwise? Every time you imported a new module, it could completely change the set of member functions for any types in the current module. That would be really bad. Not to mention, all of the code that relies on knowing what the member functions actually are would be screwed if uniform function syntaxt affected __traits(getMember ...). Arrays don't have member functions. getMember _might_ give you properties like length (I'd have to try it to know for sure), but it has no member functions, so of course it isn't going to find popFront() and the like in its member functions. If you want that sort of behaviour, use __traits(compiles, ...) instead. Uniform function syntax is syntactic sugar. It should not change the meaning of a program like it would if you tried to make them member functions according to __traits. - Jonathan M Davis