Array-like data structure for fixed sized types with non-machine-word sizes
using namespace std; is a bad practice.

The code is plain C. You have two options:

Admit this fact, change your #includes to the C-style, and declare your functions as extern &quot;C&quot;. This way they are callable from both C and C++ code.

Make a class, and overload operator[](std::size_t) and operator[](std::size_t) const. The width shall be a class member. Much more C++ish.



An A parameter to getindex should be const-qualified.

Declare variables as close to use as possible. E.g. instead of
      uint64_t mask1;
      ....
      if () {
          ....
      } else {
          mask1 = ....;
      }

do
      ....
      if () {
      } else {
          uint64_t mask2 = ....