Arm Mbed OS support forum

Std::span or mbed::Span

Hi there! –

While going through PR 13563, I came accross the mbed::Span struct.

I have a few questions:

  • which one should I use in my application code? std::span or mbed::Span?
  • what about unit testing outside of mbed os with mbed::Span
  • what about code portability?
  • what’s the rational behind reimplementing std structs like this one?
  • and finally, why the upper case S in Span? why not mbed::span or mbed::make_span instead of mbed::make_Span?

Thanks for the information :slight_smile:

– Ladislas

The mbed platform, like many other C++ projects, required a type that abstract a view to an array.

Several components defined their own array view as it is a common requirement on many projects and when std::span was proposed to the C++ standard we decided to provide a single implementation of this concept modeled after this interface.

There is a single difference between std::span and mbed::Span: size_type is equals to ptrdiff_t on mbed::Span while it is equals to size_t with std::span. We initially thought of using size_t to model size_type but the official proposal was at the time mandating ptrdiff_t and we opted to follow the standard to avoid compatibility issues in the future. After our initial publication of the code, the standard proposal was amended to use size_t.

We will eventually revisit mbed::Span to conform to the standard and propose an mstd::span like other mbed std primitives.

As to what to use now, I would stick with mbed::Span for now because std::span will be introduced with the C++20 standard that should be released later this year.

1 Like