c++风格的函数签名,用于计算一组值的标量

C++11esque signature of a function computing a scalar of a collection of values

本文关键字:标量 一组 用于 函数 风格 c++ 计算      更新时间:2023-10-16

到目前为止,我已经猜到了

double mean(ConstIterator startIt, ConstIterator endIt);
对于计算STD集合中存储的一组值的均值的函数来说,

是一个不错的签名。

但是在c++ 11中,我们有lambda和for val : Col

这个函数的最佳实践签名是什么?

在得到范围之前,函数接受值的集合方面不会有太大的变化。

然而,除非函数是特定于某些类型的,否则通常这类事情是一般实现的:

template<typename Iterator, typename Sentinel>
auto mean(Iterator begin, Sentinel end) { // C++14 deduced return type
  // ...
}