Skip to content

Feat/unique ptr #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed

Conversation

brodheadw
Copy link

This UniquePtr implementation integrates with radiant's allocator system and provides standard smart pointer semantics with move-only ownership, customizable deleters, and automatic resource cleanup. The implementation uses EmptyOptimizedPair to achieve zero storage overhead for empty deleters (sizeof(UniquePtr) == sizeof(T*)). It supports type-safe conversions for inheritance hierarchies and integrates with AllocTraits for allocator-aware construction through two make_unique overloads: standard (new/delete) and allocator-aware.

The implementation follows radiant conventions, using Get() instead of get(), avoiding std:: dependencies, and integrating with the existing AllocTraits system. AllocatorDeleter provides automatic cleanup for allocator-constructed objects.

Comprehensive tests cover basic functionality, move semantics, custom deleters, type conversions, allocator integration, and edge cases including allocation failures.

brodheadw added 16 commits May 8, 2025 15:45
…n requirement to Development Setup section of CONTRIBUTING.md
…d version requirement to Development Setup section of CONTRIBUTING.md"

This reverts commit 2c4c34f.
…n requirement to Development Setup section of CONTRIBUTING.md
- Create radiant/UniquePtr.h with the class template declaration,
  default and pointer‐taking constructors, destructor and move‐ops.
- Add placeholder comments for the missing member functions.
Change UniquePtr to inherit from an empty DefaultDelete deleter so sizeof(UniquePtr<T>) == sizeof(T*)

Fix ctor to initialize base deleter, not mistakenly pass pointer

Remove stored function-pointer field, rely on empty-base optimization

Update UniquePtrDefault alias to use the new DefaultDelete

Add test/test_UniquePtr.cpp covering basic lifetime, release/reset, move, swap and custom deleter size guarantee

test: revise tests for EBO-optimized DefaultDelete (drop old alias, move D and its count to namespace scope, simplify static_assert, update CustomDeleter test)
…sive tests

Introduce DefaultDelete<T> as an empty deleter type to enable empty-base-optimization

Refactor UniquePtr<T, Deleter> to inherit from Deleter, removing extra storage and ensuring sizeof(UniquePtr) == sizeof(T*)

Add move-ctor, move-assign, release, reset, swap, and nullptr conversion APIs

Provide ADL-friendly swap overload

Update alias UniquePtrDefault<T> to use default deleter

Add test/test_UniquePtr.cpp with GoogleTest suite covering basic lifetime, sizeof check, release/reset, move semantics, swap semantics, and custom deleter
…d of std traits

add converting constructor to DefaultDelete to allow DefaultDelete<Base> from DefaultDelete<Derived>

remove <type_traits> dependency and replace std::is_convertible_v with rad::IsConv

keep existing move and converting-move overloads unchanged; tests continue to pass
@brodheadw brodheadw closed this May 27, 2025
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