为什么`std :: stringstream :: stringstream(std :: string&&)`不存在? [英] Why doesn't `std::stringstream::stringstream(std::string&&)` exist?

查看:102
本文介绍了为什么`std :: stringstream :: stringstream(std :: string&&)`不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望stringstream的构造函数可以从string&&窃取其初始内容.这样的物种间移动构造函数"在STL中通常不存在吗?如果没有,为什么不呢?

I was hoping stringstream has a constructor that steals its initial content from a string&&. Do such inter-species "move constructors" generally not exist in the STL? If not, why not?

推荐答案

有一段令人失望的历史.但未来也很光明.

There's history, which is disappointing. But also a future that looks bright.

当移动语义学进入C ++ 11时,它是巨大的,有争议的并且是压倒性的.我希望能够将字符串从stringstream移到中.但是,当时的政治要求内部存储必须basic_string<charT>.例如,内部存储可能是vector.而且没有能力用分配器控制事物.无论如何,在C ++ 11的时间框架内已经意识到了这种需求,但这只是一座桥梁.

When move semantics went into C++11, it was huge, controversial, and overwhelming. I wanted to be able to move strings into and out of stringstream. However the politics at the time demanded that the internal store did not have to be a basic_string<charT>. For example the internal store could be a vector. And there was no ability to control things with an allocator. In any event, the need was recognized in the C++11 time frame, but it was just a bridge too far.

幸运的是,彼得·索默拉德(Peter Sommerlad)通过 P0408 弥补了这一懈怠.该提议增加了您寻求的功能,希望能用于C ++ 20,但这还不确定.它已成功通过LEWG,并且现在在LWG的桌面上.他们本月未在拉珀斯维尔(Rapperswil)到达目的地,纯粹是因为日程安排过多.我希望它将通过LWG和全体委员会的投票.当然,我会投票.

Fortunately Peter Sommerlad has picked up the slack with P0408. This proposal adds the functionality you seek, hopefully for C++20, but that is not certain yet. It has successfully passed through the LEWG, and is on the LWG's desk right now. They did not get to it this month in Rapperswil, purely because of an overloaded schedule. I am hopeful that it will pass through the LWG, and the full committee vote. It certainly will have my vote.

这篇关于为什么`std :: stringstream :: stringstream(std :: string&amp;&amp;)`不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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