https://issues.dlang.org/show_bug.cgi?id=481
rswhi...@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rswhi...@gmail.com --- Comment #40 from rswhi...@gmail.com --- (In reply to Shriramana Sharma from comment #38) > Hmmm. I read through the thread starting at > http://forum.dlang.org/post/mag5hp$105a$1...@digitalmars.com. I think I sorta > see the point of the developers here. > > While I still think [$] is a cool little tidbit, I also have to agree with > the comment which said "let's not add every little tidbit to the language". > The title of the request is "letting compiler determine length for > fixed-length arrays", not specifically to add [$]. Having the compiler > determine the length can be done in many ways, and given that I already have > to go to the library for a lot of commonly used stuff like writeln and to!, > this one doesn't seem too much more. Although it *does* seem like something > you should have out of the box, so do stuff like print()... :-) > > The one thing the library solution probably cannot address would be the > convoluted examples like a fixed-size array of a dynamic array of fixed-size > arrays, but let's face it: those are really contrived examples and not worth > introducing a language feature for... > > I'm leaving my votes in since I do want *something* to be done to address > the actual request, since any such library solution is ATM still sitting > over at http://dpaste.dzfl.pl/f49a97e35974 and not actually included in > Phobos. > > BTW I don't think it should be named just 's' in the std.array module, but > something more meaningful, like fixedLengthArray (yikes, yes I know, but I'm > open to suggestions) and one can always do something like: > > import std.array: f = fixedLengthArray; There is a better way: ---- import std.stdio; pragma(inline, true); auto s(T, size_t n)(auto ref T[n] arr) { return arr; } void main() { auto arr = [1, 2, 3].s; writeln(typeof(arr).stringof); } --- --