std::transform. std::transform applies the given function to a range and stores the result in another range, keeping the original elements order and beginning at d_first . 1) The unary operation unary_op is applied to the range defined by [first1, last1) .
static_cast is commonly used to cast between numerical types and covert void* to pointers pointing to a variable of a certain type. The user should pay attention to the range of the numerical type.
You cannot perform arithmetic on a void pointer because pointer arithmetic is defined in terms of the size of the pointed-to object.
I timed the difference between both implementations using google benchmark and came to the conclusion that the loop is about 5 times faster than using std::transform.
It is possible to overload operator,
. Casting either operand to void
prevents any overloaded operator from being called, since overloaded operators cannot take void
parameters.
It avoids call of overloaded operator,
if there is any. Because the type void
can't be an argument of a function (operator).
Another approach would be inserting void()
in the middle:
++__first, void(), ++__result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With