Skip to content

Patternia v0.9.3 Release Note

Release Date: May 2026 Version: 0.9.3


Overview

Patternia v0.9.3 adds the neg(p) negation pattern combinator, compile-time diagnostics for val<> misuse, variant dispatch optimization (16 to 8 threshold), and two new user guides (Performance Tuning and Common Mistakes). There are no breaking API changes.


New Features

neg(p) — Negation Pattern Combinator

Matches when the value does NOT match the sub-pattern.

// Match when value is NOT within range
auto result = match(x) | on(
  neg(val<1>) >> []{ return "not one"; },
  neg(val<2>) >> []{ return "not two"; },
  _           >> []{ return "one or two"; }
);

// neg(pred(...)): match when predicate fails
auto is_even = [](int x) { return x % 2 == 0; };
auto result = match(x) | on(
  neg(pred(is_even)) >> []{ return "odd"; },
  _                  >> []{ return "even"; }
);

Properties:

  • Single sub-pattern, zero binding (bind() returns empty tuple).
  • neg(neg(p)) is logically equivalent to p (double negation).
  • Fully compatible with existing combinators (any, all, structural bindings).

val<> Compile-Time Diagnostic

Now produces a clear compile-time error when val<> is misused with runtime values (e.g., val(argc)). Previously this would produce cryptic template instantiation errors. A compile-fail test verifies the diagnostic fires.


Test Coverage

154/154 tests passed, including:

  • 4 new neg(p) unit tests covering: basic negation, wildcard negation, pred negation, and double negation.
  • 1 compile-fail test for val<>(runtime_value) misuse.
  • All existing tests remain unchanged.

Documentation

  • Performance Tuning Guide (docs/guide/performance-tuning.md): covers PTN_ON macro usage, val<> vs lit() tradeoffs, structural binding performance, and variant dispatch optimization.
  • Common Mistakes Guide (docs/guide/common-mistakes.md): 6 common pitfalls including val<> runtime misuse, missing wildcards, lambda capture issues, $(pattern) vs $(binding), handler arity, and return type consistency.

Performance

  • Lowered k_variant_inline_dispatch_alt_threshold from 16 to 8. Variant matches with ≤ 8 alternatives now use branch-based dispatch instead of jump tables, reducing branch misprediction overhead for typical workloads.
  • See v0.9.3 Performance Note.