array cast should be supported corrected
Bill Baxter
wbaxter at gmail.com
Wed Aug 6 14:21:45 PDT 2008
On Thu, Aug 7, 2008 at 6:06 AM, BCS <ao at pathlink.com> wrote:
> Reply to Frank,
>
>> However. What is better in a template arraycast with o(n) or a cast?
>> The programmer always needs to know what the concequences are. With
>> this argumentation the string concatenation ~ should also be banned from
>> the language, because hidden heap allocation has always unbound execution
>> time.
>
> Array cat's /always/ do a O(?) allocation and a O(n+m) copy.
Not true for ~=. Sometimes allocates sometimes doesn't. You'll have
to come up with a better argument than that. :-)
That said, I don't see why writing arraycast!(T)(x) is so much worse
than cast(T)x. I wish D had more flavors of cast. The current cast
is a very blunt instrument. Seems obvious to me that It's a bad idea
to use the same construct to mean "please convert this to a T" and
"please pretend the bits of this are actually bits of a T". C++ added
all those extra kinds of casts for a reason.
> Cast usually
> does a O(1) transformation. Having the corner case be much worse than the
> normal case is the problem, not the fact it's O(n).
I think casting to an interface is O(n) in the number of interfaces
the object supports, no?
--bb
More information about the Digitalmars-d
mailing list