Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

Implements static polymorphism in the C++ version using the Curiously Recurring Template Pattern (CRTP) as requested in issue #79.

Added missing Polymorph.h - Provides CRTP base class implementation
Enables compile-time polymorphism - Methods resolve statically without virtual function overhead
Preserves existing API - All current code using this->object() works unchanged
Comprehensive testing - Added test cases demonstrating functionality

Implementation Details

The Polymorph<TSelf> class provides:

  • object() method returning reference to derived class (TSelf&)
  • const object() method for read-only access
  • constexpr and noexcept qualifiers for optimal performance
  • Full compatibility with existing template hierarchy

Pattern Usage

template <typename TSelf, typename TElement>
class Base : public Polymorph<TSelf>
{
    void method() { 
        this->object().derivedMethod(); // Static dispatch
    }
};

class Derived : public Base<Derived, int>
{
    void derivedMethod() { /* implementation */ }
};

Test Plan

Basic CRTP functionality - Verified static dispatch works correctly
Collections pattern - Tested with simulated DoublyLinkedList methods
Compilation - Ensures no build errors with new header
Performance - All method calls resolve at compile time

🤖 Generated with Claude Code


Resolves #79

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

Issue: #79
@konard konard self-assigned this Sep 13, 2025
- Add missing Polymorph.h header with CRTP base class implementation
- Provide object() method for static polymorphism access to derived classes
- Enables compile-time polymorphic behavior without virtual function overhead
- Add comprehensive test cases demonstrating CRTP functionality
- Resolves issue #79: Attempt to use static polymorphism in C++ version

The implementation follows the Curiously Recurring Template Pattern where:
- Base classes inherit from Polymorph<TSelf>
- Methods can call this->object().Method() to invoke derived class methods
- All method resolution happens at compile time with no runtime overhead

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Attempt to use static polymorphism in C++ version Implement static polymorphism using CRTP pattern Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 15:47
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.

Attempt to use static polymorphism in C++ version

2 participants