在C ++ 17中没有从std :: string到std :: string_view的隐式转换(在std :: experimental :: basic_string_view中) [英] No implicit conversion from std::string to std::string_view in C++17 (was in std::experimental::basic_string_view)

查看:178
本文介绍了在C ++ 17中没有从std :: string到std :: string_view的隐式转换(在std :: experimental :: basic_string_view中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是有关 C ++ 17 的: http://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view

从std :: basic_string到隐式转换的警告是什么std :: basic_string_view,它不包含在后者的界面中?

What's the caveat of implicit conversion from std::basic_string to std::basic_string_view that it wasn't included in the interface of the latter?

我相信它将大大改善此类。尤其是比较运算符系列,它们也不接受std :: string作为 lhs rhs 都不是。

I believe it would greatly improve this class. Especially the family of comparison operators that, also do not accept std::string as neither lhs nor rhs.

库基础知识TS 规范中有这样的转换: http ://en.cppreference.com/w/cpp/experimental/basic_string_view/basic_string_view

There is such conversion in library fundamentals TS specification: http://en.cppreference.com/w/cpp/experimental/basic_string_view/basic_string_view

此问题是关于为什么将其删除的问题。

This question is about why it was removed. Or rather not adopted.

推荐答案

basic_string_view 被认为是较低级别的类。 。字符串容器的提供者负责提供对 string_view 的隐式转换。如果您有自己的字符串类型,则可以给它一个 explicit 运算符string_view()重载以执行隐式

basic_string_view is considered the lower level class. It's the providers of string containers who have the responsibility of providing implicit conversions to string_view. If you have your own string type, then you would give it a possibly explicit operator string_view() overload to perform implicit conversion.

因此,决定(PDF) basic_string 会将转换为 basic_string_view 。原始的图书馆基础知识版本将隐式转换放在 basic_string_view 上,因为TS通常是扩展。如果没有有效地分叉该类型,就不会影响该类型。

As such, it was decided (PDF) that basic_string would provide the conversion to basic_string_view. The original Library Fundamentals version put the implicit conversion on basic_string_view, because a TS is usually an extension. It can't affect an existing type without effectively forking that type.

这篇关于在C ++ 17中没有从std :: string到std :: string_view的隐式转换(在std :: experimental :: basic_string_view中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆