Skip to content

[Static if] replace overload constraints with static if (searching.d)#5150

Closed
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:static_if_searching
Closed

[Static if] replace overload constraints with static if (searching.d)#5150
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:static_if_searching

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Feb 18, 2017

Split up of #5145

@wilzbach wilzbach force-pushed the static_if_searching branch from 9328a55 to 74a5a5e Compare February 22, 2017 05:07
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.

(some comments about the constraints)

if (isNarrowString!R1 && isInputRange!R2 && !isNarrowString!R2 &&
is(typeof(r1.front == r2.front)))
if (isNarrowString!R1 && (isNarrowString!R2 ||
isInputRange!R2 && is(typeof(r1.front == r2.front))))
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 overload is isNarrowString!R1 && isNarrowString!R2, which implies R2 is either a narrow string or an input range with the same element type as R1.

(is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool) ||
isBidirectionalRange!R2 &&
is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool))
is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool)))
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 overload is isBidirectionalRange!R && is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool)

Which implies it's either bidirectional and back of both ends is comparable with pred or

Todo!!!

(isRandomAccessRange!R1 && (
isForwardRange!R2 ||
hasLength!R1 && hasSlicing!R1 && isBidirectionalRange!R2))
))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This groups these overloads:

isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && isBidirectionalRange!R2 && is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))

  • isRandomAccessRange!R1 && isForwardRange!R2 && !isBidirectionalRange!R2 && is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))

Notice

  • for all of them the front of both ranges needs to be comparable with the given binary function: is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool)) is required
  • overload 2 & 3 can be grouped further as they both require RandomAccess

if (isBidirectionalRange!R1 && (
is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool) ||
isBidirectionalRange!R2 && (is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool))
))
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 overload is isBidirectionalRange!R && is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool))
-> isBidirectionalRange!R is the overlapping constraint.

@UplinkCoder
Copy link
Member

The reason to have the overloads is to have the acceptable overloads visible.

@wilzbach
Copy link
Contributor Author

wilzbach commented Feb 26, 2017

The reason to have the overloads is to have the acceptable overloads visible.

And the reason for unifying them under one function is that @WalterBright and others agree that
the user shouldn't be bothered with implementation details.

@wilzbach
Copy link
Contributor Author

wilzbach commented Jul 9, 2017

Mostly superseded by #5575

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.

3 participants