-
Notifications
You must be signed in to change notification settings - Fork 116
[onedpl][ranges] L3 Range based algo API and implementation (memory group) #2292
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
base: main
Are you sure you want to change the base?
Conversation
606f4fa
to
39d183b
Compare
22f1c16
to
0ec2d06
Compare
0ec2d06
to
470f339
Compare
int val1; //value initialization | ||
int val2; | ||
|
||
Elem_0(): val1() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain in comments the idea of works with structure in which data is uninitialized and from this point may have any state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int
will be set to 0
due to zero-initialization (a sub-case of value initialization). I've corrected the comment above and moved it to this line for clarity.
|
||
oneapi::dpl::uninitialized_fill(std::forward<_ExecutionPolicy>(__exec), __first, __last, __value); | ||
|
||
return {__last}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {__last}; | |
return __last; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
is written intentionally, because it is equivalent to std::ranges::borrowed_iterator_t<_R>{__last}
(see the return type for the function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we have compile error in the next case?
return __last;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for note: practically we never have returns with this form for cases when we return one value, as I seen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return __last;
tells the function returns an instance of "decltype(__last)"return {__last};
tells the function returns an instance of new type (return type), which is created from__last
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My two cents:
- I like (1) when a function is short: no duplication, you see the return type and {} suggests that is it not the type of
__last
. - I do not like (2). It is as (1) but it does not benefit from {}. Adding {} is not that extra number of symbol we should avoid.
- I do not like (3), because I think that having the return type in the function signature is more important.
- I like (4) when a function is large.
It's mostly a matter of preference (and now looks like bikeshedding), but __pattern_uninitialized_fill
is small, so I vote for (1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it's a good topic to discuss shortly on our meeting.
UPD: the option (1) described at https://en.cppreference.com/w/cpp/language/list_initialization.html
And this variant has strongly defined semantic when make sense to apply in.
As far as we haven't compile errors here there is no reasons to apply it in the discussing cases I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree here fully with @dmitriy-sobolev . (1) when short, (4) when large.
I think these options make the code most clear and readable, which is my rule of thumb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some discussion with @SergeyKopienko offline and exploring with godbolt, I realized that (1) is not explicitly invoking the constructor, but rather creating an initializer list, and then still using implicit construction of the return type from that initializer list.
https://godbolt.org/z/dTo84fooz
While not the exact same error message, (1) and (2) both don't work with explicit constructors. I guess (1) may give the perception that the type will be changing, (1) is not a shorthand equivalent to (4).
So, I guess perhaps I prefer (4) generally. For short functions, I think (1) and (2) are both fine, its probably not worth a whole lot more time discussing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...from cppreference.com :
https://en.cppreference.com/w/cpp/language/return.html
2) Uses [copy-list-initialization](https://en.cppreference.com/w/cpp/language/list_initialization.html) to construct the return value of the function.
https://en.cppreference.com/w/cpp/language/list_initialization.html
8) in a return statement with a brace-enclosed initializer list used as the return expression and list-initialization initializes the returned object
ee23b56
to
9aad8b3
Compare
int val1; | ||
int val2; | ||
|
||
Elem() { val1 = 1; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have additional comments in the code why we don't initialize each field in constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment:
// It is sufficient to initialize only one field, the other can be used to verify that the raw memory is correctly set
Actually, I do not see strong reasons to have multiple members, but I suggest leaving it as it is. A side effect is checking the internal test infrastructure where it sets the raw memory.
3db16f1
to
80e2660
Compare
80e2660
to
be1d1a7
Compare
This reverts commit 0740bda.
This reverts commit e7b7b63.
…l::__internal::__swap_fn" This reverts commit b725006.
This reverts commit 81fd65a.
This reverts commit 4f8f8f5.
This reverts commit dab8e9a.
This reverts commit 72b1f8e.
This reverts commit 6fdd2cb.
This reverts commit 31a659c.
This reverts commit 786044c.
This reverts commit dfee286.
This reverts commit 4aaa892.
… to another PR" This reverts commit 683585e.
…_swap" This reverts commit 8e8a1c5.
This reverts commit ce723c2.
…mpare" This reverts commit a3dc444.
This reverts commit d4048e2.
…t_symmetric_difference, high level API" This reverts commit 42a98e8.
…anges::set_intersection high level API" This reverts commit c3f437e.
…igh level API" This reverts commit ac103a1.
… high level API" This reverts commit d30bb56.
3926ae2
to
86c4ff3
Compare
f4db229
to
9cf3a70
Compare
[onedpl][ranges] L3 Range based algo API and implementation (memory group)