简体   繁体   English

为什么没有类似于std :: string_view的视图<T>

[英]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_viewstd::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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM