Why std :: transform and similar increments for for for (void) loop?

What is the purpose of (void) ++__result in the code below?

Implementation for std :: transform:

 // std::transform template <class _InputIterator, class _OutputIterator, class _UnaryOperation> inline _LIBCPP_INLINE_VISIBILITY _OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) { for (; __first != __last; ++__first, (void) ++__result) *__result = __op(*__first); return __result; } 
+72
c ++
Jul 13 '16 at 16:27
source share
2 answers

You can overload operator, Casting or the void operand prohibits the call of any overloaded operator, since overloaded operators cannot accept void parameters.

+100
Jul 13 '16 at 16:31
source share

It avoids calling the overloaded operator, , if any. Since the void type cannot be an argument to a function (operator).

Another approach would be to insert void() in the middle:

 ++__first, void(), ++__result 
+5
Jul 14 '16 at 14:23
source share



All Articles