假设m
类型为map<int, string>
,我们遇到了一个调用
copy(m.begin(), m.end(), back_inserter(x))
.
关于 x 的类型我们能说些什么?
如果copy(m.begin(), m.end(), back_inserter(x))
,请给我一个例子将是合法的。谢谢
最佳答案
What can we say about the type of x?
我们可以这样说:
-
m.value_type
是pair<const int, string>
,因此x.value_type
可能也是如此(不是严格要求,但在 STL 中是常规的)。 -
x.push_back(value_type)
必须有效,对于back_inserter(x)
去工作。
即x
上的唯一要求是它支持以下内容:
x.push_back(pair<const int, string>());
这个函数实际上做什么并不重要,但它必须有这个名称并支持这个参数类型。
关于c++11 - 将 MAP 容器复制到 X 的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37041438/