相关疑难解决方法(0)

在地图中使用unique_ptr时删除std :: pair中的函数

我有一段C++代码,我不确定它是否正确.请考虑以下代码.

#include <memory>
#include <vector>
#include <map>

using namespace std;

int main(int argc, char* argv[])
{
    vector<map<int, unique_ptr<int>>> v;
    v.resize(5);

    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

GCC编译这段代码没有问题.但是,英特尔编译器(版本19)因错误而停止:

/usr/local/ [...] /include/c++/7.3.0/ext/new_allocator.h(136): error: function "std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2> &) [with _T1=const int, _T2=std::unique_ptr<int, std::default_delete<int>>]" (declared at line 292 of "/usr/local/ [...] /include/c++/7.3.0/bits/stl_pair.h") cannot be referenced -- it is a deleted function
    { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
                            ^
      detected during:

[...]

instantiation of "void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type={std::size_t={unsigned long}}) [with _Tp=std::map<int, std::unique_ptr<int, std::default_delete<int>>, std::less<int>, std::allocator<std::pair<const int, std::unique_ptr<int, …
Run Code Online (Sandbox Code Playgroud)

c++ icc c++14

10
推荐指数
1
解决办法
621
查看次数

标签 统计

c++ ×1

c++14 ×1

icc ×1