Skip to content

Commit 8e1ff6f

Browse files
committed
Remove substitution_dispatch
A facade added by add_facade is a super of the built facade, and a proxy of the built facade converts to a proxy of the super by carrying the metadata over directly. substitution_dispatch did the same by way of a convention and an indirect call, so it no longer earns its place. Remove the class, the conventions the builder produced for it, and the transformations observer_facade and weak_facade applied to it. basic_facade_builder::add_facade_with_substitution is kept and redirects to add_facade, so existing code keeps compiling. Converting to a view or weak proxy of a super replaces what the removed transformations provided. The accessors of the view and weak conversion dispatches gain a conversion function template over the target facade, constrained on the target being reachable from the target of the own facade, which holds for exactly the supers. The invoked overload names the own facade, unless the super declares the skill itself, in which case it names the super and the metadata answers without a second conversion. Both yield the same pointer. The overload qualifiers and the target facade transform are deduced from the convention's own overload type, so the accessor cannot drift from view_conversion_overload or weak_conversion_overload.
1 parent 28e938e commit 8e1ff6f

21 files changed

Lines changed: 144 additions & 293 deletions

docs/spec/.pages

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ nav:
1818
- proxy_indirect_accessor: proxy_indirect_accessor
1919
- proxy_view<br />observer_facade: proxy_view.md
2020
- proxy: proxy
21-
- substitution_dispatch: substitution_dispatch
2221
- weak_dispatch: weak_dispatch
2322
- weak_proxy<br />weak_facade: weak_proxy.md
2423
- Alias Templates:

docs/spec/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ This document provides the API specifications for the C++ library Proxy (version
3131
| [`proxy_indirect_accessor`](proxy_indirect_accessor/README.md) | Provides indirection accessibility for `proxy` |
3232
| [`proxy_view`<br />`observer_facade`](proxy_view.md) | Non-owning `proxy` optimized for raw pointer types |
3333
| [`proxy`](proxy/README.md) | Wraps a pointer object matching specified facade |
34-
| [`substitution_dispatch`](substitution_dispatch/README.md) | Dispatch type for `proxy` substitution with accessibility |
3534
| [`weak_dispatch`](weak_dispatch/README.md) | Weak dispatch type with a default implementation that throws `not_implemented` |
3635
| [`weak_proxy`<br />`weak_facade`](weak_proxy.md) | `proxy` with weak ownership |
3736

docs/spec/basic_facade_builder/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using facade_builder =
4141
| ------------------------------------------------------------ | ------------------------------------------------------------ |
4242
| [`add_convention`<br />`add_indirect_convention`<br />`add_direct_convention`](add_convention.md) | Adds a convention to the template parameters |
4343
| [`add_facade`](add_facade.md) | Adds a facade to the template parameters |
44-
| [`add_facade_with_substitution`](add_facade_with_substitution.md) | Adds a facade to the template parameters, together with [substitution](../substitution_dispatch/README.md) support |
44+
| [`add_facade_with_substitution`](add_facade_with_substitution.md) | Equivalent to [`add_facade`](add_facade.md) |
4545
| [`add_reflection`<br />`add_indirect_reflection`<br />`add_direct_reflection`](add_reflection.md) | Adds a reflection to the template parameters |
4646
| [`add_skill`](add_skill.md) | Adds a custom skill |
4747
| [`restrict_layout`](restrict_layout.md) | Specifies maximum `MaxSize` and `MaxAlign` in the template parameters |

docs/spec/basic_facade_builder/add_facade.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ The alias template `add_facade` of `basic_facade_builder<Ss, Cs, Rs, MaxSize, Ma
2020

2121
The conventions and reflections of `F` are not copied into `Cs` or `Rs`. They are reached through the super. Adding the same facade more than once, or redeclaring a convention that a super already provides, is well-defined and does not have side effects on [`build`](build.md) at either compile-time or runtime.
2222

23-
A convention whose overload is a specialization of [`facade_aware_overload_t`](../facade_aware_overload_t.md) is the exception: its overload depends on the facade it is built into, so it is also checked and made available against the built facade, not only against the super that declares it. [`proxiable`](../proxiable.md) therefore requires the pointer type to satisfy both substitutions, and a failure of either is diagnosed. This is what lets a skill such as [`as_view`](../skills_as_view.md) declared on a super yield a [`proxy_view`](../proxy_view.md) of the built facade rather than of the super.
23+
A convention whose overload is a specialization of [`facade_aware_overload_t`](../facade_aware_overload_t.md) is the exception: its overload depends on the facade it is built into, so it is also checked and made available against the built facade, not only against the super that declares it. [`proxiable`](../proxiable.md) therefore requires the pointer type to satisfy both substitutions, and a failure of either is diagnosed. This is what lets a skill such as [`as_view`](../skills_as_view.md) declared on a super yield a [`proxy_view`](../proxy_view.md) of the built facade as well as of the super.
2424

2525
The metadata of the built facade embeds the metadata of each super, so that converting to a `proxy<F>` needs no indirect call to translate the metadata. The contained value is still copied or relocated as it would be by a copy or a move of a `proxy` of the built facade, which involves an indirect call unless the corresponding [`constraint_level`](../constraint_level.md) is `trivial`. Two consequences of embedding are worth noting. When a super is reachable through more than one other super (a diamond), its metadata is embedded once per path. When the built facade strengthens a [`constraint_level`](../constraint_level.md) that `F` also declares (for example from `nontrivial` to `nothrow`), both levels are represented. Either case makes the metadata larger than the sum of the distinct conventions, and nesting diamonds compounds the effect. Metadata of that size is held out of line and shared by every `proxy` of the facade, so the cost is in static data rather than in `sizeof(proxy<F>)`.
2626

27-
A [`proxy`](../proxy/README.md) of the built facade converts to a `proxy<F>`, subject to the copyability and relocatability of `F`.
27+
A [`proxy`](../proxy/README.md) of the built facade converts to a `proxy<F>`, subject to the copyability and relocatability of `F`. It also converts to a [`proxy_view`](../proxy_view.md)`<F>` when [`as_view`](../skills_as_view.md) is in effect, and to a [`weak_proxy`](../weak_proxy.md)`<F>` when [`as_weak`](../skills_as_weak.md) is.
2828

2929
## Example
3030

@@ -89,5 +89,4 @@ int main() {
8989
9090
## See Also
9191
92-
- [`add_facade_with_substitution`](add_facade_with_substitution.md)
9392
- [`build`](build.md)

docs/spec/basic_facade_builder/add_facade_with_substitution.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ template <facade F>
77
using add_facade_with_substitution = basic_facade_builder</* see below */>;
88
```
99

10-
The alias template `add_facade_with_substitution` of `basic_facade_builder<Cs, Rs, MaxSize, MaxAlign, Copyability, Relocatability, Destructibility>` is equivalent to [`add_facade`](add_facade.md)`<F>`, except that it always merges a direct convention of [`substitution_dispatch`](../substitution_dispatch/README.md) into `Cs`. This convention enables substitution from a `proxy` of the built [facade](../facade.md) to a `proxy<F>`.
11-
12-
## Notes
13-
14-
`add_facade_with_substitution` was introduced in `4.1.0` as a replacement for the deprecated `add_facade<F, true>` syntax.
15-
16-
The substitution convention is helpful when an API requires backward compatibility, at the cost of potentially a slightly larger binary size. When substitution is not required, use [`add_facade`](add_facade.md) to guarantee minimal binary size in code generation.
10+
The alias template `add_facade_with_substitution` of `basic_facade_builder<Ss, Cs, Rs, MaxSize, MaxAlign, Copyability, Relocatability, Destructibility>` is equivalent to [`add_facade`](add_facade.md)`<F>`.
1711

1812
## Example
1913

docs/spec/proxy_view.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using proxy_view = proxy<observer_facade<F>>;
2222
| Name | Description |
2323
| ---------------------------------- | ------------------------------------------------------------ |
2424
| `super_types`<br />*(since 5.0.0)* | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type transformed from `typename F::super_types`. Specifically, for each super `G` in `typename F::super_types`, `observer_facade<G>` is included. |
25-
| `convention_types` | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type transformed from `typename F::convention_types`. Specifically, for each convention `C` in `typename F::convention_types`:<br />- If `C::is_direct` is `false`, include `C` unchanged.<br />- Otherwise, if `typename C::dispatch_type` is [`substitution_dispatch`](./substitution_dispatch/README.md), include a transformed convention `C'` whose `is_direct` is `true`, `dispatch_type` is still `substitution_dispatch`, and whose `overload_type` is `typename C::overload_type` with a return type of `proxy<G>` replaced by `proxy_view<G>` and qualifiers replaced by `const noexcept`.<br />- Otherwise `C` is discarded. Duplicates are removed. |
25+
| `convention_types` | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type transformed from `typename F::convention_types`. Specifically, for each convention `C` in `typename F::convention_types`, `C` is included when `C::is_direct` is `false`, or otherwise discarded. |
2626
| `reflection_types` | A [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type transformed from `typename F::reflection_types`. Specifically, for each reflection type `R` in `typename F::reflection_types`, `R` is included when `R::is_direct` is `false`, or otherwise discarded. |
2727

2828
## Member Constants of `observer_facade`

docs/spec/skills_as_view.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ template <class FB>
1010
using as_view = /* see below */;
1111
```
1212

13-
The alias template `as_view` modifies a specialization of [`basic_facade_builder`](basic_facade_builder/README.md) to allow implicit conversion from [`proxy`](proxy/README.md)`<F>` to [`proxy_view`](proxy_view.md)`<F>`, where `F` is a built [facade](facade.md) type.
13+
The alias template `as_view` modifies a specialization of [`basic_facade_builder`](basic_facade_builder/README.md) to allow implicit conversion from [`proxy`](proxy/README.md)`<F>` to [`proxy_view`](proxy_view.md)`<G>`, where `F` is a built [facade](facade.md) type and `G` is `F` or a super of `F`, reachable via `typename F::super_types` transitively. *Since 5.0.0*: conversion to a view of a super is allowed. Previously only `proxy_view<F>` was available.
1414

15-
Let `p` be a value of type `proxy<F>`, `ptr` be the contained value of `p` (if any), the conversion from type `proxy<F>&` to type `proxy_view<F>` is equivalent to `return observer-ptr{std::addressof(*ptr)}` if `p` contains a value, or otherwise equivalent to `return nullptr`. `observer-ptr` is an exposition-only type that `*observer-ptr`, `*std::as_const(observer-ptr)`, `*std::move(observer-ptr)` and `*std::move(std::as_const(observer-ptr))` are equivalent to `*ptr`, `*std::as_const(ptr)`, `*std::move(ptr)` and `*std::move(std::as_const(ptr))`, respectively.
15+
Let `p` be a value of type `proxy<F>`, `ptr` be the contained value of `p` (if any), the conversion from type `proxy<F>&` to type `proxy_view<G>` is equivalent to `return observer-ptr{std::addressof(*ptr)}` if `p` contains a value, or otherwise equivalent to `return nullptr`. `observer-ptr` is an exposition-only type that `*observer-ptr`, `*std::as_const(observer-ptr)`, `*std::move(observer-ptr)` and `*std::move(std::as_const(observer-ptr))` are equivalent to `*ptr`, `*std::as_const(ptr)`, `*std::move(ptr)` and `*std::move(std::as_const(ptr))`, respectively.
1616

1717
## Notes
1818

19+
A view of a super exposes the conventions and reflections of that super. It observes the same object as `p` without taking ownership, exactly as `proxy_view<F>` does.
20+
1921
`as_view` is useful when a certain context does not take ownership of a `proxy` object. Similar to [`std::unique_ptr::get`](https://en.cppreference.com/w/cpp/memory/unique_ptr/get), [`std::shared_ptr::get`](https://en.cppreference.com/w/cpp/memory/shared_ptr/get) and the [borrowing mechanism in Rust](https://doc.rust-lang.org/rust-by-example/scope/borrow.html).
2022

2123
## Example

docs/spec/skills_as_weak.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ template <class FB>
1010
using as_weak = /* see below */;
1111
```
1212

13-
The alias template `as_weak` modifies a specialization of [`basic_facade_builder`](basic_facade_builder/README.md) to allow implicit conversion from [`proxy`](proxy/README.md)`<F>` to [`weak_proxy`](weak_proxy.md)`<F>`, where `F` is a built [facade](facade.md) type.
13+
The alias template `as_weak` modifies a specialization of [`basic_facade_builder`](basic_facade_builder/README.md) to allow implicit conversion from [`proxy`](proxy/README.md)`<F>` to [`weak_proxy`](weak_proxy.md)`<G>`, where `F` is a built [facade](facade.md) type and `G` is `F` or a super of `F`, reachable via `typename F::super_types` transitively, for which converting `weak_proxy<F>` to `weak_proxy<G>` is not potentially-throwing. *Since 5.0.0*: conversion to a weak proxy of a super is allowed. Previously only `weak_proxy<F>` was available.
1414

15-
Let `p` be a value of type `proxy<F>`, `ptr` be the contained value of `p` (if any), `Ptr` be the type of `ptr`, the conversion from type `const proxy<F>&` to type `weak_proxy<F>` is equivalent to `return typename Ptr::weak_type{p}` if `p` contains a value, or otherwise equivalent to `return nullptr`.
15+
Let `p` be a value of type `proxy<F>`, `ptr` be the contained value of `p` (if any), `Ptr` be the type of `ptr`, the conversion from type `const proxy<F>&` to type `weak_proxy<G>` is equivalent to `return typename Ptr::weak_type{p}` if `p` contains a value, or otherwise equivalent to `return nullptr`.
1616

1717
## Example
1818

docs/spec/substitution_dispatch/.pages

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/spec/substitution_dispatch/README.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)