Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit 777510b

Browse files
authored
Improve proxy_view (#241)
1 parent fdfc2cb commit 777510b

29 files changed

Lines changed: 260 additions & 241 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main() {
5353
std::cout << std::format("p2 = {}\n", *p2); // Prints "p2 = 123"
5454

5555
pro::proxy<Formattable> p3 = pro::make_proxy<Formattable>(3.14159);
56-
std::cout << std::format("p3 = {:.2f}\n", *p3) << "\n"; // Prints "p3 = 3.14"
56+
std::cout << std::format("p3 = {:.2f}\n", *p3); // Prints "p3 = 3.14"
5757
}
5858
```
5959
@@ -208,7 +208,7 @@ The "Proxy" library is a self-contained solution for runtime polymorphism in C++
208208
- **Allocator awareness**: [function template `allocate_proxy`](https://microsoft.github.io/proxy/docs/allocate_proxy.html) is able to create a `proxy` from a value with any custom allocator. In C++11, [`std::function`](https://en.cppreference.com/w/cpp/utility/functional/function) and [`std::packaged_task`](https://en.cppreference.com/w/cpp/thread/packaged_task) had constructors that accepted custom allocators for performance tuning, but these were [removed in C++17](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0302r1.html) because "the semantics are unclear, and there are technical issues with storing an allocator in a type-erased context and then recovering that allocator later for any allocations needed during copy assignment". These issues do not apply to `allocate_proxy`.
209209
- **Configurable constraints**: [`facade_builder`](https://microsoft.github.io/proxy/docs/basic_facade_builder.html) provides full support for constraints configuration, including memory layout (by [`restrict_layout`](https://microsoft.github.io/proxy/docs/basic_facade_builder/restrict_layout.html)), copyability (by [`support_copy`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_copy.html)), relocatability (by [`support_relocation`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_relocation.html)), and destructibility (by [`support_destruction`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_destruction.html)).
210210
- **Reflection**: `proxy` supports type-based compile-time reflection for runtime queries. Please refer to [`facade_builder::add_reflection`](https://microsoft.github.io/proxy/docs/basic_facade_builder/add_reflection.html) and [function template `proxy_reflect`](https://microsoft.github.io/proxy/docs/proxy_reflect.html) for more details.
211-
- **Non-owning proxy**: Although `proxy` can manage the lifetime of an object effectively, similar to a smart pointer, we sometimes want to dereference it before passing to a non-owning context. This has been implemented as an extension since 3.2. Please refer to [alias template `proxy_view`, class template `observer_facade`](https://microsoft.github.io/proxy/docs/proxy_view.html) and [`facade_builder::add_view`](https://microsoft.github.io/proxy/docs/basic_facade_builder/add_view.html) for more details.
211+
- **Non-owning proxy**: Although `proxy` can manage the lifetime of an object effectively, similar to a smart pointer, we sometimes want to dereference it before passing to a non-owning context. This has been implemented as an extension since 3.2. Please refer to [alias template `proxy_view`, class template `observer_facade`](https://microsoft.github.io/proxy/docs/proxy_view.html) and [`facade_builder::support_view`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_view.html) for more details.
212212
- **RTTI**: [RTTI (run-time type information)](https://en.wikipedia.org/wiki/Run-time_type_information) provides "weak" reflection capability in C++ since the last century. Although it is not as powerful as reflection in some other languages (like `Object.GetType()` in C# or `Object.getClass()` in Java), it offers the basic infrastructure for type-safe casting at runtime. Since 3.2, "RTTI for `proxy`" has been implemented as an extension and allows users to opt-in for each facade definition. Please refer to [`facade_builder::support_rtti`](https://microsoft.github.io/proxy/docs/basic_facade_builder/support_rtti.html) for more details.
213213
- **Weak dispatch**: When an object does not implement a convention, and we do not want it to trigger a hard compile error, it is allowed to specify a [`weak_dispatch`](https://microsoft.github.io/proxy/docs/weak_dispatch.html) that throws when invoked.
214214

benchmarks/proxy_invocation_benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace {
99

1010
void BM_SmallObjectInvocationViaProxy(benchmark::State& state) {
1111
auto data = GenerateSmallObjectInvocationProxyTestData();
12-
std::vector<pro::proxy_view<const InvocationTestFacade>> views{data.begin(), data.end()};
12+
std::vector<pro::proxy_view<InvocationTestFacade>> views{data.begin(), data.end()};
1313
for (auto _ : state) {
1414
for (auto& p : views) {
1515
int result = p->Fun();
@@ -50,7 +50,7 @@ void BM_LargeObjectInvocationViaProxy(benchmark::State& state) {
5050

5151
void BM_LargeObjectInvocationViaProxyView(benchmark::State& state) {
5252
auto data = GenerateLargeObjectInvocationProxyTestData();
53-
std::vector<pro::proxy_view<const InvocationTestFacade>> views{data.begin(), data.end()};
53+
std::vector<pro::proxy_view<InvocationTestFacade>> views{data.begin(), data.end()};
5454
for (auto _ : state) {
5555
for (auto& p : views) {
5656
int result = p->Fun();

benchmarks/proxy_invocation_benchmark_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PRO_DEF_MEM_DISPATCH(MemFun, Fun);
1010

1111
struct InvocationTestFacade : pro::facade_builder
1212
::add_convention<MemFun, int() const>
13-
::add_view<const InvocationTestFacade>
13+
::support_view
1414
::build{};
1515

1616
struct InvocationTestBase {

docs/PRO_DEF_FREE_AS_MEM_DISPATCH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Macro `PRO_DEF_FREE_AS_MEM_DISPATCH`
22

33
```cpp
4-
#define PRO_DEF_FREE_AS_MEM_DISPATCH // since 3.1, see below
4+
#define PRO_DEF_FREE_AS_MEM_DISPATCH // since 3.1.0, see below
55
```
66
77
Macro `PRO_DEF_FREE_AS_MEM_DISPATCH` defines dispatch types for free function expressions with accessibility via a member function. It supports two syntaxes:

docs/PRO_DEF_WEAK_DISPATCH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Macro `PRO_DEF_WEAK_DISPATCH`
22

33
```cpp
4-
#define PRO_DEF_WEAK_DISPATCH // deprecated since 3.2, see below
4+
#define PRO_DEF_WEAK_DISPATCH // deprecated since 3.2.0, see below
55
```
66
77
<mark>⚠️ Macro <code>PRO_DEF_WEAK_DISPATCH</code> has been replaced by class template <code>weak_dispatch</code> since 3.2, and may be removed in a future version.</mark>

docs/ProOverload.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Named requirements: *ProOverload*
22

3-
A type `O` meets the *ProOverload* requirements if it matches one of the following definitions, where `R` is the *return type*, `Args...` are the *argument types*.
3+
A type `O` meets the *ProOverload* requirements if `substituted-overload<O, F>` matches one of the following definitions, where `F` is any type meeting the [*ProBasicFacade* requirements](ProBasicFacade.md), `R` is the *return type*, `Args...` are the *argument types*.
4+
5+
The exposition-only type `substituted-overload<O, F>` is `OT<F>` if `O` is a specialization of [`facade_aware_overload_t<OT>`](facade_aware_overload_t.md), or `O` otherwise.
46

57
| Definitions of `O` |
68
| ----------------------------- |

docs/bad_proxy_cast.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Class `bad_proxy_cast`
22

33
```cpp
4-
class bad_proxy_cast : public std::bad_cast;
4+
class bad_proxy_cast : public std::bad_cast; // since 3.2.0
55
```
66
77
A type of object to be thrown by the value-returning forms of [`proxy_cast`](basic_facade_builder/support_rtti.md) on failure.

docs/basic_facade_builder.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ using facade_builder = basic_facade_builder<std::tuple<>, std::tuple<>,
3030
| Name | Description |
3131
| ------------------------------------------------------------ | ------------------------------------------------------------ |
3232
| [`build`](basic_facade_builder/build.md) | Specifies a [`facade`](facade.md) type deduced from the template parameters of the `basic_facade_builder` |
33-
| [`support_format`<br />`support_wformat`](basic_facade_builder/support_format.md)<br />*(since 3.2)* | Specifies the capability of formatting (via [formatting functions](https://en.cppreference.com/w/cpp/utility/format)) to the template parameters |
34-
| [`support_rtti`<br />`support_indirect_rtti`<br />`support_direct_rtti`](basic_facade_builder/support_rtti.md)<br />*(since 3.2)* | Specifies the capability of RTTI (via `proxy_cast` and `proxy_typeid`) to the template parameters |
33+
| [`support_format`<br />`support_wformat`](basic_facade_builder/support_format.md)<br />*(since 3.2.0)* | Specifies the capability of formatting (via [formatting functions](https://en.cppreference.com/w/cpp/utility/format)) to the template parameters |
34+
| [`support_rtti`<br />`support_indirect_rtti`<br />`support_direct_rtti`](basic_facade_builder/support_rtti.md)<br />*(since 3.2.0)* | Specifies the capability of RTTI (via `proxy_cast` and `proxy_typeid`) to the template parameters |
35+
| [`support_view` ](basic_facade_builder/support_view.md)<br />*(since 3.2.1)* | Specifies the capability of implicit conversion to `proxy_view` to the template parameters |
3536
3637
## Member Alias Templates
3738
@@ -40,7 +41,6 @@ using facade_builder = basic_facade_builder<std::tuple<>, std::tuple<>,
4041
| [`add_convention`<br />`add_indirect_convention`<br />`add_direct_convention`](basic_facade_builder/add_convention.md) | Adds a convention to the template parameters |
4142
| [`add_facade`](basic_facade_builder/add_facade.md) | Adds a facade to the template parameters |
4243
| [`add_reflection`<br />`add_indirect_reflection`<br />`add_direct_reflection`](basic_facade_builder/add_reflection.md) | Adds a reflection to the template parameters |
43-
| [`add_view` ](basic_facade_builder/add_view.md)<br />*(since 3.2)* | Specifies the capability of implicit conversion to `proxy_view` to the template parameters |
4444
| [`restrict_layout`](basic_facade_builder/restrict_layout.md) | Specifies maximum `max_size` and `max_align` of `C` in the template parameters |
4545
| [`support_copy`](basic_facade_builder/support_copy.md) | Specifies minimum `copyability` of `C` in the template parameters |
4646
| [`support_destruction`](basic_facade_builder/support_destruction.md) | Specifies minimum `destructibility` of `C` in the template parameters |

docs/basic_facade_builder/add_convention.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ The alias templates `add_convention`, `add_indirect_convention`, and `add_direct
1818
- `IC::is_direct` is `false`.
1919
- `typename IC::dispatch_type` is `D`.
2020
- `typename IC::overload_types` is a [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type of distinct types in `Os`.
21-
- `typename IC::template accessor<F>` is `typename D::template accessor<F, false, D, Os...>` if applicable.
21+
- `typename IC::template accessor<F>` is `typename D::template accessor<F, false, D, `[`substituted-overload<Os, F>`](../ProOverload.md)`...>` if applicable.
2222
- `add_direct_convention` merges an implementation-defined convention type `IC` into `Cs`, where:
2323
- `IC::is_direct` is `true`.
2424
- `typename IC::dispatch_type` is `D`.
2525
- `typename IC::overload_types` is a [tuple-like](https://en.cppreference.com/w/cpp/utility/tuple/tuple-like) type of distinct types in `Os`.
26-
- `typename IC::template accessor<F>` is `typename D::template accessor<F, true, D, Os...>` if applicable.
26+
- `typename IC::template accessor<F>` is `typename D::template accessor<F, true, D, `[`substituted-overload<Os, F>`](../ProOverload.md)`...>` if applicable.
2727
2828
When `Cs` already contains a convention type `IC2` where `IC2::is_direct == IC::is_direct && std::is_same_v<typename IC2::dispatch_type, typename IC::dispatch_type>` is `true`, `Os` merges with `typename IC2::overload_types` and removes duplicates, and `std::tuple_size_v<Cs>` shall not change.
2929

docs/basic_facade_builder/add_view.md

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

0 commit comments

Comments
 (0)