Motivation
switch_expression::append() expands a switch with additional case expressions:
auto expanded = ex.append(deferred::case_(11, body));
The generic name append does not describe what may be appended. A member named case_ would make the expression read more like the C++ construct it models:
auto expanded = ex.case_(11, body);
Proposed API
Consider either accepting a label and body directly:
template<typename Label, typename Body>
auto case_(Label&& label, Body&& body) const&;
template<typename Label, typename Body>
auto case_(Label&& label, Body&& body) &&;
or accepting already-constructed case expressions:
auto expanded = ex.case_(deferred::case_(11, body));
The direct label/body form is more concise and avoids the visually repetitive .case_(deferred::case_(...)).
Design considerations
- Existing cases must retain precedence over newly added cases.
- The operation should return a new flattened
switch_expression, matching current append() value semantics.
- The
const& overload should copy owned state; the && overload should move it.
- Move-only labels and bodies must work through the rvalue overload.
- Result types must be recomputed across the default, existing cases, and added case.
- Decide whether
append() remains as an alias, is deprecated, or is eventually replaced.
- The overload must not introduce ambiguity with the namespace-level
deferred::case_() factory.
Compatibility
Adding case_() alongside append() is backward compatible. Removing or renaming append() should be deferred to a major release.
Acceptance criteria
Motivation
switch_expression::append()expands a switch with additional case expressions:The generic name
appenddoes not describe what may be appended. A member namedcase_would make the expression read more like the C++ construct it models:Proposed API
Consider either accepting a label and body directly:
or accepting already-constructed case expressions:
The direct label/body form is more concise and avoids the visually repetitive
.case_(deferred::case_(...)).Design considerations
switch_expression, matching currentappend()value semantics.const&overload should copy owned state; the&&overload should move it.append()remains as an alias, is deprecated, or is eventually replaced.deferred::case_()factory.Compatibility
Adding
case_()alongsideappend()is backward compatible. Removing or renamingappend()should be deferred to a major release.Acceptance criteria
case_().case_()andappend()is documented.