[英]Why there is no view<T> similar to std::string_view
I am aware that std::string_view
is a non-owning reference to a string and the major differences between std::string_view
and std::string
are 我知道
std::string_view
是对字符串的非拥有引用, std::string_view
和std::string
之间的主要区别是
Now, Why std::string_view is not applicable to other types ? 现在,为什么std :: string_view不适用于其他类型? or why this implementation is specific ONLY to
std::string
? 或者为什么这个实现只针对
std::string
?
For Example : if we have similar <T>generic_view
where T
can be of any type including custom types. 例如:如果我们有类似的
<T>generic_view
,其中T
可以是任何类型,包括自定义类型。
With this, instead of using const T&
as function argument, <T>generic_view
can be used. 这样,可以使用
<T>generic_view
,而不是使用const T&
作为函数参数。 And also other advantages of std::string_view
will be useful like Allocation, Copying etc.. 而且
std::string_view
其他优点也很有用,比如Allocation,Copying等。
There is a proposed non-owning type for contiguous collections of arbitrary objects. 对于任意对象的连续集合,存在建议的非拥有类型。
std::span
has been approved for C++20. std::span
已被批准用于C ++ 20。 (An implementation is available now, as gsl::span
.) (现在可以使用
gsl::span
作为实现。)
It behaves like C++17's std::string_view
, but the interface provides general container-like access, and doesn't restrict data access to const
. 它的行为类似于C ++ 17的
std::string_view
,但是该接口提供了类似于容器的通用访问,并且不限制对const
数据访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.