问题描述
根据cppreference,有void push(value_type&& value );
。但是当我使用 C++17 选项在 visual studio 2017
上优化我的代码时,我发现 g_queue.push(std::move(element))
实际上调用了 std::queue::push(const value_type&)
而不是 std::queue::push(const value_type&&)
。
对我来说,队列的 value_type
(即 T
)是 std::vector<char>
。
MSVC 没有 std::queue::push(const value_type &&)
真是令人惊讶!
而且根据MSDN,似乎没有std::queue::push(value_type&&)
确实。
更新:
我查看了由 MS 实现的 std::queue 的标题。确实没有 void push( value_type&& value )。标题路径是 c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\queue
第 130 行!
我用谷歌搜索,但遗憾的是我没有找到任何关于 Microsoft Visual Studio 在线标题的网站
而且 Perfomance Profiler
也骗不了我,它真的叫 std::queue::push(const value_type&)
。
一个演示片段正在路上。请给我两分钟时间。
#include<vector>
#include<queue>
#include<string>
int main()
{
std::queue<std::vector<char>> queue;
std::string str = "I need some help,thanks.";
std::vector<char> vec(str.begin(),str.end());
//The `Perfomance Profiler` provied by VC2017 Could not cheat me too.
//It really calls std::queue::push(const value_type&).
queue.push(std::move(vec));
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)