Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

  • Implements optional static polymorphism pattern for Memory classes instead of direct interface inheritance
  • Creates Polymorph<TSelf, TBase...> base class that enables compile-time polymorphic behavior
  • Updates all Memory classes to use the new pattern: ArrayMemory, FileArrayMemory, DirectMemoryAsArrayMemoryAdapter, HeapResizableDirectMemory, FileMappedResizableDirectMemory, TemporaryFileMappedResizableDirectMemory
  • Provides self() and as<T>() methods for accessing the derived type without runtime overhead

Implementation Details

  • Polymorph class: Template base class that inherits from multiple base classes and provides static polymorphism methods
  • Static polymorphism methods:
    • self() - returns reference to the derived type
    • as<T>() - allows casting to specific type at compile time
  • Zero runtime overhead: All polymorphic behavior is resolved at compile time
  • Backward compatibility: Maintains all existing functionality while adding static polymorphism capabilities

Example Usage

ArrayMemory<int> arrayMem(10);
auto& selfRef = arrayMem.self();           // Gets ArrayMemory<int>&
auto& asRef = arrayMem.as<ArrayMemory<int>>(); // Explicit type casting

Test plan

  • All modified classes compile successfully with C++20
  • Static polymorphism methods (self(), as<T>()) work correctly
  • Maintains compatibility with existing interface contracts
  • No runtime performance impact (compile-time polymorphism only)
  • All inheritance relationships preserved with new Polymorph pattern

🤖 Generated with Claude Code


Resolves #75

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #75
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 13:29
- Add Polymorph<TSelf, TBase...> base class for optional static polymorphism
- Update ArrayMemory, FileArrayMemory, DirectMemoryAsArrayMemoryAdapter to inherit from Polymorph
- Update ResizableDirectMemory derived classes to use Polymorph pattern
- Fix pointer_t visibility issues in DirectMemoryAsArrayMemoryAdapter
- Add type_traits include to ResizableDirectMemoryBase for compilation
- Remove UTF-8 BOM from ResizableDirectMemoryBase.h
- Include Polymorph.h in Platform.Memory.h

This implements the requested optional static polymorphism instead of direct interface inheritance, allowing compile-time polymorphic behavior without runtime overhead.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Use optional static polymorphism instead of direct inheritance from interface Implement optional static polymorphism instead of direct inheritance from interface Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 10:38
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.

Use optional static polymorphism instead of direct inheritance from interface

2 participants