Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

📝 Summary

This PR replaces the LIMIT_AS_RANGE macro with a modern constexpr template function, addressing issue #76.

🔄 Changes Made

  • Removed: LIMIT_AS_RANGE macro and its #undef directive
  • Added: Internal::FullRange<T>() constexpr template function in the Internal namespace
  • Updated: All predefined range constants (SByte, Int16, Int32, etc.) to use the new function

✨ Benefits

  • Type Safety: Template function provides compile-time type checking vs. macro expansion
  • Debugging: Function calls are easier to debug and step through than macro expansions
  • Namespace Safety: Function is contained within Internal namespace, avoiding global pollution
  • Modern C++: Follows modern C++20 best practices by using constexpr functions over macros
  • Maintainability: Template function is more readable and maintainable than macro

🏗️ Implementation Details

The original macro:

#define LIMIT_AS_RANGE(type) std::numeric_limits<type>::lowest(), std::numeric_limits<type>::max()

Has been replaced with:

namespace Internal
{
    template<typename T>
    constexpr Range<T> FullRange() noexcept
    {
        return Range<T>(std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
    }
}

Usage changed from:

constexpr auto SByte = Range(LIMIT_AS_RANGE(std::int8_t));

To:

constexpr auto SByte = Internal::FullRange<std::int8_t>();

✅ Testing

  • ✅ Code compiles successfully with C++20 standard
  • ✅ All predefined ranges (SByte, Int32, UInt64, etc.) produce correct min/max values
  • ✅ Template function works correctly for all numeric types (signed/unsigned integers, floats)

📋 Fixes

Closes #76


🤖 Generated with Claude Code

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

Issue: #76
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 14:48
- Replaced the LIMIT_AS_RANGE macro with a template constexpr function FullRange()
- Added the function to Internal namespace to avoid polluting the public API
- Maintains the same functionality while providing type safety and better debugging
- Eliminates macro pollution and follows modern C++ best practices

Fixes #76

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

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Use function or method instead of macro Replace LIMIT_AS_RANGE macro with constexpr function Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 11:51
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 function or method instead of macro

2 participants