Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: allow 'stackalloc' followed by initialization #1112

Closed
ygc369 opened this issue Nov 16, 2017 · 7 comments
Closed

Proposal: allow 'stackalloc' followed by initialization #1112

ygc369 opened this issue Nov 16, 2017 · 7 comments

Comments

@ygc369
Copy link

ygc369 commented Nov 16, 2017

For example:

Span<int> prime = stackalloc int[10] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; // this should be allowed
@jcouv
Copy link
Member

jcouv commented Nov 20, 2017

Tagging @VSadov @OmarTawfik

@alrz
Copy link
Contributor

alrz commented Nov 20, 2017

I think Span is similar to initializer_list<T> in C++. so we could default to Span when no type is specified.

var span = {1, 2, 3};

@orthoxerox
Copy link

@alrz What would be the backing store of {1, 2, 3}, an array?

@alrz
Copy link
Contributor

alrz commented Nov 20, 2017

@orthoxerox It could be a shorthand for Span<int> span = stackalloc int[3] {1, 2, 3};

@orthoxerox
Copy link

@alrz I think this might be too confusing. Nothing indicates that you cannot return this value from your method, but you can't.

@alrz
Copy link
Contributor

alrz commented Nov 20, 2017

Yeah, var x = { 1 }; is probably too magical, but I think these should be possible:

Span<int> x = { 1 };
Span<int> x = stackalloc [] { 1 };
Span<int> x = stackalloc int[] { 1 };
Span<int> x = stackalloc int[1] { 1 };

With arrays, you can use var in all cases except for the first one.

@VSadov
Copy link
Member

VSadov commented Nov 20, 2017

The question of array initializers for stackalloc comes up very often nowdays.

It is fairly uncontroversial and a relatively small feature. It has been discussed before with near universal agreement that it should be done at some point

I have posted a proposal here #1122 - to make sure it does not fall off the list.

@ygc369 ygc369 closed this as completed Nov 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants