Skip to content

Releases

v0.9.7

Choose a tag to compare

@sentomk sentomk released this 19 Nov 05:42
0b7f7ac

Patternia v0.9.7 Hotfix Release Note

Release Date: November 2026
Version: 0.9.7
Type: Hotfix


Overview

Patternia v0.9.7 is a hotfix release for v0.9.6. An installed copy of
v0.9.6 does not compile: four headers added in v0.9.6 were left out of
the install, so #include <ptn/patternia.hpp> fails with a
missing-file error. v0.9.7 installs every header. The library code is
the same as in v0.9.6.

If you use v0.9.6 through vcpkg, cmake --install or
find_package(patternia), upgrade to v0.9.7. Code that uses the source
tree directly (an include path, add_subdirectory or FetchContent)
was not affected.


Bug Fixes

Installed package missing headers

CMakeLists.txt installed the headers named in a hand-written list,
and the four headers added in v0.9.6 were never added to it:

  • ptn/core/common/index_switch.hpp
  • ptn/core/common/inline.hpp
  • ptn/core/common/owned_eval.hpp
  • ptn/pattern/plain_value.hpp

The public headers are now collected from include/ptn with
file(GLOB_RECURSE), so a new header is installed without a list to
update. (#113)


Internal Improvements

  • New CTest test install.consumer: it installs the build tree into a
    scratch prefix, checks that every header under include/ was
    installed, and builds and runs a program that finds the package with
    find_package(patternia). It runs with the rest of the suite on
    every CI configuration.

Documentation

  • The README is rewritten for v0.9.6, with the performance section
    moved up. (#111)
  • The documentation site moved to
    patternia.cc.
    (#109)

Impact

  • API surface: unchanged.
  • Runtime semantics and generated code: unchanged.
  • Install: cmake --install and package managers now ship every
    header.

v0.9.6

Choose a tag to compare

@sentomk sentomk released this 18 Nov 13:57
f56c42a

Patternia v0.9.6 Release Note

Release Date: November 2026
Version: 0.9.6


Overview

Patternia v0.9.6 makes case lists shorter and lets a match own its
subject:

  • $ can end a case list without a trailing _.
  • The right-hand side of >> accepts the same expressions as guards:
    $(pt)[x > 0] >> (x - y).
  • A plain value can stand wherever a pattern is expected:
    any('a', 'e', 'i'), is<int>(0).
  • match(std::move(value)) and match(make_value()) own the subject.
    Patterns and guards observe it, and only the selected handler can
    consume it, so move-only subjects such as std::unique_ptr work.

The release also reworks dispatch. Every keyed match (dense val<N>
literals, lit(...) literals, std::variant alternatives, borrowed
and owned subjects) now selects its case through one switch, and the
whole path is always inlined. The one exception is an owned variant
with four or fewer alternatives, which is evaluated in source order. On GCC this makes literal and variant
matches compile to the same code as a hand-written switch, where
v0.9.5 used chains or trees of comparisons and, depending on the
translation unit, wrote the case pack to the stack. With -g, GCC
also writes about 8 times less debug information for the same code.

There are no breaking API changes. A few behaviors changed; see
Behavior Changes.


New Features

$ as the final fallback

An unguarded $ (or $()) matches every value and binds the whole
subject, so it can end a case list on its own:

// v0.9.5
match(roll) | on(
  lit(3) >> add_fancy_hat,
  lit(7) >> remove_fancy_hat,
  $      >> [](int r) { move_player(r); },
  _      >> [] {}                           // required, unreachable
);

// v0.9.6
match(roll) | on(
  lit(3) >> add_fancy_hat,
  lit(7) >> remove_fancy_hat,
  $      >> [](int r) { move_player(r); }   // already the fallback
);

A guarded binding such as $[_ > 0] or a binding with a subpattern
such as $(is<int>) still needs a fallback. A trailing _ after $
remains valid.

Expression handlers

The right-hand side of >> accepts the expressions guards already
use, evaluated only when the case is selected:

match(n) | on(
  $[_ > 0] >> (_ * 2 + 1),
  $        >> -_
);

constexpr auto pt = has<&Point::x, &Point::y>;
auto [x, y] = pt;
match(p) | on(
  $(pt)[x > 0 && y > 0] >> (x + y),
  $(pt)[x > 0]          >> (x - y),
  $(pt)                 >> (x * x + y * y),
  _                     >> 0
);
  • _ is the first bound value; structural names resolve against the
    case's own pattern.
  • Arithmetic results keep their type; comparisons and logical
    expressions return bool and short-circuit. Parenthesize them after
    >>, as in $ >> (_ > 0), because >> binds tighter. + and -
    bind tighter than >>, but GCC's -Wparentheses (in -Wall) asks
    for parentheses around them too.
  • Unary + and - are new, in handlers and in guards.
  • Results are returned by value, so $ >> _ does not hand out a
    reference to a temporary binding.

Plain values inside patterns

Wherever a pattern is expected as an argument, an arithmetic,
enumeration or string-like value is treated as lit(value):

// v0.9.5
any(lit('a'), lit('e'), lit('i')) >> "vowel",
is<int>(lit(0))                   >> "int zero",

// v0.9.6
any('a', 'e', 'i')  >> "vowel",
is<int>(0)          >> "int zero",
alt<1>("hi")        >> "second is hi",
(lit(' ') || '\n')  >> "whitespace",
neg(0)              >> "nonzero",

any, all, neg, is<T>(p), alt<I>(p) and the right operand of
the pattern-level || / && accept plain values. !v is unchanged,
since ! on a built-in type cannot be overloaded.

Owning a subject

An rvalue subject is now owned by the match context instead of being
referenced:

auto task = std::make_unique<Task>();
match(std::move(task)) | on(
  $[([](const auto &p) { return p && p->ready(); })]
    >> [](std::unique_ptr<Task> p) { run(std::move(p)); },
  $ >> [](std::unique_ptr<Task> p) { defer(std::move(p)); }
);
  • Constructing the context moves the subject. Patterns and guards see
    it through const references; a rejected case leaves it intact for
    later cases; only the selected handler receives consuming bindings.
  • The same holds for variant alternatives ($(is<T>) binds the
    alternative as an rvalue), structural members, nested guards and the
    any, all and neg combinators.
  • A context can be stored and evaluated later; it keeps the subject
    alive. Results of an owning match are materialized before the
    context is destroyed.
  • A temporary or moved on(...) pack can hold move-only handlers and
    operator() && handlers; a stored pack keeps its handlers as
    lvalues for reuse.
  • Guards on owned subjects must accept read-only bindings; a guard that
    takes a binding by non-const reference is a compile-time error that
    says to consume the value in the handler.

Lvalue subjects are still borrowed, with const reference bindings.

Constant case packs

A case pack may be const or constexpr and reused:

constexpr auto classify = on(val<1> >> 1, val<2> >> 2, _ >> 0);
int a = match(x) | classify;
int b = match(compute()) | classify;

PTN_ON and static_on now cache their cases as const when no
handler keeps state, so the compiler treats them as constants.

Diagnostics for malformed cases

on(...) rejects an argument that is not a case before handler
deduction and dispatch planning start, with one diagnostic instead of
a cascade. on(0 >> 1, _ >> 0), where 0 >> 1 is C++'s built-in bit
shift, now says so and suggests lit(0) >> 1.


Behavior Changes

$(alt<I>) binds the alternative on borrowed subjects

$(alt<I>) now binds the selected alternative, as $(is<T>) does and
as it already did on owned subjects. Before, a borrowed match bound the
whole variant, so a handler for the alternative did not compile:

std::variant<int, std::string> v = 5;

// v0.9.5: did not compile; the handler had to take the variant
// v0.9.6: x is the int alternative
match(v) | on($(alt<0>) >> [](int x) { return x; }, _ >> 0);

A handler written for the old binding, taking the whole variant, has
to take the alternative instead.

Materialized bindings are forwarded

When a custom pattern's bind() returns a value (std::tuple<T>), the
handler now receives T&& instead of T&, on borrowed subjects too.
Handlers that take T, T&& or const T& are unaffected; a handler
taking a non-const T& must change. Built-in borrowed bindings remain
const references.

A valueless variant reaches the fallback

A borrowed match on a variant that is valueless_by_exception() used
to call std::abort(). It now evaluates the cases in order: type
patterns reject it and the _ or $ fallback runs.

static_on returns a const reference for stateless handlers

When no handler keeps state, static_on caches its cases as const
and returns a const reference. auto &cases = static_on(...) keeps
working; code that names a non-const reference type has to add
const. A handler with state keeps a mutable cache, as before.

A bool on the right of || and && is a value

With plain values accepted, (neg(0) && flag) means
all(neg(0), lit(flag)): the subject is compared with flag, which
is not tested as a condition.


Performance

On GCC, literal and variant matches now compile to the same code as a
hand-written switch. Instructions at -O2 on x86-64, v0.9.5 to
v0.9.6:

Match GCC 13 Clang 18
64 dense val<N> literals (switch: 6) 134 to 7 144 to 6
15 sparse lit(...) literals 47 (14 branches) to 6 40 to 39 (unchanged, a table)
16 variant alternatives 59 (8 branches) to 8 80 to 7

In CI's GCC 13 benchmarks, mixed-alternative variant workloads went
from about 2× the hand-written switch to parity. Owned subjects
dispatch like borrowed ones and run as fast as hand-written code on
Apple Clang. With GCC 13 at -O2 -g, the benchmark suite's object
file shrank from 686 MB to 92 MB and compiles in 5.8 s instead of
18.4 s.

On Apple Clang (arm64), a two-alternative variant match now compiles
to the same instructions as the hand-written switch and runs at its
speed (1.31 ns in the benchmark loop); v0.9.5's different sequence ran
at 0.92 ns there.

See the v0.9.6 performance note for the
measurements, the methods and what did not improve.


Bug Fixes

  • $(p) compiles for any subpattern: $(pred(...)), $(lit(3)),
    $(val<3>), $(any(...)), $(neg(...)) and $(_) bind the
    subject. They failed with "alt_index is not a member".
  • A file whose first include is <ptn/patternia.hpp> compiles with
    MSVC in C++20: common_traits.hpp now includes <cstdlib>.
  • On GCC, whether a literal match compiled to a table depended on the
    order of functions in the translation unit; the case pack is now
    stored in a type whose access is always inlined.

Internal Improvements

  • Dispatch: one index_visit switch for dense literals, lit(...)
    plans and variant alternatives, replacing the variant comparison
    chain, comparison tree and function-pointer table; the dispatch path,
    the owned evaluation path and their continuations are always inlined.
  • Codegen gate: scripts/check_codegen.py and 15 probes in
    tests/codegen/ compile representative matches at -O2 in CTest and
    fail when a match makes a call, uses the stack, branches more than a
    limit or grows past a hand-written reference.
  • Benchmarks: owning and borrowed matches, rejected guards, structural
    bindings and consuming handlers (bench/bench_ownership.cpp); the PR
    benchmark comparison now includes LiteralMatch64 and
    LiteralMatchRDense.
  • Tests: 439 tests (up from 256 in v0.9.5), including the 15 codegen
    probes.
  • Docs: the roadmap is organized by version; ...
Read more

v0.9.5

Choose a tag to compare

@sentomk sentomk released this 29 Oct 15:26
0a0650a

Patternia v0.9.5 Release Note

Release Date: October 2026
Version: 0.9.5


Overview

Patternia v0.9.5 is a naming-and-dispatch release. has<...> is now
tuple-like, so a C++17 structured binding names the members of a
structural pattern without a macro, and PTN_BIND is deprecated in
its favor. Handler classification is rewritten so generic lambdas,
pointers to members and reference-returning handlers work, and the bare
spellings is<T> and alt<I> reach the static variant dispatch fast
path that only is<T>() and alt<I>() used to get.

There are no breaking API changes. One behavior changed for code that
passed a pointer to member as a handler; see
Behavior Changes.


New Features

Structured-binding member names

has<...> implements the tuple-like protocol (std::tuple_size,
std::tuple_element and an ADL get). A structured binding declares
one member-anchored placeholder per non-ignored member:

struct Point { int x; int y; };

constexpr auto pt = has<&Point::x, &Point::y>;
auto [x, y] = pt;

match(p) | on(
  $(pt)[x * x + y * y == 25] >> "on circle",
  _                          >> "elsewhere"
);

Names follow the members listed in has<...>, and _ign slots do not
get a name:

constexpr auto pkt = has<&Pkt::type, &Pkt::len, ptn::_ign, &Pkt::crc>;
auto [type, len, crc] = pkt;   // three names, one per member

The names are placeholders, not values extracted from a subject;
$(pt) still decides which values reach the handler.

Scope rules:

  • Function-local auto [x, y] = pt; works with on(...), but not with
    PTN_ON(...), whose captureless lambda cannot see automatic
    bindings.
  • For PTN_ON, declare the pattern and its names at namespace scope.
  • In C++20, static constexpr auto pt = ...; plus
    static auto [x, y] = pt; also works inside a function.
  • In C++17, keep PTN_BIND for function-local names used inside
    PTN_ON.

Misuse is reported once, not as a cascade: a placeholder that does not
belong to the pattern, an out-of-range index into has<...>, or member
names on a non-structural pattern each produce a single diagnostic.
Guard diagnostics no longer mention PTN_BIND.

Handler forms

Handler classification no longer instantiates the handler to find out
what it is. This fixes three cases that did not work before:

  • A generic lambda that reads members of its argument now compiles
    inside on(...):

    match(v) | on(
      $(is<Circle>()) >> [](const auto &c) { return c.r; },
      $(is<Square>()) >> [](const auto &s) { return s.side; },
      _               >> 0
    );
  • Handlers that return a reference (a lambda returning const T &, or
    a pointer to a data member such as $ >> &Point::y) are accepted.

  • Pointers to members are handlers (see below).


Behavior Changes

Pointers to members are handlers

$(is<Circle>()) >> &Circle::area now calls area on the matched
value. Before, the pointer itself was the result of the case. Code that
relied on a case returning a member pointer has to wrap it in a lambda:

// v0.9.4: the case produced the member pointer
// v0.9.5: the case produces the call result
$(is<Circle>()) >> &Circle::area

// to keep the old meaning
$(is<Circle>()) >> [] { return &Circle::area; }

Deprecations

PTN_BIND

PTN_BIND is deprecated in favor of structured-binding member names.
It keeps working, and it remains the way to name placeholders inside a
function that uses PTN_ON in C++17. The removal version is not
decided.

// v0.9.4
PTN_BIND(Point, x, y);
$(has<&Point::x, &Point::y>)[x * x + y * y == 25]

// v0.9.5
constexpr auto pt = has<&Point::x, &Point::y>;
auto [x, y] = pt;
$(pt)[x * x + y * y == 25]

Performance

Bare is<T> and alt<I> are now stored as the canonical pattern types
that the dispatch optimizer recognizes. On an 8-alternative
std::variant, is<T> >> ... and alt<I> >> ... cases dispatch about
40% faster than in v0.9.4 and match the is<T>() / alt<I>() forms.
See the v0.9.5 performance note.


Bug Fixes

  • -Wextra -Werror users no longer fail on #include <ptn/patternia.hpp>:
    negation_pattern::bind named an argument it never used.
  • Two unsequenced double-forwards in guard and tuple evaluation, and an
    unconstrained forwarding constructor, found by the new clang-tidy
    gate, are fixed.

Internal Improvements

  • CI: clang-tidy gate on headers, tests and samples; a libFuzzer
    oracle target (fuzz/ptn_fuzz_match) with a smoke run on every PR and
    a weekly deep run; pinned developer tools and CI dependency versions;
    Linux matrix runners pinned to ubuntu-24.04.
  • Bench: the PR benchmark job compares base and PR on one runner and
    posts a sticky comment with the noise floor applied; generated charts
    moved off main to the bench-charts branch.
  • Tests: 256 tests (up from 204 in v0.9.4), including compile-fail
    cases that pin the diagnostics for invalid member names and out-of-range
    has<...> indices.
  • Docs: tutorials and the API reference use structured-binding names.

Migration Guide

Nothing needs to change to upgrade. To move off the deprecated macro:

// before
PTN_BIND(Point, x, y);
auto r = match(p) | on($(has<&Point::x, &Point::y>)[x < y] >> 1, _ >> 0);

// after: namespace scope, also valid inside PTN_ON
constexpr auto pt = has<&Point::x, &Point::y>;
auto [x, y] = pt;
auto r = match(p) | on($(pt)[x < y] >> 1, _ >> 0);

Inside a function that uses PTN_ON in C++17, keep PTN_BIND.

v0.9.4

Choose a tag to compare

@sentomk sentomk released this 01 Aug 10:21
0cd3b11

Patternia v0.9.4 Release Note

Release Date: August 2026
Version: 0.9.4


Overview

Patternia v0.9.4 is a guard-focused release. It introduces PTN_BIND
member-anchored named placeholders for structural guards, unifies the
placeholder syntax around _ and PTN_BIND, and adds operator sugar
(!p, (a || b), (a && b)) for the pattern combinators.

This release contains breaking changes; see
Breaking Changes and the
Migration Guide below.


Breaking Changes

Positional guard APIs removed

The positional guard spellings are removed in favor of _ and
PTN_BIND:

Removed Replacement
__ (double-underscore) _
_0 _
arg<N> PTN_BIND names
PTN_LET(v, expr) PTN_BIND + guard expression
PTN_WHERE((a, b), expr) PTN_BIND + guard expression

_ now serves both as the single-value guard placeholder and as the
wildcard fallback.

PTN_BIND names must be members of the type

PTN_BIND(Type, names...) expands each name to
member_t<&Type::name>. Placeholder names that were aliases rather
than real members of Type no longer compile; use the member names
themselves. Misspellings are now caught at the PTN_BIND line.


New Features

PTN_BIND(Type, names...) — named guard placeholders

Declares member-anchored named placeholders for guards attached to
has<...>, supporting one to ten names:

struct Point { int x; int y; };
PTN_BIND(Point, x, y);

match(p) | on(
  $(has<&Point::x, &Point::y>)[x * x + y * y == 25] >> "on circle",
  _ >> "elsewhere"
);

Names follow members, not positions: each name resolves to the
position of its member in the has<...> member list at compile time,
so the order of member pointers in has<...> does not matter:

$(has<&Point::y, &Point::x>)[x == 3 && y == 4]  // x is still .x

Misuse is caught at compile time: a misspelled member name fails at
the PTN_BIND line, and a name whose member is not listed in
has<...> fails a static_assert.

Declarations are valid at namespace or block scope. Block-scope
declarations use static storage duration, so they can be referenced
inside PTN_ON's captureless caching lambda:

int classify(const Point &p) {
  PTN_BIND(Point, x, y);
  return match(p) | PTN_ON(
      $(has<&Point::x, &Point::y>)[x * x + y * y == 25] >> 1,
      _ >> 0);
}

Operator sugar for combinators

The pattern algebra now has operator forms:

match(status) | on(
  !val<200>                  >> "error",     // !p     == neg(p)
  (lit(301) || lit(302))     >> "redirect",  // (a||b) == any(a, b)
  (pred(is_json) && !lit(0)) >> "json",      // (a&&b) == all(a, b)
  _                          >> "ok"
);

The operators only accept pattern operands, so guard-level && / ||
inside [...] keep their existing meaning. Note that >> binds
tighter than || and &&, so combined patterns need parentheses in a
case; unary ! needs none.


Internal Improvements

  • CI: commit-style PR validation, clang-format check, LLVM
    source-based coverage, and a fix letting docs-only PRs satisfy
    branch protection.
  • Bench: compile-time translation units are generated into the build
    tree instead of the source tree.
  • Docs: contributing guide now documents the CI-enforced PR rules.

Migration Guide

PTN_LET / PTN_WHERE

// v0.9.3
auto g1 = PTN_LET(v, v == 1);
auto g2 = PTN_WHERE((x, y), x < y);

// v0.9.4 — single bound value: use `_`
$[_ == 1] >> ...;

// v0.9.4 — multiple bound values: declare names once
PTN_BIND(Point, x, y);
$(has<&Point::x, &Point::y>)[x < y] >> ...;

arg<N> / _0 / __

// v0.9.3
$[_0 > 0] >> ...;
$(has<&Point::x, &Point::y>)[arg<0> < arg<1>] >> ...;

// v0.9.4
$[_ > 0] >> ...;
PTN_BIND(Point, x, y);
$(has<&Point::x, &Point::y>)[x < y] >> ...;

Alias-style PTN_BIND names

// main-between-releases only (never in a tagged release):
PTN_BIND(Point, point_x, point_y);   // alias names

// v0.9.4 — names must be members of Point:
PTN_BIND(Point, x, y);

v0.9.3

Choose a tag to compare

@sentomk sentomk released this 04 May 14:34

Summary

Patternia v0.9.3 — cumulative release since v0.9.2. Adds pred(callable) first-class predicate, neg(p) negation combinator, literal_runtime_dense dispatch tier, variant inline dispatch optimization, val<> compile-fail diagnostic, and comprehensive documentation.

Changes

New Features & API

Feature PR Description
pred(callable) #15 First-class predicate pattern — match via user-defined callable
neg(p) #29 Negation pattern combinator — invert sub-pattern result. Composable with any/all, zero binding
literal_runtime_dense dispatch #24 New optimization tier for runtime literal pattern dispatch
val<> compile-fail diagnostic #29 Clear compile-time error when val<> is misused with runtime values

Performance Optimizations

Change Description
Runtime range check optimization Replace two-sided comparison with single unsigned comparison
PTN_ON matcher inline Skip static_on function boundary for zero-overhead cached path
val<n> standard literal dispatch #26 Use val shorthand for literal match dispatch
Variant inline threshold 16 → 8 Hot inline dispatch path for ≤8 alternatives

Documentation

File Description
docs/changelog/v0.9.3.md Full v0.9.3 release note
docs/guide/performance-tuning.md PTN_ON, val vs lit, structural bindings, variant dispatch
docs/guide/common-mistakes.md 6 common pitfalls with code examples
docs/performance/v0.9.3.md Variant dispatch threshold tuning analysis
docs/api/api.md neg(p) API reference added
README.md neg example, version tag 0.9.3

Infrastructure

Change Description
CT benchmarks + lit bench expansion #22 Compile-time benchmark harness + expanded literal-match scenarios
PR template #19 Standardized PR description template
Coverage badge + benchmark chart CI-collected coverage and performance data in README

Tests

  • 4 new neg(p) unit tests: basic, neg(_), neg(pred(...)), neg(neg(p))
  • 1 compile-fail test: val<>(runtime_value)
  • CT benchmark static_assert probes
  • Full ctest: 154/154 pass, no regressions

Risk

Low. All new features are additive — no breaking API changes. Performance optimizations are internal dispatch changes, existing behavior unchanged.

Checklist

  • Tests added or updated when behavior changed
  • Documentation updated when public API or behavior changed
  • Commit messages follow CONTRIBUTING.md
  • PR targets main and passes required CI

v0.9.2

Choose a tag to compare

@sentomk sentomk released this 10 Apr 12:53

Patternia v0.9.2

Patternia v0.9.2 ships the any(ps...) / all(ps...) pattern combinators with full test coverage and API documentation. any combines multiple patterns with OR semantics; all combines them with AND semantics. Both are non-binding, short-circuit on evaluation, and compose naturally with val<>, lit(), lit_ci(), is<T>, and each other.

Highlights

  • Added any(ps...) pattern combinator — matches when at least one sub-pattern matches; short-circuits on the first hit.
  • Added all(ps...) pattern combinator — matches only when every sub-pattern matches; short-circuits on the first miss.
  • Both combinators are non-binding: handlers receive zero arguments.
  • Both require at least one sub-pattern; every argument must be a pattern object (enforced via static_assert).
  • Added 21 runtime tests and 4 compile-fail tests covering short-circuit evaluation, nested composition, pattern reuse, PTN_ON(...) integration, and static argument validation.
  • Added "Pattern Combinators" section to the API reference.
  • Updated namespace summary and roadmap to reflect the stabilized API.
  • Updated version metadata to 0.9.2.

API Notes

OR combinator with any(...):

using namespace ptn;

const char *classify(int x) {
  return match(x) | on(
    any(val<1>, val<2>, val<3>) >> "small",
    _ >> "other"
  );
}

AND combinator with all(...):

using namespace ptn;

const char *check(int x) {
  return match(x) | on(
    all(any(val<1>, val<2>), val<2>) >> "two",
    _ >> "other"
  );
}

Nested composition with variant patterns:

using namespace ptn;

const char *describe(const std::variant<int, std::string, double> &v) {
  return match(v) | on(
    any(is<int>, is<double>) >> "numeric",
    is<std::string> >> "string",
    _ >> "other"
  );
}

Cached case pack with PTN_ON(...):

using namespace ptn;

int fast_classify(int x) {
  return match(x) | PTN_ON(
    any(val<1>, val<2>, val<3>) >> 1,
    _ >> 0
  );
}

Performance

No intended performance changes. any and all use fold expressions over || and && respectively, preserving left-to-right short-circuit evaluation with no heap allocation or virtual dispatch.

Compatibility

This is an additive release. No existing API surface is removed or changed.

New Notes
any(ps...) Function template; at least one pattern argument required
all(ps...) Function template; at least one pattern argument required

Install

vcpkg install patternia
find_package(patternia CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE patternia::patternia)

Docs

v0.9.1

Choose a tag to compare

@sentomk sentomk released this 18 Mar 11:16

Patternia v0.9.1

Patternia v0.9.1 is an API refinement and release-alignment update. It completes the roadmap transition from
lit<V>() to val<V>, keeps has<...> as the canonical structural variable-template entry, adds C++20 floating-
point support for val<V>, and updates release packaging metadata for the published 0.9.1 version.

Highlights

  • Added val<V> as the canonical compile-time literal pattern entry.
  • Removed lit<V>(); use val<V> instead.
  • Added C++20 floating-point support for val<V>.
  • Kept lit(value) and lit_ci(value) unchanged as runtime literal forms.
  • Kept has<&T::m...> as the canonical structural entry; the old has<...>() factory spelling is no longer part of
    the public API.
  • Updated docs, examples, and benchmarks to use val<V> and the canonical structural syntax.
  • Updated release metadata to 0.9.1.
  • Updated local vcpkg packaging metadata and source archive checksum for the published v0.9.1 tag.

API Notes

Static literal matching with val<V>:

using namespace ptn;

int classify(int x) {
  return match(x) | on(
    val<1> >> 1,
    val<2> >> 2,
    _ >> 0
  );
}

C++20 floating-point static literal matching:

  using namespace ptn;

  const char *tag(double x) {
    return match(x) | on(
      val<3.25> >> "three-point-two-five",
      _ >> "other"
    );
  }

Structural matching with canonical has<...> syntax:

  using namespace ptn;

  struct Point { int x; int y; };

  int sum(const Point &p) {
    return match(p) | on(
      $(has<&Point::x, &Point::y>) >> [](int x, int y) {
        return x + y;
      },
      _ >> 0
    );
  }

Migration

  • Replace lit() with val:

    // before
    lit<1>() >> 1

    // after
    val<1> >> 1

  • Replace has<...>() with has<...>:

    // before
    $(has<&Point::x, &Point::y>()) >> handler

    // after
    $(has<&Point::x, &Point::y>) >> handler

  • In C++17, continue to use runtime literals for floating-point values:

    // C++17
    lit(3.25) >> "three-point-two-five"

  • In C++20 or later, floating-point static literals are available:

    // C++20+
    val<3.25> >> "three-point-two-five"

Performance

No intended performance changes. val reuses the same static literal pattern machinery as the old lit() entry, so
literal lowering behavior remains the same.

Compatibility

This is a breaking release for code that still uses the removed compile-time factory forms.

Removed Replacement
lit() val
has<&T::m...>() has<&T::m...>

C++20 adds new capability:

New Availability
val<3.25> C++20 and later

Install

vcpkg install patternia

find_package(patternia CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE patternia::patternia)

Docs

  • Release note: docs/changelog/v0.9.1.md

v0.9.0

Choose a tag to compare

@sentomk sentomk released this 13 Mar 13:25

Patternia v0.9.0

Patternia v0.9.0 is an API modernization and compiler compatibility release. It introduces PTN_WHERE and PTN_LET as named guard macros, removes the legacy bind() entry point and positional guard aliases, fixes callable guard evaluation on MSVC, and adds vcpkg packaging support.

Highlights

  • Added PTN_WHERE((names...), expr) for naming guard arguments without writing a lambda (supports 1 to 5 bound values).
  • Added PTN_LET(name, expr) as single-value shorthand for PTN_WHERE((name), expr).
  • Added is<T>, as<T>, alt<I> variable templates, replacing the type::is<T>() / type::as<T>() / type::alt<I>() function syntax.
  • Added $(pattern) callable syntax for $, replacing bind(pattern).
  • Added implicit lit wrapping so value >> handler works without explicit lit(value).
  • Removed bind() entry point; use $ instead.
  • Removed _1, _2, _3 guard aliases; use arg<N> or PTN_WHERE instead.
  • Removed type:: namespace, ds<>(), chained match syntax, and variadic match(subject, cases...) entry.
  • Fixed callable guards failing to dispatch bound values in composed guard expressions (&&, ||) on all compilers.
  • Fixed std::apply-based tuple guard calls producing ICEs on MSVC conformance builds.
  • Fixed PTN_WHERE argument counting under MSVC traditional preprocessor mode.
  • Added vcpkg support (vcpkg install patternia).

API Notes

Named guard with PTN_WHERE:

using namespace ptn;

struct Point { int x; int y; };

bool on_diagonal(const Point &p) {
  return match(p) | on(
    $(has<&Point::x, &Point::y>())[PTN_WHERE((x, y), x == y)] >> true,
    _ >> false
  );
}

Single-value guard with PTN_LET:

using namespace ptn;

const char *bucket(int x) {
  return match(x) | on(
    $[PTN_LET(value, value < 0)] >> "negative",
    $[PTN_LET(value, value < 10)] >> "small",
    _ >> "large"
  );
}

Migration

  • Replace bind() / bind(subpattern) with $ / $(subpattern):
    // before
    bind()[_0 > 0] >> [](int v) { return v; }
    // after
    $[_0 > 0] >> [](int v) { return v; }
  • Replace _1, _2, _3 with arg<N> or PTN_WHERE:
    // before
    $(has<&Point::x, &Point::y>())[_1 == _2] >> "diagonal"
    // after
    $(has<&Point::x, &Point::y>())[PTN_WHERE((x, y), x == y)] >> "diagonal"
  • Replace type::is<T>() / type::as<T>() with is<T> / as<T> variable templates.
  • Replace ds<&T::m...>() with has<&T::m...>().
  • Replace match(subject, cases...) with match(subject) | on(cases...).

Performance

No performance regressions. Guard dispatch rewrites replace std::apply and std::invoke with direct index-sequence expansion, which generates identical or better codegen on MSVC.

Compatibility

This is a breaking release. The following APIs have been removed:

Removed Replacement
bind() $
bind(subpattern) $(subpattern)
_1 / _2 / _3 arg<N> or PTN_WHERE
type::is<T>() / type::as<T>() is<T> / as<T>
ds<&T::m...>() has<&T::m...>()
match(subject, cases...) match(subject) | on(...)
Chained .when(...).otherwise(...) match(subject) | on(...)

Install

vcpkg install patternia
find_package(patternia CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE patternia::patternia)

Docs

  • Release note: docs/changelog/v0.9.0.md

v0.8.3

Choose a tag to compare

@sentomk sentomk released this 08 Mar 17:29

Patternia v0.8.3

Patternia v0.8.3 is an API ergonomics release that introduces shorter, more expressive syntax for common pattern matching operations. All additions are backward-compatible; existing code continues to compile without changes.

Highlights

  • Added match(subject, cases...) as a unified entry point, eliminating the need for builder chains or the pipe operator.
  • Added _ as a wildcard alias for __.
  • Added $ as a concise shorthand for bind().
  • Added _0, _1, _2, _3 as guard placeholder aliases for arg<0> through arg<3>.
  • Deprecated the bare _ guard placeholder (placeholder_t) in favor of _0.
  • Fixed pred_and / pred_or failing to unwrap tuple when invoking raw callables in mixed guard expressions (e.g., _0 > 1u && is_even).

API Notes

Recommended form in v0.8.3:

match(x,
    lit(1) >> 100,
    lit(2) >> 200,
    _ >> 0
);

Value capture with guard:

match(x,
    $[_0 > 0 && _0 < 10] >> [](int v) { return v * 2; },
    _ >> 0
);

All existing forms remain available:

match(x) | on(lit(1) >> 100, __ >> 0);
match(x).when(lit(1) >> 100).otherwise(0);

Migration

  • Replace _ in guard expressions with _0:
    // before
    bind()[_ > 0 && _ < 10]
    // after
    $[_0 > 0 && _0 < 10]
  • No other changes are required. The old _ guard placeholder still compiles but emits a deprecation warning.

Performance

No performance changes in this release. The new match(subject, cases...) entry constructs the same tuple<Cases...> and selects the same dispatch_plan as the existing match(x) | on(...) path. Lowering behavior is identical.

Compatibility

  • No forced migration is required.
  • __, bind(), arg<N>, type::is<T>(), type::as<T>() all remain available.
  • Guard placeholder _ is deprecated; use _0 instead.

Docs

  • Release note: docs/changelog/v0.8.3.md

v0.8.2

Choose a tag to compare

@sentomk sentomk released this 03 Mar 06:24

Patternia v0.8.2

Patternia v0.8.2 is a performance and API refinement release focused on one goal: making keyed pattern chains behave much closer to hand-written switch code while keeping the optimization model scalable.

Highlights

  • Introduced a lowering engine with a shared legality model:
    • full
    • bucketed
    • none
  • Added a switch-oriented static literal dispatch path for lit<value>().
  • Added reusable hot-path matcher forms:
    • static_on(...)
    • PTN_ON(...)
  • Unified static literal dispatch and variant dispatch under the same dispatch_plan model.
  • Public examples now prefer match(x) | on(...).
  • Kept runtime literal factories for general-purpose matching:
    • lit(value)
    • lit_ci(value)

Performance

The main benchmark for this release is a 128-way literal match, chosen to separate dispatch quality from matcher construction overhead.

Representative local results:

Benchmark Meaning CPU time
BM_PatterniaPipe_LiteralMatch128StaticCases prebuilt matcher object 1.74 ns
BM_PatterniaPipe_LiteralMatch128On raw inline on(...) 17.9 ns
BM_PatterniaPipe_LiteralMatch128OnMacro cached pipeline matcher via PTN_ON(...) 2.09 ns
BM_Switch_LiteralMatch128 hand-written switch baseline 1.52 ns

Takeaway:

  • the static literal lowering path is now close to the switch baseline
  • the main remaining cost in raw inline on(...) is matcher construction
  • PTN_ON(...) recovers most of that gap while keeping pipeline syntax

API Notes

Recommended public forms in v0.8.2:

match(x) | on(
  lit(1) >> 1,
  __ >> 0
);

For hot paths:

match(x) | PTN_ON(
  lit<1>() >> 1,
  lit<2>() >> 2,
  __ >> 0
);

Literal API split:

  • lit(value) for general runtime matching
  • lit_ci(value) for runtime case-insensitive string matching
  • lit<value>() for compile-time literal lowering

Compatibility

  • No forced migration is required.
  • Existing on{...} call sites remain source-compatible.
  • Public examples and docs now prefer on(...).

Docs

  • Release note: docs/changelog/v0.8.2.md
  • Performance note: docs/performance/v0.8.2.md