std-span

What is a “span” and when should I use one?

喜夏-厌秋 提交于 2019-11-26 03:15:36
问题 Recently I\'ve gotten suggestions to use span<T> \'s in my code, or have seen some answers here on the site which use span \'s - supposedly some kind of container. But - I can\'t find anything like that in the C++ standard library. So what is this mysterious span<T> , and why (or when) is it a good idea to use it if it\'s non-standard? 回答1: What is it? A span<T> is: A very lightweight abstraction of a contiguous sequence of values of type T somewhere in memory. Basically a struct { T * ptr;