Safer casts

Yigal Chripun yigal100 at gmail.com
Sun May 11 15:10:54 PDT 2008


Janice Caron wrote:
> On 11/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>>  I don't know how
>>  Andrei implemented it, but either the template inlines stuff
> 
> If the function is called N times (where N > 0), the template is
> instantiated exactly once.
> 
> The function /may/ get inlined, but this will be true of all
> functions, not just template functions. In D, there is no way to say
> "never inline this function".
> 
> 
> 
>>  if not than it would be the same as the delegate version.
> 
> Yes.
> 
> 
>>  only it'll
>>  bloat the executable since for each unique delegate there will be a copy
>>  of the template.
> 
> It is certainly possible to ensure that there is exactly one delegate
> type for each element type, so the number of copies can be made
> minimal.
> 
> 
>>  If my understanding here is wrong, feel free to correct me. [Janice?]
> 
> See separate post. By my reckoning, your OrderedCollection interface
> results in more executable bloat than use of std.algorithm.sort. (But
> if my understanding of your idea is wrong, feel free to correct me).

if what you say is true ( and i don't have any reason to believe
otherwise) than the use of templates here is redundant.
I like the idea of open classes very much (and wait for it to get
implemented for D2) since this removes the inconsistency between methods
and free functions.
the idea is that the classes would contain the minimal needed set of
methods (those there need polymorphism) and other functionality can be
provided with free functions, _but_ with a consistent interface. so, for
example, if all the collections would use the same reduce function, it
can be defined outside the hierarchy as a free function, but the user
would still be able to use collection.reduce as if it was part of the
interface. another possibility is to use mixins for common functionality
to avoid re-inventing the wheel.
in any way, the wanted result is that the user can use a consistent API.

-- Yigal



More information about the Digitalmars-d mailing list