Skip to content

Commit f2c9c99

Browse files
committed
refactor(pattern): remove type:: namespace
Problem - The deprecated type::is<T>() / type::alt<I>() functions and the ptn::pat::type namespace were still present, even though all internal and external code had migrated to is<T> / alt<I> variable templates. Implementation - Move type::detail types (type_is_pattern, type_alt_pattern, no_subpattern, non_binding_base) into ptn::pat::detail. - Remove the four [[deprecated]] functions from ptn::pat::type. - Remove namespace type = ptn::pat::type alias from patternia.hpp. - Update forward declarations and template specializations in diagnostics.hpp and optimize.hpp. - Update static_assert messages to drop type:: prefix. - Update code examples in docs/performance/v0.8.2.md. - Remove type:: deprecation note from README.md.
1 parent 358b1a8 commit f2c9c99

6 files changed

Lines changed: 59 additions & 102 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
## *Update*
3030

31-
- **API update (v0.8.5)** introduces `is<T>()`, and `alt<I>()` variable templates for type patterns, `$(pattern)` callable syntax for explicit binding, and `has<>()[guard]` for structural validation. Old `type::` namespace functions are deprecated.
31+
- **API update (v0.8.5)** introduces `is<T>()`, and `alt<I>()` variable templates for type patterns, `$(pattern)` callable syntax for explicit binding, and `has<>()[guard]` for structural validation.
3232
- **API update (v0.8.3)** adds `match(x, cases...)` unified entry, `_` wildcard alias, `$` bind shorthand, and `_0``_3` guard placeholders. Guard placeholder `_` is deprecated in favor of `_0`.
3333
- **Release update (v0.8.2)** keeps public usage centered on `match(x) | on(...)` and adds reusable hot-path forms through `static_on(...)` and `PTN_ON(...)`.
3434
- **Performance update (v0.8.2)** introduces a lowering engine with `full` / `bucketed` / `none` legality and a switch-oriented static literal path for large keyed matches.

docs/performance/v0.8.2.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ The `full` case is straightforward:
250250

251251
```cpp
252252
match(v) | on(
253-
type::alt<0>() >> 1,
254-
type::alt<1>() >> 2,
253+
alt<0>() >> 1,
254+
alt<1>() >> 2,
255255
__ >> 0
256256
);
257257
```
@@ -264,9 +264,9 @@ maps to multiple residual checks:
264264

265265
```cpp
266266
match(v) | on(
267-
type::is<int>()[_0 > 100] >> 10,
268-
type::is<int>() >> 1,
269-
type::is<std::string>() >> 2,
267+
is<int>()[_0 > 100] >> 10,
268+
is<int>() >> 1,
269+
is<std::string>() >> 2,
270270
__ >> 0
271271
);
272272
```

include/ptn/core/common/diagnostics.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include "ptn/core/common/common_traits.hpp"
1616
#include "ptn/pattern/base/pattern_traits.hpp"
1717

18-
namespace ptn::pat::type::detail {
18+
namespace ptn::pat::detail {
1919
struct no_subpattern;
2020

2121
template <std::size_t I, typename SubPattern>
2222
struct type_alt_pattern;
23-
} // namespace ptn::pat::type::detail
23+
} // namespace ptn::pat::detail
2424

2525
namespace ptn::pat::mod {
2626
template <typename Inner, typename Pred>
@@ -126,7 +126,7 @@ namespace ptn::core::common {
126126
struct alt_pattern_index : std::integral_constant<std::size_t, alt_npos> {};
127127

128128
template <std::size_t I, typename SubPattern>
129-
struct alt_pattern_index<ptn::pat::type::detail::type_alt_pattern<
129+
struct alt_pattern_index<ptn::pat::detail::type_alt_pattern<
130130
I,
131131
SubPattern>> : std::integral_constant<std::size_t, I> {};
132132

@@ -139,9 +139,9 @@ namespace ptn::core::common {
139139
: std::integral_constant<std::size_t, alt_npos> {};
140140

141141
template <std::size_t I>
142-
struct plain_alt_pattern_index<ptn::pat::type::detail::type_alt_pattern<
142+
struct plain_alt_pattern_index<ptn::pat::detail::type_alt_pattern<
143143
I,
144-
ptn::pat::type::detail::no_subpattern>>
144+
ptn::pat::detail::no_subpattern>>
145145
: std::integral_constant<std::size_t, I> {};
146146

147147
template <typename Case>
@@ -255,8 +255,8 @@ namespace ptn::core::common {
255255
!detail::has_unreachable_alt_after_plain_alt<Cases...>::value;
256256
static_assert(
257257
no_unreachable_alt_after_plain_alt,
258-
"[Patternia.type::alt]: case is unreachable because an earlier "
259-
"plain type::alt<I>() already covers this alternative. Tip: remove "
258+
"[Patternia.alt]: case is unreachable because an earlier "
259+
"plain alt<I>() already covers this alternative. Tip: remove "
260260
"the later alt<I>(...) case, or reorder cases.");
261261
}
262262

@@ -268,8 +268,8 @@ namespace ptn::core::common {
268268
!detail::is_new_case_unreachable_after_plain_alt<Cases...>::value;
269269
static_assert(
270270
new_case_reachable,
271-
"[Patternia.type::alt]: case is unreachable because an earlier "
272-
"plain type::alt<I>() already covers this alternative. Tip: remove "
271+
"[Patternia.alt]: case is unreachable because an earlier "
272+
"plain alt<I>() already covers this alternative. Tip: remove "
273273
"the later alt<I>(...) case, or reorder cases.");
274274
}
275275

@@ -475,7 +475,7 @@ namespace ptn::core::common {
475475
meta::is_spec_of_v<std::variant, meta::remove_cvref_t<Subject>>;
476476
static_assert(
477477
is_variant_subject,
478-
"[Patternia.type::is]: Subject must be a std::variant.");
478+
"[Patternia.is]: Subject must be a std::variant.");
479479
}
480480

481481
// Ensures Alt appears exactly once in the variant's alternatives.
@@ -493,8 +493,8 @@ namespace ptn::core::common {
493493
constexpr bool alt_appears_once = (count == 1);
494494
static_assert(
495495
alt_appears_once,
496-
"[Patternia.type::is]: Alternative type must appear exactly once in "
497-
"std::variant. Tip: use type::alt<I>() for duplicate types, or wrap "
496+
"[Patternia.is]: Alternative type must appear exactly once in "
497+
"std::variant. Tip: use alt<I>() for duplicate types, or wrap "
498498
"types in distinct structs.");
499499
}
500500

@@ -507,7 +507,7 @@ namespace ptn::core::common {
507507
// (A) Alternative index must be in range.
508508
constexpr bool alt_index_in_range = I < std::variant_size_v<subject_t>;
509509
static_assert(alt_index_in_range,
510-
"[Patternia.type::alt]: Alternative index is out of range. "
510+
"[Patternia.alt]: Alternative index is out of range. "
511511
"Tip: valid indices are [0, variant_size-1].");
512512
}
513513

include/ptn/core/common/optimize.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#include "ptn/core/common/common_traits.hpp"
1717
#include "ptn/core/common/diagnostics.hpp"
1818

19-
namespace ptn::pat::type::detail {
19+
namespace ptn::pat::detail {
2020
struct no_subpattern;
2121

2222
template <typename T, typename SubPattern>
2323
struct type_is_pattern;
2424

2525
template <std::size_t I, typename SubPattern>
2626
struct type_alt_pattern;
27-
} // namespace ptn::pat::type::detail
27+
} // namespace ptn::pat::detail
2828

2929
namespace ptn::pat::mod {
3030
template <typename Inner, typename Pred>
@@ -165,55 +165,55 @@ namespace ptn::core::common {
165165
}
166166
};
167167

168-
// Matches `type::is<T>()` with no subpattern/binding.
168+
// Matches `is<T>()` with no subpattern/binding.
169169
template <typename Pattern>
170170
struct is_simple_variant_type_is_pattern : std::false_type {};
171171

172172
template <typename Alt>
173173
struct is_simple_variant_type_is_pattern<
174-
ptn::pat::type::detail::
175-
type_is_pattern<Alt, ptn::pat::type::detail::no_subpattern>>
174+
ptn::pat::detail::
175+
type_is_pattern<Alt, ptn::pat::detail::no_subpattern>>
176176
: std::true_type {};
177177

178178
template <typename Pattern>
179179
constexpr bool
180180
is_simple_variant_type_is_pattern_v = is_simple_variant_type_is_pattern<
181181
std::decay_t<Pattern>>::value;
182182

183-
// Matches `type::alt<I>()` with no subpattern/binding.
183+
// Matches `alt<I>()` with no subpattern/binding.
184184
template <typename Pattern>
185185
struct is_simple_variant_type_alt_pattern : std::false_type {};
186186

187187
template <std::size_t I>
188188
struct is_simple_variant_type_alt_pattern<
189-
ptn::pat::type::detail::
190-
type_alt_pattern<I, ptn::pat::type::detail::no_subpattern>>
189+
ptn::pat::detail::
190+
type_alt_pattern<I, ptn::pat::detail::no_subpattern>>
191191
: std::true_type {};
192192

193193
template <typename Pattern>
194194
constexpr bool is_simple_variant_type_alt_pattern_v =
195195
is_simple_variant_type_alt_pattern<std::decay_t<Pattern>>::value;
196196

197-
// Matches `type::is<T>(...)` (any subpattern).
197+
// Matches `is<T>(...)` (any subpattern).
198198
template <typename Pattern>
199199
struct is_variant_type_is_pattern : std::false_type {};
200200

201201
template <typename Alt, typename SubPattern>
202202
struct is_variant_type_is_pattern<
203-
ptn::pat::type::detail::type_is_pattern<Alt, SubPattern>>
203+
ptn::pat::detail::type_is_pattern<Alt, SubPattern>>
204204
: std::true_type {};
205205

206206
template <typename Pattern>
207207
constexpr bool is_variant_type_is_pattern_v = is_variant_type_is_pattern<
208208
std::decay_t<Pattern>>::value;
209209

210-
// Matches `type::alt<I>(...)` (any subpattern).
210+
// Matches `alt<I>(...)` (any subpattern).
211211
template <typename Pattern>
212212
struct is_variant_type_alt_pattern : std::false_type {};
213213

214214
template <std::size_t I, typename SubPattern>
215215
struct is_variant_type_alt_pattern<
216-
ptn::pat::type::detail::type_alt_pattern<I, SubPattern>>
216+
ptn::pat::detail::type_alt_pattern<I, SubPattern>>
217217
: std::true_type {};
218218

219219
template <typename Pattern>
@@ -299,38 +299,38 @@ namespace ptn::core::common {
299299
inline static constexpr key_t value = static_cast<key_t>(V);
300300
};
301301

302-
// Extracts alt index from `type::alt<I>()` patterns.
302+
// Extracts alt index from `alt<I>()` patterns.
303303
template <typename Pattern>
304304
struct simple_variant_alt_index;
305305

306306
template <std::size_t I>
307-
struct simple_variant_alt_index<ptn::pat::type::detail::type_alt_pattern<
307+
struct simple_variant_alt_index<ptn::pat::detail::type_alt_pattern<
308308
I,
309-
ptn::pat::type::detail::no_subpattern>>
309+
ptn::pat::detail::no_subpattern>>
310310
: std::integral_constant<std::size_t, I> {};
311311

312312
template <typename Pattern>
313313
struct variant_type_alt_index;
314314

315315
template <std::size_t I, typename SubPattern>
316316
struct variant_type_alt_index<
317-
ptn::pat::type::detail::type_alt_pattern<I, SubPattern>>
317+
ptn::pat::detail::type_alt_pattern<I, SubPattern>>
318318
: std::integral_constant<std::size_t, I> {};
319319

320-
// Matches `type::is<T>(bind())`.
320+
// Matches `is<T>(bind())`.
321321
template <typename Pattern>
322322
struct is_variant_direct_ref_bind_pattern : std::false_type {};
323323

324324
template <typename Alt>
325325
struct is_variant_direct_ref_bind_pattern<
326-
ptn::pat::type::detail::type_is_pattern<Alt,
326+
ptn::pat::detail::type_is_pattern<Alt,
327327
ptn::pat::detail::binding_pattern>>
328328
: std::true_type {};
329329

330-
// Matches `type::alt<I>(bind())`.
330+
// Matches `alt<I>(bind())`.
331331
template <std::size_t I>
332332
struct is_variant_direct_ref_bind_pattern<
333-
ptn::pat::type::detail::type_alt_pattern<I,
333+
ptn::pat::detail::type_alt_pattern<I,
334334
ptn::pat::detail::binding_pattern>>
335335
: std::true_type {};
336336

0 commit comments

Comments
 (0)