Project

General

Profile

Task #2826

introduce ssize free function

Added by Mark Abraham 3 months ago. Updated 26 days ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
core library
Target version:
-
Difficulty:
uncategorized
Close

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

Revision 35d429a0 (diff)
Added by Roland Schulz about 2 months ago

Add ssize and remove static_casts

Fixes #2826

Change-Id: I8cb3b64764798b164b355e71fb10874b49060a0a

Revision 55c76c88 (diff)
Added by Roland Schulz about 2 months ago

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 about 2 months ago

Gerrit received a related patchset '1' for Issue #2826.
Uploader: Roland Schulz ()
Change-Id: gromacs~master~I8cb3b64764798b164b355e71fb10874b49060a0a
Gerrit URL: https://gerrit.gromacs.org/9091

#2 Updated by Gerrit Code Review Bot about 2 months ago

Gerrit received a related patchset '1' for Issue #2826.
Uploader: Roland Schulz ()
Change-Id: gromacs~master~Icc5d0f9561c610cbce34c575d268171e9890ca9c
Gerrit URL: https://gerrit.gromacs.org/9093

#3 Updated by Roland Schulz about 2 months ago

  • Status changed from New to Resolved

#4 Updated by Paul Bauer 26 days ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF