More D newb questions.
Janice Caron
caron800 at googlemail.com
Tue May 6 11:54:39 PDT 2008
On 06/05/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
> There is no way opCat can do both jobs.
I completely agree. And there is another reason that this is a bad idea:
People observe that
array ~ array = array
array ~ char = array
char ~ array = array
(assuming array is an array of chars, of course), and then suppose
that the fourth case should also yield array.
char ~ char = array
But.... Suppose I replace the built in array type with my own custom
container, Array. Then I can override opCat and opCat_r to give me
MyArray ~ MyArray = MyArray
MyArray ~ char = MyArray
char ~ array = MyArray
However, there is no way I can persuade my custom container to give me
the effect:
char ~ char = MyArray
because the bottom line is, a container needs to know about its
elements, but elements do not need to know about their container.
Allowing ~ to create arrays from primitive types would give built-in
arrays an unfair advantage over custom arrays, and that alone should
be enough reason to disallow it.
More information about the Digitalmars-d
mailing list