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

Fix generate to be correctly implemented range. #4528

Merged
merged 2 commits into from
Jul 29, 2016

Conversation

schveiguy
Copy link
Member

A bit more complicated to deal with the possibility of ref returns. Also added a unit test to ensure ref returns work.

See rationale here: https://forum.dlang.org/post/nipa43$k0i$1@digitalmars.com

@qznc
Copy link
Contributor

qznc commented Jul 1, 2016

This somewhat depends on #4511


Params:
fun = is the $(D isCallable) that gets called on every call to front.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Params: section is missing now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed, basically said the same thing as Returns section.

@schveiguy
Copy link
Member Author

Can someone explain to me the failure in the travis build?

@schveiguy
Copy link
Member Author

Note: I'm working on an update to changelog...

import std.traits: ReturnType, functionAttributes, FunctionAttribute;
enum returnByRef_ = (functionAttributes!fun & FunctionAttribute.ref_) ? true : false;
static if(returnByRef_)
ReturnType!fun *elem_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Space between required if (. This is why Travis complains.

Likewise, at least one if and one foreach below.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. that is so not clear from the error message 😄

@JackStouffer
Copy link
Member

This somewhat depends on #4511

Yeah, I wouldn't pull this until that's settled. We still haven't heard Andrei's opinion.

@schveiguy
Copy link
Member Author

We still haven't heard Andrei's opinion.

I think Andrei and Walter are on the same page for that. Andrei seems stretched thin, so it may be a while.

@quickfur
Copy link
Member

quickfur commented Jul 6, 2016

What about a unittest that verifies that multiple calls to front without popFront does not invoke the generator function more than once?

@MetaLang
Copy link
Member

MetaLang commented Jul 6, 2016

I used generate in solving a Project Euler problem and switching the new implementation in still gave the right answer, so LGTM.

@schveiguy
Copy link
Member Author

@quickfur added

@@ -327,6 +329,15 @@ static assert( isFinal!(C.ff));
-------
)

$(LI $(LNAME2 generate, `std.range.generate` fixed to be a proper range.)
Copy link
Member

Choose a reason for hiding this comment

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

I would add a note here about following the clarified range rules with a link, when #4511 is pulled

Copy link
Member Author

Choose a reason for hiding this comment

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

Most expect ranges to behave this way, the updating of the rules is just a formal presentation of what everyone already knows. So I don't think a link is necessary.

@quickfur
Copy link
Member

quickfur commented Jul 7, 2016

LGTM.

@schveiguy
Copy link
Member Author

ping, #4511 has been merged.

foreach loop.
A by-value foreach loop means that the loop value is not $(D ref).
The resulting range will call $(D fun()) on construction, and every call to
$(D popFront), and the cached value returned when $(D front) is called.
Copy link
Member

Choose a reason for hiding this comment

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

"is/will be returned"?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, this grammar error "will be" fixed...

@schveiguy
Copy link
Member Author

nits fixed.


Returns: an $(D inputRange) that returns a new value generated by $(D Fun) on
any call to $(D front).
Returns: an $(D inputRange) where each element represents another call to fun.
Copy link
Member

Choose a reason for hiding this comment

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

backticks over $(D ) throughout

@JackStouffer
Copy link
Member

LGTM sans comments

@schveiguy
Copy link
Member Author

Done.

@JackStouffer
Copy link
Member

I meant backticks in your changes, but w/e :)

@schveiguy
Copy link
Member Author

My OCD forbade that idea :)

@9il
Copy link
Member

9il commented Jul 29, 2016

travis fails

@schveiguy
Copy link
Member Author

travis fails

Restarted. I fixed that issue already in another PR I think.

@dnadlinger
Copy link
Member

Please squash the relevant parts; I'll merge then.

@schveiguy
Copy link
Member Author

@klickverbot done

@dnadlinger
Copy link
Member

Auto-merge toggled on

@codecov-io
Copy link

Current coverage is 88.68% (diff: 100%)

Merging #4528 into master will increase coverage by <.01%

@@             master      #4528   diff @@
==========================================
  Files           121        121          
  Lines         73827      73850    +23   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          65471      65494    +23   
  Misses         8356       8356          
  Partials          0          0          

Powered by Codecov. Last update f75eeb5...287ca64

@dnadlinger dnadlinger merged commit 79d1195 into dlang:master Jul 29, 2016
@schveiguy schveiguy deleted the fixgenerate branch July 29, 2016 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants