-
Notifications
You must be signed in to change notification settings - Fork 436
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
accumulate
compile error using a lambda with ref parameter
#63
Comments
hi, have tou try declaring your lambda mutable? [](auto &a, auto const &b) mutable { ... } On 1 November 2014 15:23, Joseph Irwin notifications@github.com wrote:
|
Andrew |
Agree; the accumulate function should not be mutating the underlying sequence. But this highlights a larger issue with the library's concept checking, and I hope that you can shed some light on this, @asutton. It seems OK to want to mutate the input sequence via
I interpret this as: |
template So f would accept an lvalue ref, const lvalue ref, or rvalue. You could try writing "Function<F, const ValueType>", but that can be a Andrew |
Ooooh. I see. Your code is doing:
And my concept checking is doing the moral equivalent of:
That's very different. I need to change it to:
Wow, that's going to break a ton of stuff. :-P |
auto check(F f, Arg arg) -> decltype(f(arg)); And that mapped nicely into the way that Alex and Bjarne wanted to write I think our basic operating system is that when you write a constraint use Andrew |
Where
Your simple model works for all but the last one. That one needs special handling because any named thingy is an lvalue. My earlier suggestion of just using Anyway, thanks. That clears up a lot for me. |
I think I mostly understand; the lambda doesn't meet the concept requirements as they are written because Invokable (or Function) expects its arguments to be able to bind to rvalues because declval() returns an rvalue. And while I still think that taking the 'init' parameter as T& satisfies the requirement of not modifying the range, looking at cppreference.com it seems the standard library expects 'op' to behave like 'R op(T const&, U const&)' and I understand that it may not be worth changing that. I certainly didn't expect to provoke such an involved discussion; hope I didn't let any genies out of their bottles. |
After [e1db4ec], your code will compile as-is. I still think it's a bad idea. :-) |
Hi, I'm using this library in a project, and I encountered this problem. The following code doesn't compile (either on Clang 3.5.0 or gcc 4.9.1; my OS is Arch Linux):
It compiles if both parameters are by-value or const&, but it doesn't work if one or both is a reference. I can't figure out why it isn't working (maybe something to do with the Accumulateable concept?), but it seems like something that is reasonable to do.
Thanks in advance, and thanks for the library, it's very nice.
The text was updated successfully, but these errors were encountered: