Skip to content

[Static if] replace overload constraints with static if (sorting.d)#5151

Merged
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:static_if_sorting
Jul 17, 2017
Merged

[Static if] replace overload constraints with static if (sorting.d)#5151
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:static_if_sorting

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Feb 18, 2017

Split up of #5145

Copy link
Contributor Author

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that the first three constraints are exactly the same and only the last one differs.

isRandomAccessRange!RangeIndex &&
hasAssignableElements!RangeIndex &&
isIntegral!(ElementType!(RangeIndex)))
isIntegral!(ElementType!(RangeIndex)) || is(ElementType!(RangeIndex) == ElementType!(Range)*))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next, to be grouped overload is

 isRandomAccessRange!Range &&
 isRandomAccessRange!RangeIndex &&    
 hasAssignableElements!RangeIndex &&
 is(ElementType!(RangeIndex) == ElementType!(Range)*))

Notice that the first three constraints are exactly equal and only the last one differs as the first overload is for a range of indexes and the second one for a range of pointers.

isRandomAccessRange!RangeIndex &&
hasAssignableElements!RangeIndex &&
isIntegral!(ElementType!(RangeIndex)))
isIntegral!(ElementType!(RangeIndex)) || is(ElementType!(RangeIndex) == ElementType!(Range)*))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the extra 4 leading spaces?

I suggest adding parens around this line to make the logic grouping clearer.

}
auto heap = BinaryHeap!(RangeIndex, indirectLess)(index, 0);
foreach (i; 0 .. r.length)
else
Copy link
Contributor

@John-Colvin John-Colvin Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to actually have a static if here as well and an else static assert(false) at the end to help ensure that the constraint and static ifs stay in sync. (E.g. if someone introduces a bug and a user finds it in a random corner case, they'll get a static assertion instead of potentially wrong execution or some compiler error inside phobos)

@John-Colvin
Copy link
Contributor

Other than the minor comments above, LGTM

@quickfur
Copy link
Member

quickfur commented Apr 5, 2017

ping @wilzbach

Let's address @John-Colvin 's comments and let's get this PR merged. It's been sitting here for far too long already.

@wilzbach wilzbach force-pushed the static_if_sorting branch from d4b1b2e to 59508c4 Compare May 5, 2017 10:12
isRandomAccessRange!RangeIndex &&
hasAssignableElements!RangeIndex &&
isIntegral!(ElementType!(RangeIndex)))
hasAssignableElements!RangeIndex)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested I moved the specific ElementType checks and trigger a static assert error (and thus nice error message!) if an invalid type is passed by accident.

@wilzbach
Copy link
Contributor Author

wilzbach commented May 5, 2017

Let's address @John-Colvin 's comments and let's get this PR merged. It's been sitting here for far too long already.

I absolutely agree & I am quite sorry that I have been so busy over the last weeks.

@John-Colvin
Copy link
Contributor

LGTM

@wilzbach wilzbach requested review from andralex and quickfur July 9, 2017 16:49
@wilzbach wilzbach added the Review:Trivial typos, formatting, comments label Jul 9, 2017
@andralex
Copy link
Member

@wilzbach you're on fire over there

@wilzbach
Copy link
Contributor Author

@wilzbach you're on fire over there

Isn't most of the Phobos queue on 🔥?

@dlang-bot dlang-bot merged commit 739c409 into dlang:master Jul 17, 2017
@wilzbach wilzbach deleted the static_if_sorting branch December 11, 2017 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants