static arrays becoming value types
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Oct 21 10:35:35 PDT 2009
language_fan wrote:
> Wed, 21 Oct 2009 10:48:34 -0500, Andrei Alexandrescu thusly wrote:
>
>> language_fan wrote:
>>> Wed, 21 Oct 2009 11:07:29 -0400, Robert Jacques thusly wrote:
>>>> My issue was that all your example _showed_ was nominal typing. Though
>>>> I didn't mention it by name, I did mention that if SOL tuples had
>>>> structural typing, it might would be a different story. (Well,
>>>> until/if opImplicitCast was implemented, as it would allow for
>>>> structural typing.)
>>> Why do you insist on using nominal typing for tuples and the library
>>> defined "literal". If I want plain old tuples without any kind of type
>>> name, why should I care about extra hand waving needed to make it work.
>> I'm late in this dialog, but I'm not seeing an impediment here. What
>> does it matter to you that tuples actually have a name vs. not having a
>> name at all?
>
> Using tuples in D is a major pain in the ass. In fact it has been made so
> hard that people start avoiding the feature like plague.
How do you know what "people" do?
> I wrote some
> test code to reveal how inconsistent their semantics are. Note that you
> need the built-in tuples for some stuff, like assigning and mixed value/
> type tuples. Stuples can only be used as values and when the auto-
> flattening is not desired.
>
>>>> STARTS HERE
>
> template Tuple(T...) { alias T Tuple; }
Why do you define Tuple instead of using the standard std.typecons.tuple?
> struct STuple(T...) {
> T t;
> }
Why do you insist on defining another tuple type instead of using the
one provided by the standard library?
> void main() {
> Tuple!(int,int) a; // typeof(this) *is* the official tuple type
> STuple!(int,int) b; // this is actually a struct
>
> a = Tuple!(1,1); // ok
That doesn't work for me at all (with std.typecons.Tuple). I think there
is confusion about a couple of things. One is that Tuple!(int, int) is a
type that contains two ints, whereas Tuple!(1, 1) is a type that
contains two compile-time integral values. So if you write:
a = Tuple!(1, 1);
that is as good syntactically as:
a = int;
which I hope you agree shouldn't quite go through. Write this:
Tuple!(int,int) a;
a = tuple(1, 1);
or this:
auto a = tuple(1, 1);
> // Tuple!(int,int) a2 = Tuple!(1,1); // WTF? Error: cannot implicitly
> convert expression (tuple(1,1)) of type (int, int) to int
Yeah, WTF that doesn't work either:
int a2 = int;
> auto a3 = Tuple!(1,1); // ok
Not ok on my machine, nor it should be ok as this is also not ok:
auto a3 = int;
> b = STuple!(int,int)(1,1); // no easier way? make_tuple!(1,1) ?
Yeah try tuple(1, 1) in conjunction with std.typecons.Tuple.
> STuple!(int,int) b2 = STuple!(int,int)(1,1); // ok, but very verbose
Well write this:
auto stuple(T...)(T args) {
return STuple!(T)(args);
}
> auto e1 = a[0]; // ok
This doesn't work because of a bug in the compiler, but this does with
std.typecons.Tuple:
auto e1 = a.field[0];
etc. etc. etc.
I'm sure you make a couple of good points, but they are difficult to
find. I suggest you peruse std.typecons.Tuple and submit any bugs you
find to bugzilla.
Andrei
More information about the Digitalmars-d
mailing list