Sometimes I need a function or template which returns zero like in the example below (artificial, of course, for sake of simplicity).
I am fine to write everywhere []() { return 0.0f; }
, but taking into account that we have many predefined function objects for similar often used things like std::numeric_limits<T>::infinity
, etc., don’t we have something like std::zero<T>
which is recommended to use in such cases?
(I am not asking to introduce it, I just want to double check that I don’t miss recommended to use thing which could make code nicer).
#include <vector>
void add(std::vector<float>& v, std::size_t sz, auto gen) {
for (std::size_t i = 0; i < sz; ++i)
{
v.emplace_back(gen());
}
}
void main()
{
std::vector<float> v;
add(v, 5, []() { return 0.0f; });
}
13