martinmoene / span-lite

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
495 stars 40 forks source link

Fix construction from empty arrays in debug modes #57

Closed mjacobse closed 4 years ago

mjacobse commented 4 years ago

I had issues when constructing spans from std::arrays with size 0 in Visual Studio. In Debug builds it has its container debugging mode for the standard library enabled (_CONTAINER_DEBUG_LEVEL > 0) and breaks on an assertion error when operator[] is called with 0. I then tried the stdlibc++ debug mode (-D_GLIBCXX_DEBUG) and it shows the same problem. I guess that technically &arr[0] is not a bug, but practically it can become a problem with these debug modes. I couldn't think of a disadvantage of using .data(), so I propose to use that instead.

martinmoene commented 4 years ago

Thanks @mjacobse !