Skip to content

New utility for pattern-matching style over std::variant#3237

Merged
daljit46 merged 3 commits intodevfrom
match_variant
Nov 27, 2025
Merged

New utility for pattern-matching style over std::variant#3237
daljit46 merged 3 commits intodevfrom
match_variant

Conversation

@daljit46
Copy link
Member

@daljit46 daljit46 commented Nov 26, 2025

This adds a new utility for pattern-matching style over std::variant, which is a type-safe version of a discriminated union introduced in C++17.

Example:

  std::variant<int, std::string> v = 42;
  auto s = MR::match_v(v,
       [](int i) { return std::to_string(i); },
       [](const std::string& s) { return s; });
  // s == "42"

@daljit46 daljit46 self-assigned this Nov 26, 2025
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@daljit46
Copy link
Member Author

@Lestropie Here, check_syntax is detecting an issue within a comment. Is this intended behaviour?

@Lestropie
Copy link
Member

Ideally it should skip single-line comments. This can be challenging in some circumstances though. Some check_syntax code prior to #3212 collapses all code onto a single line in order to do things like removal of block comments & some checks that could involve code distributed across multiple lines. However for some new checks in #3212 I needed the ability to disable checks on a per-line basis.

Given in this instance the code snippet provided in the comment would be flagged by check_syntax as problematic, I would suggest adding the same disabling code comment to that snippet. I can try to get the regexes to not check anything after a single-line comment (while preserving a possible line-disable trigger within such a comment), but regardless of that I think providing the requisite disable directive here makes sense.

Co-authored-by: Robert Smith <robert.smith@florey.edu.au>
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@daljit46 daljit46 merged commit ed02fd3 into dev Nov 27, 2025
6 checks passed
@daljit46 daljit46 deleted the match_variant branch November 27, 2025 09:48
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