gpt4 book ai didi

c++ - 通过示例了解 std::move 及其用途

转载 作者:行者123 更新时间:2023-12-01 14:36:45 25 4
gpt4 key购买 nike

<分区>

考虑以下代码:

class c
{
large_type_t i;
public:
// the most simple variant
c( large_type_t i ): i( i ) { }
// move the parameter copied
c( large_type_t i ): i( std::move( i ) ) { }
// copy is done directly in interaction with our class member from original
c( const large_type_t &i ): i( i ) { }
// parameter was constructed in the call, just treat as rvalue
c( large_type_t &&i ): i( std::move( i ) ) { }
// this is here just to show all possible combinations in case someone in the future sees this question and someone answering it wants to explain everything
c( large_type_t &&i ): i( i ) { }
};

最好的方法是什么?无论如何,这些都将归结为相同的代码并且无关紧要吗?我觉得我根本没有理解移动的目的。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com