-
Notifications
You must be signed in to change notification settings - Fork 915
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 element access const correctness in hostdevice_vector
#10804
Fix element access const correctness in hostdevice_vector
#10804
Conversation
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.
Good fix! I have wondered about this before.
} | ||
T const* end() const { return h_data + num_elements; } | ||
|
||
auto d_begin() { return static_cast<T*>(d_data.data()); } |
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.
For clarity and consistency with the host accessors, should we use T*
, T const*
, etc. instead of auto
? It's somewhat obvious from the static_cast
in the return statement, so maybe not needed.
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.
Yeah, I justified it with the cast in each function (strictly speaking, naming the type twice breaks the DRY rule).
The real reason is that the last function breaks into multiple lines if I specify the return type :D
I don't have any good reasons to prefer one of the options here, let me know if you want to remove auto
s here.
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 approved the PR because I was fine with any outcome here. Just leave it as-is. 👍
Codecov Report
@@ Coverage Diff @@
## branch-22.06 #10804 +/- ##
================================================
+ Coverage 86.40% 86.45% +0.04%
================================================
Files 143 143
Lines 22448 22491 +43
================================================
+ Hits 19396 19444 +48
+ Misses 3052 3047 -5
Continue to review full report at Codecov.
|
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.
LGTM!
@gpucibot merge |
hostdevice_vector
members that are used for element access do not return const pointers/references when called on const objects.This PR makes sure all function members of
hostdevice_vector
are const correct: