Skip to content

feat(ptr): not_null_ptr, fix not_null hash, make_not_null, release and swap - #17

Merged
codethinki merged 1 commit into
masterfrom
feat/not-null-ptr
Oct 18, 2026
Merged

codethinki merged 1 commit into
masterfrom
feat/not-null-ptr

Conversation

@codethinki

Copy link
Copy Markdown
Owner

Summary

  • not_null_ptr<T> = not_null<T*>. The argument names the pointee like move_ptr<T> and unique_not_null<T>, const goes in the argument: not_null_ptr<T const>. The converting constructor gives not_null_ptr<T> -> not_null_ptr<T const>.
  • fix: std::hash<not_null> used not_null::pointer, which does not exist, so no not_null was hashable. It hashes the value of get() now (the raw pointer for unique_not_null).
  • fix: make_not_null had Adapt without a default and not deducible, so no call compiled. The order is <Null = nullptr, Adapt = false, T> now: make_not_null(&x), make_not_null<VK_NULL_HANDLE>(handle). It is constexpr, and noexcept only when the constructor is (debug builds check the value).
  • fix: release() on a raw pointer did not compile: the noexcept spec called T::release() and the if constexpr had no else.
  • fix: swap() only took the default Null and Adapt.

For cth_engine, which replaces its not_null<X const*> with not_null_ptr<X const>.

Test plan

  • gcc and clang, debug and release: 271/271, 7 new tests (hash, release, make_not_null, custom Null swap, const conversion)
  • CI: Linux gcc/clang, Windows msvc/clang

…d swap

not_null_ptr<T> is not_null<T*>: the template argument names the pointee
like move_ptr<T> and unique_not_null<T>, const goes in the argument
(not_null_ptr<T const>).

fixes:
- std::hash<not_null> used not_null::pointer, which does not exist.
  It hashes the value of get() now: the pointer for unique_not_null.
- make_not_null had a non deducible Adapt without a default, so no call
  compiled. Null and Adapt come first now and have defaults, T is deduced.
  It is constexpr and noexcept only when the constructor is.
- release() on a raw pointer did not compile: the noexcept spec called
  T::release() and the if constexpr had no else.
- swap() only took the default Null and Adapt.
@codethinki
codethinki enabled auto-merge (squash) October 18, 2026 22:02
@codethinki
codethinki merged commit e6a384d into master Oct 18, 2026
6 checks passed
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.

1 participant