template<typename T> T atomic_fetch_max(std::atomic<T>* obj, typename std::atomic<T>::value_type arg) noexcept { auto prev = *obj;obj->load(std::memory_order_relaxed); while (prev < arg && !obj->compare_exchange_weak(prev, arg)) {} return prev; } template<typename T> T atomic_fetch_max(std::atomic<T>* obj, typename std::atomic<T>::value_type arg) noexcept { auto prev = *obj; while (prev < arg && !obj->compare_exchange_weak(prev, arg)) {} return prev; } template<typename T> T atomic_fetch_max(std::atomic<T>* obj, typename std::atomic<T>::value_type arg) noexcept { auto prev = obj->load(std::memory_order_relaxed); while (prev < arg && !obj->compare_exchange_weak(prev, arg)) {} return prev; } - Use
"\n"instead ofstd::endl; the latter is equivalent to the former, but also forces the output to be flushed, which is usually unnecessary and has a negative impact on performance. - You use
intin some places to hold sizes, like the loop iteratoriand as the value type of the vectorindex. If the text is larger than can be represented by anint, your code will no longer work correctly. Always prefer to usestd::size_tfor sizes, counts and indices. - You can avoid the atomic variable by changing the
for_each()into atransform_reduce(). However, it probably doesn't improve performance in a significant way.
- Use
"\n"instead ofstd::endl; the latter is equivalent to the former, but also forces the output to be flushed, which is usually unnecessary and has a negative impact on performance. - You use
intin some places to hold sizes, like the loop iteratoriand as the value type of the vectorindex. If the text is larger than can be represented by anint, your code will no longer work correctly. Always prefer to usestd::size_tfor sizes, counts and indices.
- Use
"\n"instead ofstd::endl; the latter is equivalent to the former, but also forces the output to be flushed, which is usually unnecessary and has a negative impact on performance. - You use
intin some places to hold sizes, like the loop iteratoriand as the value type of the vectorindex. If the text is larger than can be represented by anint, your code will no longer work correctly. Always prefer to usestd::size_tfor sizes, counts and indices. - You can avoid the atomic variable by changing the
for_each()into atransform_reduce(). However, it probably doesn't improve performance in a significant way.
Other issues
- Use
"\n"instead ofstd::endl; the latter is equivalent to the former, but also forces the output to be flushed, which is usually unnecessary and has a negative impact on performance. - You use
intin some places to hold sizes, like the loop iteratoriand as the value type of the vectorindex. If the text is larger than can be represented by anint, your code will no longer work correctly. Always prefer to usestd::size_tfor sizes, counts and indices.
Other issues
- Use
"\n"instead ofstd::endl; the latter is equivalent to the former, but also forces the output to be flushed, which is usually unnecessary and has a negative impact on performance. - You use
intin some places to hold sizes, like the loop iteratoriand as the value type of the vectorindex. If the text is larger than can be represented by anint, your code will no longer work correctly. Always prefer to usestd::size_tfor sizes, counts and indices.
Loading
lang-cpp