参考书籍:《STL源码剖析》
参考源码: cygnus C++2.91.57 for Windows
I. 所在文件位置
// numeric
#ifndef __SGI_STL_NUMERIC
#define __SGI_STL_NUMERIC
// ......
#include <stl_numeric.h>
// ......
#endif /* __SGI_STL_NUMERIC */
// stl_nameric.h
#ifndef __SGI_STL_INTERNAL_NUMERIC_H
#define __SGI_STL_INTERNAL_NUMERIC_H
// ......
// accumulate 函数定义
// ......
#endif /* __SGI_STL_INTERNAL_NUMERIC_H */
accumulate
在 stl_numeric.h
文件中实现,但此文件为内部文件,STL 规定,想要使用就必须 #include <numeric>
。
II. 算法测试
/* 测试代码 */
#include <vector>
#include <numeric> // accumulate
#include <functional> // minus
using