Visual Studio 2013中的默认移动构造函数(更新3) [英] Default Move Constructor in Visual Studio 2013 (Update 3)

查看:325
本文介绍了Visual Studio 2013中的默认移动构造函数(更新3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够在过去找到有关此问题的多个会话(例如这里),但这种对话是从很久以前。代码我有一个问题是:

  #include< utility> 
#include< iostream>

struct Foo
{
Foo()= default;
Foo(const Foo& o)
{
std :: cout< copy<< std :: endl;
}
Foo(Foo& o)
{
std :: cout< move<< std :: endl;
}
};

struct Bar
{
Foo foo;
};

int main(void)
{
Bar a;
Bar b(a);
Bar c(std :: move(a));
}



如果在Visual Studio 2013(更新3)中执行代码,出复制两种情况。如果标准从上面的链接中的答案没有改变,那么输出应该是复制,然后是移动。 Ideone似乎给出了正确的输出。这是只是Visual Studio尚未实现的东西,或者在我的代码有一些缺失? 我知道您不能将移动构造函数标记为默认,但这并不意味着编译器会不支持生成默认移动构造函数。

解决方案


我知道你不能标记move constructor默认情况下,但这并不意味着编译器不支持生成默认移动构造函数


不幸的是,手段。 VS2013不支持隐式生成移动构造函数和移动赋值运算符。如果是这样,他们真的没有理由不允许 = default 语法,特别是因为你被允许为复制构造函数和赋值运算符。 / p>

引用MSDN:对C ++ 11功能的支持(Modern C ++)


Rvalue references v3.0添加了新规则以自动生成移动构造函数和移动赋值运算符一定条件。但是,由于时间和资源限制,Visual Studio 2013中的Visual C ++不会实现。



I've been able to find multiple conversations about this in the past (e.g. here), but such conversations are from quite a while ago. The code I have a question about is:

#include <utility>
#include <iostream>

struct Foo
{
    Foo() = default;
    Foo(const Foo &o)
    {
        std::cout << "copy" << std::endl;
    }
    Foo(Foo &&o)
    {
        std::cout << "move" << std::endl;
    }
};

struct Bar
{
    Foo foo;
};

int main(void)
{
    Bar a;
    Bar b(a);
    Bar c(std::move(a));
}

If you execute the code in Visual Studio 2013 (Update 3), it prints out "copy" for both cases. If the standard hasn't changed since the answer in the link above, then the output should be "copy" followed by "move." Ideone seems to give the correct output. Is this just something that Visual Studio hasn't implemented yet, or is there something missing in my code? I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together.

解决方案

I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together

Unfortunately, that's exactly what that means. VS2013 does not support implicit generation of move constructors and move assignment operators. If it did, they wouldn't really have a reason to disallow the = default syntax, especially since you're allowed to do that for the copy constructor and assignment operator.

Quoting MSDN: Support For C++11 Features (Modern C++)

"Rvalue references v3.0" adds new rules to automatically generate move constructors and move assignment operators under certain conditions. However, this is not implemented in Visual C++ in Visual Studio 2013, due to time and resource constraints.

这篇关于Visual Studio 2013中的默认移动构造函数(更新3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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