Thanks Nicol; an eloquent response addressing the topic.
While not quite an inherent good, C-array is our closest model of contiguous memory,
which close mapping was surely a contributor to the success of C and then C++.
On Tuesday, February 19, 2019 at 10:55:20 PM UTC-5, Nicol Bolas wrote:
...I'm curious as to what it is exactly about C++17's value category system that makes your proposal possible where it was not possible before.
I was referring to P0135 "Guaranteed copy elision through simplified value categories".
is the usual example (some say 'elison' is not the right word - 'evasion' may be more accurate).
I guess that array return could have been possible as a special case without this.
This proposed change allows a callee to allocate and return static array storage in the caller,
unwrapped - array is already an aggregate, no need to conglomerate it.
Syntactically, inside-out "declaration resembles usage" is a stumbling block,
though it is now nicely addressed with a using declaration;
template <typename T, size_t N> using carray = T[N];
Again, raw arrays, like raw pointers, are for low level code that calls for language expertise.
Poor syntax here could be seen as a feature as it puts off those who should not use it.
Ritchie calls out array-pointer relationship and declaration syntax as C's main issues
which goes on to give several paragraphs on array:
The other characteristic feature of C, its treatment of arrays, is more suspect on practical grounds, though it also has real virtues.
...
C's treatment of arrays in general (not just strings) has unfortunate implications both for optimization and for future extensions. The prevalence of pointers in C programs, whether those declared explicitly or arising from arrays, means that optimizers must be cautious, and must use careful dataflow techniques to achieve good results. Sophisticated compilers can understand what most pointers can possibly change, but some important usages remain difficult to analyze. For example, functions with pointer arguments derived from arrays are hard to compile into efficient code on vector machines, because it is seldom possible to determine that one argument pointer does not overlap data also referred to by another argument, or accessible externally. More fundamentally, the definition of C so specifically describes the semantics of arrays that changes or extensions treating arrays as more primitive objects, and permitting operations on them as wholes, become hard to fit into the existing language. Even extensions to permit the declaration and use of multidimensional arrays whose size is determined dynamically are not entirely straightforward [MacDonald 89] [Ritchie 90], although they would make it much easier to write numerical libraries in C. Thus, C covers the most important uses of strings and arrays arising in practice by a uniform and simple mechanism, but leaves problems for highly efficient implementations and for extensions.
C++ has addressed most of these array critique points (apart from dynamic arrays...).
Highly efficient implementation is now possible. This extension to array return is possible.
C++'s object model addresses aliasing, so correct C++ code can be as efficient as Fortran.
As long as decay to pointer is avoided, the program retains full information for array object-type.
References allow passing sized arrays to functions, so 'permitting operations on them as wholes'.
With references, passing array by value is not necessary;
it is inconsistent that you cannot pass array by value but references make this unimportant.
Allowing a callee to allocate and return array static storage is more important, as functions can then
wrap array creation rather than taking as an argument a mutable reference to a pre-declared array.