On Tuesday, December 10, 2013 10:10:22 Namespace wrote:
> Yeah I remember, but Kenji made a Pull Request to change this.
> Regardless it would be very useful to have static array literals.
It should be possible to do that via a templated function which takes a static
array and then returns it. e.g.
auto staticLiteral(T, size_t n)(T[n] literal)
{
return literal;
}
auto staticArray = staticLiteral([1, 2, 3, 4]);
The compiler should optimize out the heap allocation, since the literal is
directly converted to a static array (it might not optimize it now, but it
definitely should, in which case, you're effectively creating a static array
literal without any heap allocations).
Maybe that's more verbose than would be ideal, but it allows us to essentially
have static array literals without having to add anything to the language.
- Jonathan M Davis