Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

This PR implements the requested changes from issue #63 to use safe specialization for C++ functors.

Changes made:

  • Replace unsafe namespace std { ... } syntax with safe template specialization template<...> struct std::hash<Type> { ... }
  • Updated both C# (CSharpToCppTransformer.cs) and Python (cs2cpp.py) implementations
  • Added test case to verify the transformation works correctly

Before (unsafe):

namespace std 
{
    template<...>
    hash<Type<...>>
    {
    }
}

After (safe):

template<...>
std::hash<Type<...>>
{
}

Test plan

  • Updated the regex patterns in both implementations
  • Added SafeHashSpecializationTest to verify the transformation
  • Ensured backwards compatibility with existing transformations
  • Verified the generated code uses the safer template specialization syntax

The safe specialization approach avoids namespace pollution and potential ADL (Argument-Dependent Lookup) issues while maintaining full functionality.

🤖 Generated with Claude Code


Resolves #63

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

Issue: #63
@konard konard self-assigned this Sep 13, 2025
Replace unsafe std namespace specializations with safe template
specialization syntax:
- Changed from 'namespace std { template<...> struct hash<Type> {...} }'
- To 'template<...> struct std::hash<Type> {...}'

This addresses issue #63 by using the safer approach that avoids
namespace pollution and ADL issues.

Changes made in both C# and Python implementations:
- CSharpToCppTransformer.cs: Updated regex to generate safe syntax
- cs2cpp.py: Updated SubRule to generate safe syntax
- Added test case to verify the transformation works correctly

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Use safe specialization for C++ functors Use safe specialization for C++ functors Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 09:20
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 safe specialization for C++ functors

1 participant