Task #2826
introduce ssize free function
Description
We often have to use static_cast<gmx::index>(i) < stdcontainer.size()
when we have indices declared as int.
At https://gerrit.gromacs.org/#/c/8826/3..9/src/gromacs/mdlib/nbnxn_search.cpp,unified, Roland suggested to avoid the cast we could add to basedefinitions:
template<typename T> gmx::index gmx::ssize(T t) { return t.size(); }
Then this can be if(ssize(nbl.cj) > ncj_old_j)
. This matches what will be in C++20 to solve this singed/unsigned issue.
This is not yet formally adopted for C++20 (but the standard library working group is in favour of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1227r0.html). But we could implement it as gmx::compat::ssize anyway.
Then we can eliminate a bunch of static_cast in favour of this less intrusive syntax.
Associated revisions
Revert size to be unsigned for ArrayRef
Given the decision for std::span to be signed this became
inconsistent with future C++ while already being inconsistent
with std::vector. The goal of the original change, to have
signed variables for all arithmetic including loop indices,
can be achieve by using ssize everwhere arithmethic is used.
ssize is both available as free function (also for std::vector)
and member function.
Related #2826
Change-Id: Icc5d0f9561c610cbce34c575d268171e9890ca9c
History
#1 Updated by Gerrit Code Review Bot 10 months ago
Gerrit received a related patchset '1' for Issue #2826.
Uploader: Roland Schulz (roland.schulz@intel.com)
Change-Id: gromacs~master~I8cb3b64764798b164b355e71fb10874b49060a0a
Gerrit URL: https://gerrit.gromacs.org/9091
#2 Updated by Gerrit Code Review Bot 10 months ago
Gerrit received a related patchset '1' for Issue #2826.
Uploader: Roland Schulz (roland.schulz@intel.com)
Change-Id: gromacs~master~Icc5d0f9561c610cbce34c575d268171e9890ca9c
Gerrit URL: https://gerrit.gromacs.org/9093
#3 Updated by Roland Schulz 10 months ago
- Status changed from New to Resolved
Applied in changeset 35d429a0bdd16f216bcc055c5c4018a10d0e02f1.
#4 Updated by Paul Bauer 10 months ago
- Status changed from Resolved to Closed
Add ssize and remove static_casts
Fixes #2826
Change-Id: I8cb3b64764798b164b355e71fb10874b49060a0a