Update docs to highlight lambda comparison#2146
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
| statements, the function is considered uncomparable.) | ||
| ) | ||
|
|
||
| --- |
There was a problem hiding this comment.
Try the new SPEC_RUNNALE_EXAMPLE_COMPILE macro
Verify with pmake test_dspec
| manifest constants, enum values and function arguments. If the | ||
| expression contains local variables, function calls or return | ||
| statements, the function is considered uncomparable.) | ||
| ) |
There was a problem hiding this comment.
How about adding:
If these constraints aren't fulfilled, the function is considered uncomparable and
isSamereturnsfalse
wilzbach
left a comment
There was a problem hiding this comment.
Getting there. I think some comments explaining your example would be helpful to the reader.
spec/traits.dd
Outdated
| expression contains local variables, function calls or return | ||
| statements, the function is considered uncomparable.) | ||
| $(LI If these constraints aren't fulfilled, the function is considered | ||
| uncomparable and `isSame` returns $(D false).) |
There was a problem hiding this comment.
This is not part of the list and should be put in a new paragraph after the list.
| static assert(__traits(isSame, a => ++a, b => ++b)); | ||
| static assert(!__traits(isSame, (int a, int b) => a + b, (a, b) => a + b)); | ||
| static assert(__traits(isSame, (a, b) => a + b + 10, (c, d) => c + d + 10)); | ||
|
|
There was a problem hiding this comment.
// lambdas accessing local variables are considered incomparable
|
|
||
| int b; | ||
| static assert(!__traits(isSame, a => a + b, a => a + b)); | ||
|
|
There was a problem hiding this comment.
// lambas calling local functions are considered incomparable.
spec/traits.dd
Outdated
| expression contains local variables, function calls or return | ||
| statements, the function is considered uncomparable.) | ||
| $(LI If these constraints aren't fulfilled, the function is considered | ||
| uncomparable and `isSame` returns $(D false).) |
| } | ||
| } | ||
|
|
||
| static assert(__traits(isSame, (A a) => ++a.a, (A b) => ++b.a)); |
There was a problem hiding this comment.
// lambdas with different data types are incomparable - even if have the same memory layout
|
@wilzbach Done |
wilzbach
left a comment
There was a problem hiding this comment.
LGTM - thanks a lot!
(probably a squash before merging this wouldn't hurt)
|
@RazvanN7 squash please. |
|
@wilzbach @ZombineDev sorry for the late response. I rebased. Thanks! |
For : dlang/dmd#7484