boostorg / boostorg/container_hash

hash_combine, hash_range, and hash_value can be constexpr

Open
#16 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39
Forks
61
PR merge metrics
No merged PRs in 30d

Description

Since most part of internal calculations are based on integer arithmetic and bitwise operations, I believe those three functions and all their variants can be marked `constexpr` today. Can someone please enlighten me, why the standard `std::hash::operator()` and proposed `std::hash_combine()` in [P0814R2](https://wg21.link/p0814r2) is not `constexpr`? (backward-compatibility, or other reasons?)

If we are to provide constexpr-ness, there are two cases of implementations:
- When user is using standard later or equal to C++20
- In this case, non-constexpr intrinsic like `_rotl` (defined for `BOOST_FUNCTIONAL_HASH_ROTL32`) can be replaced with [`std::rotl`](https://en.cppreference.com/w/cpp/numeric/rotl)
- When user is using C++14 to C++17 and one *prefers* constexpr
- The library can fallback to bitwise implementation (which is always `constexpr`)
- Currently Boost.ContainerHash provides no option for this case. I think new macro like `BOOST_FUNCTIONAL_HASH_USE_CONSTEXPR` is needed.

refs: cplusplus/papers#253

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.