Skip to content

Modernize to C++17: replace deprecated aligned_storage, add nodiscard#170

Open
HFTrader wants to merge 1 commit into
efficient:masterfrom
HFTrader:modernize-cpp17
Open

Modernize to C++17: replace deprecated aligned_storage, add nodiscard#170
HFTrader wants to merge 1 commit into
efficient:masterfrom
HFTrader:modernize-cpp17

Conversation

@HFTrader
Copy link
Copy Markdown
Contributor

Summary

Bump minimum standard from C++11 to C++17 and apply modernizations:

  • Replace std::aligned_storage (deprecated C++23, removed C++26) with alignas + std::byte arrays in bucket_container. Use std::launder for pointer access to constructed objects, and a separate storage_ptr() for construct/destroy on uninitialized storage
  • Add [[nodiscard]] to public query functions: hash_function(), key_eq(), get_allocator(), hashpower(), bucket_count(), empty(), size(), capacity(), load_factor(), contains()
  • Mark primary constructor explicit to prevent implicit conversion from size_type
  • Update CMake target_compile_features from cxx_constexpr to cxx_std_17

Test plan

  • All existing unit tests pass
  • Universal benchmark builds and runs
  • Verified with GCC 13.3

Bump minimum standard from C++11 to C++17 and apply modernizations:

- Replace deprecated std::aligned_storage (removed in C++26) with
  alignas + std::byte arrays in bucket_container. Use std::launder
  for pointer access to constructed objects, and a separate
  storage_ptr() for construct/destroy on uninitialized storage.

- Add [[nodiscard]] to public query functions: hash_function(),
  key_eq(), get_allocator(), hashpower(), bucket_count(), empty(),
  size(), capacity(), load_factor(), contains().

- Mark primary constructor explicit to prevent implicit conversion
  from size_type.

- Update CMake target_compile_features from cxx_constexpr to
  cxx_std_17.
@carlocorradini
Copy link
Copy Markdown

This is super useful since my compiler screams on every insert because of std::aligned_storage 😥

@carlocorradini
Copy link
Copy Markdown

carlocorradini commented May 13, 2026

@HFTrader Instead of forcing C++17, add a check to use alignas + std::byte instead of std::aligned_storage.
Do the same for [[nodiscard]] and other features that are only available from specific C++ versions.

I don't think they'll merge this, since forcing C++17 would be a breaking change.
It would be better to keep compatibility checks and use newer features only when the target C++ version supports them.

@HFTrader
Copy link
Copy Markdown
Contributor Author

@carlocorradini thanks for the feedback — and good point that a hard bump is the heavier ask of the two.

A couple of things worth weighing, though:

  1. std::aligned_storage is deprecated in C++23 (P1413), which is why your compiler is screaming. So the long-term direction is alignas + std::byte regardless — the question is just whether libcuckoo carries both code paths or picks one.
  2. [[nodiscard]] can be gated cleanly with __has_cpp_attribute(nodiscard) (or a LIBCUCKOO_NODISCARD macro), so that one is cheap to make conditional. Happy to do that.
  3. The std::aligned_storagealignas(T) std::byte[N][sizeof(T)] swap is also doable under C++11 — std::byte is C++17, but alignas + unsigned char works in C++11 and is functionally equivalent. The std::launder calls would need a __cpp_lib_launder guard (it's a no-op in practice pre-C++17, since the old reinterpret_cast path was what everyone relied on).

That said: the repo's last release was 2019 and there's a backlog of unmerged PRs, so I'm not optimistic either way. If a maintainer chimes in preferring the gated approach, I'm glad to rework it that way — just didn't want to add #if __cplusplus >= … scaffolding speculatively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants