Project

General

Profile

Task #2826

introduce ssize free function

Added by Mark Abraham 10 days ago.

Status:
New
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.

Also available in: Atom PDF