Skip to content

Refactor numeric type handling and enhance conversion modules#18

Merged
FrozenLemonTee merged 11 commits intomainfrom
refactor-complete-conversion
Mar 26, 2026
Merged

Refactor numeric type handling and enhance conversion modules#18
FrozenLemonTee merged 11 commits intomainfrom
refactor-complete-conversion

Conversation

@FrozenLemonTee
Copy link
Copy Markdown
Member

No description provided.

… maintainability

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…handling

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…s to enhance type handling

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…esentation bridges

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…es and improve type safety

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…nd floating point handling

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…type casting

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…nterface

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
… module

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
…conversions

Signed-off-by: FrozenlemonTee <1115306170@qq.com>
Copilot AI review requested due to automatic review settings March 26, 2026 14:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors numeric risk detection in the conversion subsystem to support underlying-type rep “bridging”, and adds new conversion modules to enable conversions between primitive<> wrappers and underlying types.

Changes:

  • Refactors conversion.underlying numeric risk handling to operate via underlying-type traits (including built-in proxy selection via common_rep_traits).
  • Adds new conversion modules for primitiveprimitive and primitiveunderlying casting (conversion.primitive, conversion.mixing) and exports them from conversion.
  • Extends test support types and adds new test coverage for numeric risk bridging and primitive/mixed conversions.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/conversion/underlying.cppm Refactors numeric risk logic and adjusts cast API surface to work via underlying traits.
src/conversion/mixing.cppm Adds overloads for casting between primitives and underlying types.
src/conversion/primitive.cppm Adds primitive-to-primitive cast wrappers built on underlying conversions.
src/conversion/conversion.cppm Re-exports the new conversion modules.
tests/basic/support/conversion_box_types.hpp Adds bridged rep/box test types + underlying/common-rep trait specializations.
tests/basic/conversion/traits/test_numeric_risk.cpp Adds tests for rep-bridge and built-in-proxy-bridge numeric risk detection.
tests/basic/conversion/primitive/test_primitive_casts.cpp Adds tests for primitive-to-primitive casting behavior.
tests/basic/conversion/primitive_underlying/test_mixed_casts.cpp Adds tests for underlying↔primitive mixed casting.
tests/basic/*/test_*.cpp (various) Minor whitespace cleanup around includes.
.gitignore Ignores cmake-build-* directories.
Comments suppressed due to low confidence (1)

src/conversion/underlying.cppm:207

  • The rep-level helpers (unchecked_rep_cast/checked_rep_cast/saturating_rep_cast/...) are constrained on numeric_underlying_type for both DestRep and SrcRep. These helpers are invoked with underlying::traits<...>::rep_type, which can be a custom numeric rep (i.e., not an underlying_type), so conversions involving custom reps will fail to compile (or be uncallable) even when a static_cast between reps exists. Consider relaxing these templates to accept arbitrary rep types (e.g., just require statically_castable), and keep numeric risk checking gated on std_numeric; then perform numeric_underlying_risk checks at the underlying-type layer when you want bridged risk detection.
template <numeric_underlying_type DestRep, numeric_underlying_type SrcRep>
  requires statically_castable<DestRep, SrcRep>
constexpr auto unchecked_rep_cast(SrcRep value) noexcept
    -> std::remove_cvref_t<DestRep> {
  using dest_type = std::remove_cvref_t<DestRep>;
  return static_cast<dest_type>(value);
}

template <numeric_underlying_type DestRep, numeric_underlying_type SrcRep>
  requires statically_castable<DestRep, SrcRep>
constexpr auto checked_rep_cast(SrcRep value)
    -> cast_result<std::remove_cvref_t<DestRep>> {
  using dest_type = std::remove_cvref_t<DestRep>;
  using src_type = std::remove_cvref_t<SrcRep>;

  if constexpr (std_numeric<dest_type> && std_numeric<src_type>) {
    if (auto const kind = numeric_risk<dest_type>(value); kind.has_value()) {
      return std::unexpected(*kind);
    }
  }

  return static_cast<dest_type>(value);
}

@FrozenLemonTee FrozenLemonTee merged commit a74666e into main Mar 26, 2026
7 checks passed
@FrozenLemonTee FrozenLemonTee deleted the refactor-complete-conversion branch March 26, 2026 14:26
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.

2 participants