infer elementType for ranges in makeArray,makeSlice#4263
Conversation
std/experimental/allocator/package.d
Outdated
|
|
||
| /// Ditto | ||
| T[] makeArray(T, Allocator, R)(auto ref Allocator alloc, R range) | ||
| auto makeArray(T = void, Allocator, R)(auto ref Allocator alloc, R range) |
There was a problem hiding this comment.
I would prefer that, but
- this might break compatibility (which might be okay because it's experimental)
- removes the feature to use a different type
There was a problem hiding this comment.
auto makeArray(T = ElementType!R, Allocator, R)
1 and 2. really?
d099a4e to
6c2b8ca
Compare
|
thanks to @9il helpful I removed |
| /// Ditto | ||
| Unqual!(ElementType!R)[] makeArray(Allocator, R)(auto ref Allocator alloc, R range) | ||
| if (isInputRange!R) | ||
| { |
6c2b8ca to
c95b820
Compare
|
I also prefer Ilya's version:
|
I would prefer that too, but unfortunately D isn't that smart. It yields |
|
@wilzbach that should work. It may be a possible bug with template argument type deduction. |
@MetaLang AFAIK it's a missing feature, which would be awesome to have! |
std/experimental/allocator/package.d
Outdated
| Unqual!(ElementType!R)[] makeArray(Allocator, R)(auto ref Allocator alloc, R range) | ||
| if (isInputRange!R) | ||
| { | ||
| import std.range.primitives; |
There was a problem hiding this comment.
static if (is(StringTypeOf!R) && is(R : E[], E))
alias ElementEncodingType = E;
else
alias ElementEncodingType = ElementType!R static if (is(typeof(R.init.front.init) T))
alias ElementType = T;
else
alias ElementType = void;... where is the difference?
There was a problem hiding this comment.
ElementType!(char[]) == dchar
ElementEncodingType!(char[]) == char
(Because R.init.front.init is dchar for narrow strings.)
|
preapproved once nits are looked at |
d61f087 to
c44b282
Compare
Ah auto-decoding :S |
|
No problem :) Maybe not directly related to your PR, but do you happen to know what will |
|
Ping @9il, I think this can be merged now |
std/experimental/allocator/package.d
Outdated
| } | ||
|
|
||
| /// Ditto | ||
| Unqual!(ElementType!R)[] makeArray(Allocator, R)(auto ref Allocator alloc, R range) |
71c87b2 to
7bcd92f
Compare
| } | ||
|
|
||
| for (; !range.empty; range.popFront, ++i) | ||
| import std.conv : emplace; |
There was a problem hiding this comment.
we need the special case for narrow strings & as we already have the special case, using it for arrays will be faster too (see e.g. #4265)
|
LGTM |
|
Travis fails, fix/rebase please |
|
@9il FYI, you can log in your GH user to travis to force a rebuild (as a dlang member). Just figured this out recently. However, in this case, I don't think that will help, as there is an actual issue. |
7bcd92f to
f35efe4
Compare
Done. Should be passing now. |
|
Auto-merge toggled on |
As discussed earlier, it's possible to infer the ElementType for
makeArraywith Ranges.Even better we can keep full compatibility and make this feature opt-in - is anyone against this?
tl;dr: let's allow the variant b! (a is still possible)
Ping @9il @andralex
edit: attached https://issues.dlang.org/show_bug.cgi?id=16450 to it.