[Static if] replace overload constraints with static if (mutation.d)#5149
[Static if] replace overload constraints with static if (mutation.d)#5149dlang-bot merged 1 commit intodlang:masterfrom
Conversation
df0c644 to
59ef3cd
Compare
wilzbach
left a comment
There was a problem hiding this comment.
This contains a fix for @WalterBright's favorite example of the remove overloads.
std/algorithm/mutation.d
Outdated
| if (areCopyCompatibleArrays!(SourceRange, TargetRange)) | ||
| if (isInputRange!SourceRange && ( | ||
| areCopyCompatibleArrays!(SourceRange, TargetRange) || | ||
| isOutputRange!(TargetRange, ElementType!SourceRange))) |
There was a problem hiding this comment.
The next overload which is grouped, is also an InputRange, but also an OutputRange
std/algorithm/mutation.d
Outdated
| void initializeAll(Range)(Range range) | ||
| if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range) | ||
| if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range || | ||
| is(Range == char[]) || is(Range == wchar[])) |
There was a problem hiding this comment.
The next overload is is(Range == char[]) || is(Range == wchar[]) which can be appended here as && has a higher precedence.
| (Range range, Offset offset) | ||
| if (s != SwapStrategy.stable | ||
| && isBidirectionalRange!Range | ||
| if (isBidirectionalRange!Range |
There was a problem hiding this comment.
This is @WalterBright's favorite example. There is absolutely no need to expose different overloads depending on the SwapStrategy to the user.
std/algorithm/mutation.d
Outdated
| void reverse(Range)(Range r) | ||
| if (isBidirectionalRange!Range && !isRandomAccessRange!Range | ||
| && hasSwappableElements!Range) | ||
| if (isBidirectionalRange!Range && (hasSwappableElements!Range || isRandomAccessRange!Range)) |
There was a problem hiding this comment.
The next overload is isRandomAccessRange!Range && hasLength!Range which implies bidirectionality of Range as isRandomAccessRange requires the following:
static assert(isBidirectionalRange!R || isForwardRange!R && isInfinite!R);Hence it either needs to have swappableElements (current) or is RandomAccess (next)
59ef3cd to
6552a95
Compare
| r.popBack(); | ||
| } | ||
| } | ||
| else static if (isNarrowString!Range && !is(ElementType!Range == const) && !is(ElementType!Range == immutable)) |
There was a problem hiding this comment.
As suggested this puts the overloads into one function, s.t. documentation & error message is improved
std/algorithm/mutation.d
Outdated
| // leftover move | ||
| moveAll(src, tgt); | ||
| return result; | ||
| else static assert(0, "Unknown SwapStrategy."); |
There was a problem hiding this comment.
Nitpick, change to SwapStrategy.semistable is not supported
JackStouffer
left a comment
There was a problem hiding this comment.
Looks good otherwise
6552a95 to
4c9170a
Compare
Addressed the nit. |
4c9170a to
c6819e2
Compare
|
This broke the nightly builds @wilzbach, see http://nightlies.dlang.org/dmd-master-2017-05-13/build.html. I'm also not positive this is a good long-term direction in general, hope we can work on improved error messages for template constraints later this year. |
|
@MartinNowak The motivation is documentation simplification and not error messages. |
|
https://dlang.org/phobos/std_algorithm_mutation.html#copy |
|
Reduced test-case: This actually seems to break "instantiation failure is not an error", for the copy overloadset, because the constraints are too general, now both imported copy functions are callable, but one already errors during semantic (think within the overload resolution). |
Split up of #5145