iter_swap的要点是什么? [英] What's the point of iter_swap?
问题描述
我只是想知道,为什么会有人这样写:
I was just wondering, why would anybody write this:
std::iter_swap(i, k);
而不是这个?
std::swap(*i, *k); // saved a few keystrokes!
$ b < ,当然它只使用 swap
而不是 std :: swap
,因为我们已经在 namespace std
。这就引出了下一个问题:
Then I looked into the implementation of iter_swap
, and of course it only uses swap
instead of std::swap
since we're already in namespace std
, anyway. That leads me to the next question:
为什么会有人这样写:
using std::swap;
swap(a, b);
而不是这个?
std::iter_swap(&a, &b); // saved an entire line of code!
这里有什么重要的差异/问题吗?
Are there any important differences/issues I am overlooking here?
推荐答案
从SGI文档(此处) ):
From the SGI docs (here):
严格来说,iter_swap是多余的。它只因为技术原因而存在:在某些情况下,一些编译器难以执行解释交换所需的类型扣除(* a,* b)。
[1] Strictly speaking, iter_swap is redundant. It exists only for technical reasons: in some circumstances, some compilers have difficulty performing the type deduction required to interpret swap(*a, *b).
这篇关于iter_swap的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!