Skip to content

GH-48591: [C++] Use C++20 standard functions in bit_util.h#48611

Closed
imraniac wants to merge 1 commit intoapache:mainfrom
imraniac:cpp20-use-standard-bit-utils
Closed

GH-48591: [C++] Use C++20 standard functions in bit_util.h#48611
imraniac wants to merge 1 commit intoapache:mainfrom
imraniac:cpp20-use-standard-bit-utils

Conversation

@imraniac
Copy link

@imraniac imraniac commented Dec 20, 2025

Rationale for this change

This change replaces custom implementations of bit manipulation functions with C++20 standard library functions from the header. This will reduce the code complexity.

What changes are included in this PR?

Updated the cpp/src/arrow/util/bit_util.h file to replace the custom implementation for PopCount, CountLeadingZeros, and CountTrailingZeros with C++20 standard library functions std::popcount(), std::countl_zero() and std::countr_zero() respectively.

Are these changes tested?

Yes

Are there any user-facing changes?

No, this is an internal refactoring of bit utility functions.

@github-actions
Copy link

⚠️ GitHub issue #48591 has been automatically assigned in GitHub to PR creator.

@pitrou
Copy link
Member

pitrou commented Jan 12, 2026

Thanks for the PR @imraniac . This is fine, but I think in general we can simplify a bit further. Two suggestions:

  1. PopCount, CountLeadingZeros and CountTrailingZeros are now trivial wrappers around std functions, so how about we remove those wrappers and call the std functions directly?

  2. NumRequiredBits can similarly be replaced with std::bit_width, can you do this as well?

@pitrou
Copy link
Member

pitrou commented Jan 12, 2026

cc @zanmato1984 FYI

@pitrou
Copy link
Member

pitrou commented Feb 18, 2026

This PR is obsoleted by #49298, closing.

@pitrou pitrou closed this Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments