VS11 issues a warning:
Warning 1 warning C4189: 'n': local variable initialized but not specified
Warning 2 warning C4244: '+ =': conversion from 'double' to 'int', possible data loss
Edit, actually this warning is to use the code:
template <typename T,typename Func> inline T sum(Func f, int initial, int end)
You get another conversion error warning if you use std::function<T (int)>
, so VS is still good at this problem. (IMO, you should usually use functors as a template type, not std :: function)
Even clang with -Weverything does not warn about this (Edit: although I cannot check the version of std :: function with clang ATM). It seems that something can be improved.
I get this strange warning, though:
ConsoleApplication1.cpp:15:51: warning: will never be executed [-Wunreachable-code] auto n = sum<int>([&](int k) { return arr1[k]*arr2[k]; }, // Precision loss! ^~~~
source share