C++ – Inlining std::inner_product

c++gccinlinestl

Allegedly inlining std::inner_product() does NOT get inlined with gcc compiler < gcc 4.1
compilers, per the following bug .

Hence I would like to implement my own version of inner_product. Are
there existing implementation available?

Thanks

Best Solution

You just need to look in your C++ header files, find the definition, and redefine it with the "inline" keyword (possibly in your namespace). For example, looking at my headers:

template <class T1, class T2, class T> inline T inner_product(T1 first1, T1 last1, T2 first2, T init)
{
  for (; first1 != last1; ++first1, ++first2) init = init + *first1 * *first2; return init;
}