Skip to content

Conversation

@pbackus
Copy link
Owner

@pbackus pbackus commented Mar 4, 2025

This PR introduces three new convenience functions that allow code using SumType to be written in a more procedural style (as opposed to the functional style of match).

  • has!T checks whether a SumType contains a value of type T.
  • get!T accesses a SumType's value if it has type T, or asserts if it does not.
  • tryGet!T is like get!T, but throws an exception instead of asserting on failure.

To make room for get!T, the existing SumType.get method is renamed to getByIndex.

Phobos PR: dlang/phobos#10650

pbackus added 2 commits March 4, 2025 08:04
This change introduces three new convenience functions that allow code
using SumType to be written in a more procedural style (as opposed to
the functional style of match).

* has!T checks whether a SumType contains a value of type T.
* get!T accesses a SumType's value if it has type T, or asserts if it
  does not.
* tryGet!T is like get!T, but throws an exception instead of asserting
  on failure.

To make room for get!T, the existing SumType.get method is renamed to
getByIndex.

Frontend requirement is bumped to 2.103 for __traits(fullyQualifiedName).

Phobos PR: dlang/phobos#10650
@pbackus pbackus merged commit 699415a into master Mar 4, 2025
11 checks passed
@pbackus pbackus deleted the proc-api branch March 4, 2025 13:18
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