It's pretty common I run into need to wrap C apis that only take 32bit integer, or 32bit unsigned arrays (or even smaller). But passing either std::span or std::vector into these APIs causes my compiler to warn me about mismatched sizes, std::size_t being different than std::int32_t for example. I'd like to find a library that provides the following:

  • versions of span, vector, array which contain additional template parameter for the size type.

  • versions of array and vector that have a fixed capacity, but variable size.

Does anything close to this exist for C++?

  • The Guidelines Support Library (GSL) has gsl::narrow wrapping a static_cast but also checking if information is lost when casting which can be useful for interfacing with C APIs.
    – paleonix
    Commented Feb 2 at 17:37
  • GSL has it's own span type and gsl-lite, a specific GSL implementation lets you customize its index type, but only as a preprocessor macro, not as a template argument.
    – paleonix
    Commented Feb 2 at 17:55

1 Answer 1


After a short search I found pector which allows specifying the size/index type as a template parameter to its vector equivalent. It doesn't have equivalents to span or array though. Luckily both span and array are comparatively easy to implement yourself as you do not need to take care of memory management.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.