Skip to content

Commit b76fd39

Browse files
authored
Refactor lifetime model selection into type traits (#69)
Replace the `*_impl` proxy creation functions with type traits that name the selected lifetime model, so that the models can be reused by types other than `proxy` (e.g. an upcoming `box`). No observable behavior change. - Rename the internal `allocated_ptr` class template to `wide_ptr`, and add `allocated_ptr`, `owned_ptr` and `shared_ptr` type traits that select a lifetime model instead of constructing a `proxy` directly. The creation functions now construct `proxy<F>` from the selected pointer type. - Let `inplace_ptr` ignore its first constructor argument so that all owning lifetime models share a uniform `(alloc, args...)` construction signature. - Order the `T&& value` overload first in each creation function family, and renumber the corresponding specs to match.
1 parent 4b49a1a commit b76fd39

8 files changed

Lines changed: 137 additions & 140 deletions

File tree

docs/spec/allocate_proxy.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ The definition of `allocate_proxy` makes use of an exposition-only class templat
88

99
```cpp
1010
// (1)
11+
template <facade F, class Alloc, class T>
12+
proxy<F> allocate_proxy(const Alloc& alloc, T&& value); // freestanding-deleted
13+
14+
// (2)
1115
template <facade F, class T, class Alloc, class... Args>
1216
proxy<F> allocate_proxy(const Alloc& alloc, Args&&... args); // freestanding-deleted
1317

14-
// (2)
18+
// (3)
1519
template <facade F, class T, class Alloc, class U, class... Args>
1620
proxy<F> allocate_proxy(const Alloc& alloc, std::initializer_list<U> il, Args&&... args); // freestanding-deleted
17-
18-
// (3)
19-
template <facade F, class Alloc, class T>
20-
proxy<F> allocate_proxy(const Alloc& alloc, T&& value); // freestanding-deleted
2121
```
2222
23-
`(1)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
23+
`(1)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;*`std::decay_t<T>`*, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
2424
25-
`(2)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
25+
`(2)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
2626
27-
`(3)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;*`std::decay_t<T>`*, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
27+
`(3)` Creates a `proxy<F>` object containing a value `p` of type *allocated-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
2828
2929
*Since 3.3.0*: For `(1-3)`, if [`proxiable_target<std::decay_t<T>, F>`](proxiable_target.md) is `false`, the program is ill-formed and diagnostic messages are generated.
3030

docs/spec/allocate_proxy_shared.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ The definition of `allocate_proxy_shared` makes use of exposition-only class tem
99

1010
```cpp
1111
// (1)
12+
template <facade F, class Alloc, class T>
13+
proxy<F> allocate_proxy_shared(const Alloc& alloc, T&& value); // freestanding-deleted
14+
15+
// (2)
1216
template <facade F, class T, class Alloc, class... Args>
1317
proxy<F> allocate_proxy_shared(const Alloc& alloc, Args&&... args); // freestanding-deleted
1418

15-
// (2)
19+
// (3)
1620
template <facade F, class T, class Alloc, class U, class... Args>
1721
proxy<F> allocate_proxy_shared(const Alloc& alloc, std::initializer_list<U> il, Args&&... args); // freestanding-deleted
18-
19-
// (3)
20-
template <facade F, class Alloc, class T>
21-
proxy<F> allocate_proxy_shared(const Alloc& alloc, T&& value); // freestanding-deleted
2222
```
2323
24-
`(1)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
24+
`(1)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;*`std::decay_t<T>`*, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
2525
26-
`(2)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
26+
`(2)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
2727
28-
`(3)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;*`std::decay_t<T>`*, Alloc&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
28+
`(3)` Creates a `proxy<F>` object containing a value `p` of type *strong-compact-ptr&lt;T, Alloc&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
2929
3030
For `(1-3)`, if [`proxiable_target<std::decay_t<T>, F>`](proxiable_target.md) is `false`, the program is ill-formed and diagnostic messages are generated.
3131

docs/spec/make_proxy.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ proxy<F> make-proxy-internal(Args&&... args) {
1919
2020
```cpp
2121
// (1)
22+
template <facade F, class T>
23+
proxy<F> make_proxy(T&& value); // freestanding-deleted
24+
25+
// (2)
2226
template <facade F, class T, class... Args>
2327
proxy<F> make_proxy(Args&&... args); // freestanding-deleted
2428
25-
// (2)
29+
// (3)
2630
template <facade F, class T, class U, class... Args>
2731
proxy<F> make_proxy(std::initializer_list<U> il, Args&&... args); // freestanding-deleted
28-
29-
// (3)
30-
template <facade F, class T>
31-
proxy<F> make_proxy(T&& value); // freestanding-deleted
3232
```
3333

34-
`(1)` Equivalent to `return make-proxy-internal<F, T>(std::forward<Args>(args)...)`.
34+
`(1)` Equivalent to `return make-proxy-internal<F, std::decay_t<T>>(std::forward<T>(value))`.
3535

36-
`(2)` Equivalent to `return make-proxy-internal<F, T>(il, std::forward<Args>(args)...)`.
36+
`(2)` Equivalent to `return make-proxy-internal<F, T>(std::forward<Args>(args)...)`.
3737

38-
`(3)` Equivalent to `return make-proxy-internal<F, std::decay_t<T>>(std::forward<T>(value))`.
38+
`(3)` Equivalent to `return make-proxy-internal<F, T>(il, std::forward<Args>(args)...)`.
3939

4040
*Since 3.3.0*: For `(1-3)`, if [`proxiable_target<std::decay_t<T>, F>`](proxiable_target.md) is `false`, the program is ill-formed and diagnostic messages are generated.
4141

docs/spec/make_proxy_inplace.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ The definition of `make_proxy_inplace` makes use of an exposition-only class tem
88

99
```cpp
1010
// (1)
11+
template <facade F, class T>
12+
proxy<F> make_proxy_inplace(T&& value)
13+
noexcept(std::is_nothrow_constructible_v<std::decay_t<T>, T>)
14+
requires(std::is_constructible_v<std::decay_t<T>, T>);
15+
16+
// (2)
1117
template <facade F, class T, class... Args>
1218
proxy<F> make_proxy_inplace(Args&&... args)
1319
noexcept(std::is_nothrow_constructible_v<T, Args...>)
1420
requires(std::is_constructible_v<T, Args...>);
1521

16-
// (2)
22+
// (3)
1723
template <facade F, class T, class U, class... Args>
1824
proxy<F> make_proxy_inplace(std::initializer_list<U> il, Args&&... args)
1925
noexcept(std::is_nothrow_constructible_v<
2026
T, std::initializer_list<U>&, Args...>)
2127
requires(std::is_constructible_v<T, std::initializer_list<U>&, Args...>);
22-
23-
// (3)
24-
template <facade F, class T>
25-
proxy<F> make_proxy_inplace(T&& value)
26-
noexcept(std::is_nothrow_constructible_v<std::decay_t<T>, T>)
27-
requires(std::is_constructible_v<std::decay_t<T>, T>);
2828
```
2929
30-
`(1)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;T&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
30+
`(1)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;*`std::decay_t`*&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
3131
32-
`(2)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;T&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
32+
`(2)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;T&gt;*, where `*p` is direct-non-list-initialized with `std::forward<Args>(args)...`.
3333
34-
`(3)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;*`std::decay_t`*&gt;*, where `*p` is direct-non-list-initialized with `std::forward<T>(value)`.
34+
`(3)` Creates a `proxy<F>` object containing a value `p` of type *inplace-ptr&lt;T&gt;*, where `*p` is direct-non-list-initialized with `il, std::forward<Args>(args)...`.
3535
3636
*Since 3.3.0*: For `(1-3)`, if [`inplace_proxiable_target<std::decay_t<T>, F>`](inplace_proxiable_target.md) is `false`, the program is ill-formed and diagnostic messages are generated.
3737

docs/spec/make_proxy_shared.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
88
```cpp
99
// (1)
10+
template <facade F, class T>
11+
proxy<F> make_proxy_shared(T&& value); // freestanding-deleted
12+
13+
// (2)
1014
template <facade F, class T, class... Args>
1115
proxy<F> make_proxy_shared(Args&&... args); // freestanding-deleted
1216

13-
// (2)
17+
// (3)
1418
template <facade F, class T, class U, class... Args>
1519
proxy<F> make_proxy_shared(std::initializer_list<U> il, Args&&... args); // freestanding-deleted
16-
17-
// (3)
18-
template <facade F, class T>
19-
proxy<F> make_proxy_shared(T&& value); // freestanding-deleted
2020
```
2121
22-
`(1)` Equivalent to `return allocate_proxy_shared<F, T>(std::allocator<void>{}, std::forward<Args>(args)...)`.
22+
`(1)` Equivalent to `return allocate_proxy_shared<F, std::decay_t<T>>(std::allocator<void>{}, std::forward<T>(value))`.
2323
24-
`(2)` Equivalent to `return allocate_proxy_shared<F, T>(std::allocator<void>{}, il, std::forward<Args>(args)...)`.
24+
`(2)` Equivalent to `return allocate_proxy_shared<F, T>(std::allocator<void>{}, std::forward<Args>(args)...)`.
2525
26-
`(3)` Equivalent to `return allocate_proxy_shared<F, std::decay_t<T>>(std::allocator<void>{}, std::forward<T>(value))`.
26+
`(3)` Equivalent to `return allocate_proxy_shared<F, T>(std::allocator<void>{}, il, std::forward<Args>(args)...)`.
2727
2828
*Since 3.3.0*: For `(1-3)`, if [`proxiable_target<std::decay_t<T>, F>`](proxiable_target.md) is `false`, the program is ill-formed and diagnostic messages are generated.
2929

include/proxy/v4/detail/core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ struct meta_storage : facade_traits<F>::meta_storage_base {
716716
template <class T>
717717
class inplace_ptr {
718718
public:
719-
template <class... Args>
720-
explicit inplace_ptr(std::in_place_t, Args&&... args)
719+
template <class Ignore, class... Args>
720+
explicit inplace_ptr(const Ignore&, Args&&... args)
721721
: value_(std::forward<Args>(args)...) {}
722722
inplace_ptr() = default;
723723
inplace_ptr(const inplace_ptr&) = default;

0 commit comments

Comments
 (0)