|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
digitalmars.D.dtl - TypeInfo, containers and compare
For sorted containers I'm using the TypeInfo's "compare" as the default comparison function and storing any custom comparison function in a field in the container. I'd like some ideas about ways to specify this function. Given that arrays always use the TypeInfo's compare to sort elements what do people think about making the sorted container always use the TypeInfo and if a user wants a custom compare they define a custom TypeInfo? I think it is possible to define TypeInfos but I haven't been able to find any posts on the newsgroups giving an example. I'm leaning towards keeping it as a field. Another wrinkle is supporting delegates as well as functions but for something like a comparison function delegates don't seem that useful. -Ben Jul 22 2004
Ben Hinkle wrote:For sorted containers I'm using the TypeInfo's "compare" as the default comparison function and storing any custom comparison function in a field in the container. I'd like some ideas about ways to specify this function. Given that arrays always use the TypeInfo's compare to sort elements what do people think about making the sorted container always use the TypeInfo and if a user wants a custom compare they define a custom TypeInfo? I think it is possible to define TypeInfos but I haven't been able to find any posts on the newsgroups giving an example. I'm leaning towards keeping it as a field. Another wrinkle is supporting delegates as well as functions but for something like a comparison function delegates don't seem that useful. Jul 22 2004
You might consider just making it a delegate field, since delegate works for TypeInfo.compare() also: int delegate (void *, void *) p; TypeInfo ti = typed (T); p = &ti.compare; p.compare ( ... ); I tend to think the minor overhead for delegates (one additional push?) is worth the extra flexibility. - Kris "Ben Hinkle" <bhinkle mathworks.com> wrote in message news:cdp84a$134e$1 digitaldaemon.com...For sorted containers I'm using the TypeInfo's "compare" as the default comparison function and storing any custom comparison function in a field Jul 22 2004
|