STL源码中 有很多传递调用,(侯捷著)其中有一种:
template
OutputIterator adjacent_difference_t(InputIterator first, InputIterator last, OutputIterator result)
{
if (first == last) return result;
result = *first;
return _adjacent_difference_t(first, last, result, value_type(first));
}
template
OutputIterator _adjacent_difference_t(InputIterator first, InputIterator last, OutputIterator result,T)
{
T value = *first;
while (++first != last)
{
T tmp = *first;
*++result = tmp - value;
value = tmp;
}
return result;
} 这是个判断相邻元素的差额的函数。在第一个中间有一个 value_type(first) 这个东西,我怎么也找到不到这个是从哪里来的,虽然下面给了一种直接写整个函数的方法,但是他这个value_type(first)的使用方法在其他函数似乎也有很大作用,本着求知的精神,希望有明白的人能够求解一下:这个value_type(first)是从哪里来的,同理还有search(),find_end()中好像也有这样的用法,不过在其他地方用的是distance_type( )罢了。
《STL源码剖析》中 adjacent_difference函数中的传递调用
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- Tsui丶 2017-08-14 05:33关注
这个value_type实际上就是一个pair用它可以给map插入一些值
http://blog.csdn.net/hzh2007/article/details/8671627 详细解答解决 无用评论 打赏 举报
悬赏问题
- ¥60 Python如何后台操作Vmwake虚拟机键鼠
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog
- ¥15 Excel发现不可读取的内容