Use lambda to prevent ambiguity of unary operation
The reason of this MR is the following error
[4/5] Building CXX object plugins/cpu/CMakeFiles/ksystemstats_plugin_cpu.dir/cpu.cpp.o
FAILED: plugins/cpu/CMakeFiles/ksystemstats_plugin_cpu.dir/cpu.cpp.o
/usr/bin/c++ -DKCOREADDONS_LIB -DKF_DEPRECATED_WARNINGS_SINCE=0x60000 -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x56500 -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_DEPRECATED_WARNINGS_SINCE=0x60000 -DQT_DISABLE_DEPRECATED_BEFORE=0x50f02 -DQT_GUI_LIB -DQT_NO_URL_CAST_FROM_STRING -DQT_USE_QSTRINGBUILDER -DTRANSLATION_DOMAIN=\"ksystemstats_plugins\" -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -Dksystemstats_plugin_cpu_EXPORTS -I/home/albayenes/kde6/build/ksystemstats/plugins/cpu -I/home/albayenes/kde6/src/ksystemstats/plugins/cpu -I/home/albayenes/kde6/build/ksystemstats/plugins/cpu/ksystemstats_plugin_cpu_autogen/include -I/home/albayenes/kde6/build/ksystemstats -isystem /home/albayenes/kde6/qt6/include/QtCore -isystem /home/albayenes/kde6/qt6/include -isystem /home/albayenes/kde6/qt6/mkspecs/linux-g++ -isystem /home/albayenes/kde6/usr/include/KF6/KCoreAddons -isystem /home/albayenes/kde6/usr/include/KF6/KI18n -isystem /home/albayenes/kde6/usr/include/ksysguard -isystem /home/albayenes/kde6/qt6/include/QtDBus -isystem /home/albayenes/kde6/qt6/include/QtGui -pipe -fno-operator-names -fno-exceptions -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Werror=init-self -Wvla -Wdate-time -Wsuggest-override -Wlogical-op -fdiagnostics-color=always -g -std=gnu++20 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -MD -MT plugins/cpu/CMakeFiles/ksystemstats_plugin_cpu.dir/cpu.cpp.o -MF plugins/cpu/CMakeFiles/ksystemstats_plugin_cpu.dir/cpu.cpp.o.d -o plugins/cpu/CMakeFiles/ksystemstats_plugin_cpu.dir/cpu.cpp.o -c /home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp: In lambda function:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: error: no matching function for call to ‘transform_reduce(KSysGuard::AggregateSensor::SensorIterator&, const KSysGuard::AggregateSensor::SensorIterator&, double, std::plus<void>, <unresolved overloaded function type>)’
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/albayenes/kde6/qt6/include/QtCore/qhashfunctions.h:12,
from /home/albayenes/kde6/qt6/include/QtCore/qlist.h:10,
from /home/albayenes/kde6/qt6/include/QtCore/qobject.h:13,
from /home/albayenes/kde6/qt6/include/QtCore/QObject:1,
from /home/albayenes/kde6/usr/include/ksysguard/systemstats/SensorObject.h:11,
from /home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.h:10,
from /home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:8:
/usr/include/c++/13/numeric:370:5: note: candidate: ‘template<class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2> constexpr _Tp std::transform_reduce(_InputIterator1, _InputIterator1, _InputIterator2, _Tp, _BinaryOperation1, _BinaryOperation2)’
370 | transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:370:5: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: candidate expects 6 arguments, 5 provided
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:413:5: note: candidate: ‘template<class _InputIterator1, class _InputIterator2, class _Tp> constexpr _Tp std::transform_reduce(_InputIterator1, _InputIterator1, _InputIterator2, _Tp)’
413 | transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:413:5: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: candidate expects 4 arguments, 5 provided
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:439:5: note: candidate: ‘template<class _InputIterator, class _Tp, class _BinaryOperation, class _UnaryOperation> constexpr _Tp std::transform_reduce(_InputIterator, _InputIterator, _Tp, _BinaryOperation, _UnaryOperation)’
439 | transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:439:5: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: couldn’t deduce template parameter ‘_UnaryOperation’
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/numeric:739:
/usr/include/c++/13/pstl/glue_numeric_defs.h:35:1: note: candidate: ‘template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::transform_reduce(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _Tp)’
35 | transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/pstl/glue_numeric_defs.h:35:1: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: deduced conflicting types for parameter ‘_ForwardIterator1’ (‘KSysGuard::AggregateSensor::SensorIterator’ and ‘double’)
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/pstl/glue_numeric_defs.h:41:1: note: candidate: ‘template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::transform_reduce(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _Tp, _BinaryOperation1, _BinaryOperation2)’
41 | transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/pstl/glue_numeric_defs.h:41:1: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: deduced conflicting types for parameter ‘_ForwardIterator1’ (‘KSysGuard::AggregateSensor::SensorIterator’ and ‘double’)
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/pstl/glue_numeric_defs.h:47:1: note: candidate: ‘template<class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::transform_reduce(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Tp, _BinaryOperation, _UnaryOperation)’
47 | transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
| ^~~~~~~~~~~~~~~~
/usr/include/c++/13/pstl/glue_numeric_defs.h:47:1: note: template argument deduction/substitution failed:
/home/albayenes/kde6/src/ksystemstats/plugins/cpu/cpu.cpp:115:43: note: deduced conflicting types for parameter ‘_ForwardIterator’ (‘KSysGuard::AggregateSensor::SensorIterator’ and ‘double’)
115 | double sum = std::transform_reduce(begin, end, 0.0, std::plus{}, qvariant_cast<double>);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
Edited by Enes Albay