On Monday, 9 May 2016 at 00:44:09 UTC, Peter Häggman wrote:
Their tuples seem to be a complete DIY:
https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx
I wouldn't be surpised to see in the implementation an array of
variant or something like that, explaining why it's limited to
octuples [1]. Sharp tuples look weak compared to D tuple-ish
things: Tuple, TList, AliasSeq, variadics, ...
[1] Also I think that the param-"variadicity" is simply
emulated via a set of overloaded constructor, explaining why
they stop at 8.
C#'s tuples are actually 8 different templated classes - one for
each arity. There's a lot of duplicated code to make that work.
Wait, it's actually 9 classes - in addition to Tuple<T1> through
Tuple<T1, ..., T8> there's the humble Tuple - a non-generic class
that cannot be instantiated and only exists to be a namespace for
the Tuple.Create function. The example code on gooroo seems to
have eaten the template arguments for the constructor example -
to instantiate a tuple you use one of these syntaxen:
var t1 = new Tuple<int, string>(1, "foo");
var t2 = Tuple.Create(2, "bar");
The 'templates' in C# are (much) more limited than old C++
templates, and have nothing on D's templates. That's not
necessarily a bad thing, though - the language is different and
fills a different niche. It does mean some things that are very
elegant in D end up very inelegant in C#, though.