Skip to content

Gecode 7: scoped enums and descriptive constant names - #293

Draft
zayenz wants to merge 2 commits into
feature/breaking-7-09-bug-fixesfrom
feature/breaking-7-10-scoped-enums
Draft

zayenz wants to merge 2 commits into
feature/breaking-7-09-bug-fixesfrom
feature/breaking-7-10-scoped-enums

Conversation

@zayenz

@zayenz zayenz commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Unscoped enums leak their enumerators into the enclosing namespace and convert implicitly to int, hiding type mismatches and accidental integer arithmetic. This PR converts the remaining unscoped enums across the public and test headers to enum class and replaces heavily abbreviated constant names with descriptive ones.

Scoped enums

The remaining unscoped enums across Gecode's modules and test component become enum class, keeping their underlying values and order unchanged. To keep migrations manageable, using enum at each enclosing scope preserves existing spellings such as IRT_EQ, Gecode::SS_FAILED, and IntVarBranch::SEL_RND; in class templates, where using enum cannot name a dependent type, static constexpr aliases provide the same names.

What stops compiling is implicit conversion to int, arithmetic or bit shifts (such as 1 << RM_EQV), array indexing, streaming, and comparing across different enums. Call sites now convert explicitly with std::to_underlying or static_cast. Because installed headers use std::to_underlying, downstream projects need C++23 even if they do not consume Gecode through CMake.

IntPropLevel is the one enum that supports bitwise operations. It gets an unsigned int underlying type (matching the bit-fields in IntPropLevels), gains operator|, operator&, and operator|=, and drops IPL_BITS_ in favor of an internal constant. Testing a bit now requires an explicit comparison such as (ipl & IPL_BASIC) != IPL_DEF. ev_t is also renamed to Int::Cumulatives::EventType.

Descriptive constant names

Following the IRT_LE -> IRT_LT rename in #286, abbreviated enum constants are given descriptive names without compatibility aliases. Examples include RestartMode (RM_* -> RESTART_*, removing the prefix collision with ReifyMode), ReifyMode::RM_PMI -> RM_RIMP, TaskType (TT_FIXP/TT_FIXS/TT_FIXE -> TT_FIXED_PROCESSING/TT_FIXED_START/TT_FIXED_END), SetRelType (SRT_DISJ/SRT_CMPL -> SRT_DISJOINT/SRT_COMPLEMENT), and SetOpType (SOT_DUNION/SOT_INTER -> SOT_DISJOINT_UNION/SOT_INTERSECTION). Underlying values, printed output, and CLI option strings do not change; docs/code-style.md and changelog.in list every rename.

Stack

Merge in this order. #242 targets main, and each later PR builds on the one before it so its diff shows only its own commits. The first four PRs are standalone search and random-number changes; #284 through #274 are the Gecode 7 changes split out of what used to be a single branch.

  1. Rank solutions with Space::compare in best-solution search #242 Rank solutions with Space::compare
  2. Rename the meta-search hooks to hub and spoke #282 Rename the meta-search hooks to hub and spoke
  3. Give meta search hub and spoke contexts and report why search ended #283 Hub and spoke contexts and end reasons
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators
  5. Gecode 7: CMake-only C++23 build baseline #284 Gecode 7: build baseline
  6. Gecode 7: format the sources with LLVM 22 #285 Gecode 7: reformat
  7. Gecode 7: normalized API names, LT constants and Clang checks #286 Gecode 7: API names, LT constants, checks
  8. Gecode 7: post nothing for empty arrays #287 Gecode 7: empty arrays
  9. Gecode 7: pass large parameters by const reference #288 Gecode 7: const& parameters
  10. Gecode 7: state and assert the heap size contract #289 Gecode 7: heap contract
  11. Gecode 7: trivially copyable handles and defaulted special members #290 Gecode 7: modern classes
  12. Gecode 7: native float interval instead of Boost #291 Gecode 7: native float interval
  13. Gecode 7: bug fixes and Doxygen warnings #292 Gecode 7: bug fixes and Doxygen
  14. Gecode 7: scoped enums and descriptive constant names #293 Gecode 7: scoped enums ← this PR
  15. Gecode 7: clang-tidy sweep #274 Gecode 7: clang-tidy sweep

68 enums become enum class. using enum keeps existing spellings such as IRT_EQ and IntVarBranch::SEL_RND compiling; class templates use static constexpr aliases instead, since using enum cannot name a dependent type. Enumerator values and order do not change.

IntPropLevel is the only enum with operators and has an unsigned underlying type, because IntPropLevels stores levels in bit-fields. IPL_BITS_ is replaced by a private constant computed from the levels, and ev_t becomes EventType.

Other conversions are now explicit, and installed headers need C++23.

Zdev-Change-Id: Zbe6acb9cfd1f8806879c5c1a6bd306c2cf58f61134417b2e83c6ee379d2bce5f
Apply the approved constant renames with no compatibility aliases, following the IRT_LE to IRT_LT rename. RestartMode's RM_ constants become RESTART_, because ReifyMode shares that prefix, and truncated names such as SRT_DISJ and SOT_DUNION are spelled out. docs/code-style.md and the changelog list each rename.

Enumerator values, printed strings, and option values do not change.

Zdev-Change-Id: Z43bb475ac60ed9ff06a641cb09f52d90383860f01757f28f113e8f472c039503

This branch has not been deployed

No deployments
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.

1 participant