为什么将std :: swap移至< utility&gt ;? [英] Why was std::swap moved to <utility>?

查看:83
本文介绍了为什么将std :: swap移至< utility&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么将 std :: swap 移到C ++ 11的< utility> 标头中?

Why has std::swap been moved to the <utility> header for C++11?

N3290 C.2.7说:

N3290 C.2.7 says:


17.6.3.2

17.6.3.2

对原始功能的影响:函数交换移至其他标头

Effect on original feature: Function swap moved to a different header

理论上:删除对<$ c $的依赖c>< algorithm> 进行交换。

Rationale: Remove dependency on <algorithm>for swap.

对原始功能的影响:有效的C ++ 2003代码已编译,希望进行交换放在< algorithm> 中可能必须改为包含< utility>

Effect on original feature: Valid C++ 2003 code that has been compiled expecting swap to be in <algorithm> may have to instead include <utility>.

我听不懂粗体部分。

推荐答案

委员会希望允许您使用 swap(),而不会对大型且更复杂的< algorithm> 头文件引入编译时依赖性。由于 swap()的使用如此广泛,因此让您以尽可能少的额外负担来拉入它的定义是很有意义的。对于通常不需要< algorithm> 的文件,这通常会缩短文件的编译时间。它的新家允许使用它而不会带来不必要的开销。

The committee wanted to allow you to use swap() without introducing a compile-time dependency on the large and more complex <algorithm> header file. Because swap() is so widely used, it makes sense to let you pull in its definition with as little additional baggage as possible; this will generally lead to faster compile times for files that don't otherwise need <algorithm>. Its new home allows it to be used without introducing unneeded overhead.

这篇关于为什么将std :: swap移至&lt; utility&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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