Visual Studio 2012 是否正确执行此操作?标准::移动



我最近试图回答的一个问题似乎是vs2012的c ++ 11支持中的错误。

具体来说,它无法使用不可复制构造的value_type编译 std::map,尽管只有 std::move 用于插入到映射中。要么选择了错误的插入重载,要么编译器不考虑替代。

基本上,我不知道以下代码是否:

#include <iostream>
#include <memory>
#include <utility>
#include <type_traits>
class Foo {
};
using namespace std;
int main() {
    cout << is_constructible<pair<const int,unique_ptr<Foo> >, pair<const int,unique_ptr<Foo> >& >::value << 'n';
    cout << is_constructible<pair<const int,unique_ptr<Foo> >, pair<const int,unique_ptr<Foo> >&& >::value << 'n';
}

给出输出 01。

Visual Studio 输出(现场观看):

1
1

这显然是错误的,gccclang都给出了预期的结果。此错误和您看到的原始问题可能与这两个接受的错误报告有关。is_constructible的错误结果实际上可能与原始错误无关:

  • std::is_*constructible::value == true 对于抽象类。
  • VC11:map 和 unordered_map 操作器[] 要求mapped_type是 CopyConstructible 或 MoveConstructible b

最新更新