boost :: string_ref和boost :: string_view之间的区别 [英] Differences between boost::string_ref and boost::string_view

查看:159
本文介绍了boost :: string_ref和boost :: string_view之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Boost提供了 string_view 的两种不同实现,它们将成为C ++ 17的一部分:

    utility/string_ref.hpp 中的
  • boost :: string_ref core/string_view.hpp
  • 中的
  • boost :: string_view

这些之间是否有显着差异?未来应该优先选择哪个?

注意:我在Boost 1.61中注意到,boost :: log不推荐使用string_ref,而推荐使用string_view.也许这是一个指标?( http://www.boost.org/users/history/version_1_61_0.html)

解决方案

现在足够有趣了,我正与Marshall Clow(委员会的string_view等人背后的力量)在ACCU会议上他今天早些时候在酒吧被听见,然后才被我告知他对string_view和Bjarne的指南支持库(GSL) gsl :: span< T> 的看法,这是非常相似的事情(http://www.boost.org/users/history/version_1_61_0.html)

解决方案

Funnily enough right now I'm at the ACCU conference with Marshall Clow (the force behind string_view et al on the committee) and I was quite literally about to ask him at the bar earlier today before I was called away about his views on string_view versus Bjarne's Guideline Support Library (GSL) gsl::span<T> which is a very similar thing (gsl-lite is my personal favourite implementation of the GSL as it's 03 compatible, but there are many others). I had heard they were to be unified into a single implementation for standardisation, and the gsl::span<T> direction is to be the future, but I'll report back here from the horse's mouth himself if I'm wrong on that. For now, assume the gsl::span<T> direction is the current future and Boost will get updated to have something similar soon, even if using string_view = gsl::span<char> is essentially string_view.

Edit: I just spoke to Marshall downstairs. He tells me that string_view, as per the implementation in Boost, is definitely in C++ 17. array_view is not, nor is anything historically surrounding string_view for now.

The GSL string_span is a separate entity not expected to enter in C++ 17, nor are there any present plans to unify the implementations as they solve different use cases, specifically that string_view is always a constant view of the borrowed character array, whereas string_span is expected to be a potentially modifiable view of the borrowed character array with potential uses as a source for construction of new strings, so string_span might perhaps eventually become a generalisation of string_view in some future C++ standard.

这篇关于boost :: string_ref和boost :: string_view之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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