Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/spec/proxy/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ proxy& operator=(P&& ptr)
F::destructibility >= lifetime_requirement::supported);
```

Assigns a new value to `proxy` or destroys the contained value.
Assigns a new value to `proxy` or destroys the contained value. For `(2-6)`, the source of the assignment may be owned by the contained value of `*this`, such as in `p = std::move(p->next)`. Therefore, if `*this` contains a value, the new value is first constructed from the source as a temporary `temp`, then the contained value is destroyed, and then the contained value is initialized from `temp` as specified below. If an exception is thrown while the new value is constructed from the source, `*this` is not modified. If an exception is thrown otherwise, `*this` does not contain a value.

- `(1)` Destroys the current contained value if it exists. After the call, `*this` does not contain a value.
- `(2)` Copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). When `F::copyability == lifetime_requirement::trivial`, copy assignment is defaulted. It is trivial only if the metadata storage and accessor base classes also permit trivial copy assignment.
- `(3)` Move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If the move construction throws when `F::relocatability == lifetime_requirement::supported`, `*this` does not contain a value. After move assignment, `rhs` is in a valid state with an unspecified value. The move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to the defaulted copy assignment operator.
- `(4)` Converting copy assignment operator copies the contained value of `rhs` to `*this`, as if by constructing a `proxy` from `rhs` and assigning it. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively.
- `(5)` Converting move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If the move construction throws when `F::relocatability == lifetime_requirement::supported`, `*this` does not contain a value. After the assignment, `rhs` does not contain a value. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. The converting move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to `(4)`.
- `(6)` Let `VP` be `std::decay_t<P>`. Sets the contained value to an object of type `VP`, direct-non-list-initialized with `std::forward<P>(ptr)`. Participates in overload resolution only if `VP` is not a specialization of `proxy` and is a pointer-like type eligible for `proxy` (see [*ProxyFacade* requirements](../ProxyFacade.md)). *Since 3.3.0*: If [`proxiable<VP, F, MP>`](../proxiable.md) is `false`, the program is ill-formed and a diagnostic is generated.
- `(1)` Destroys the current contained value if it exists. After the call, `*this` does not contain a value, even if the destruction throws.
- `(2)` Copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized as if by `proxy(std::move(temp))` if `std::is_nothrow_move_constructible_v<proxy>` is `true` or `std::is_nothrow_copy_constructible_v<proxy>` is `false`, or as if by `proxy(std::as_const(temp))` otherwise. When `F::copyability == lifetime_requirement::trivial`, copy assignment is defaulted. It is trivial only if the metadata storage and accessor base classes also permit trivial copy assignment.
- `(3)` Move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized as if by `proxy(std::move(temp))`. If moving the contained value of `rhs` throws, `rhs` does not contain a value. After move assignment, `rhs` is in a valid state with an unspecified value. The move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to the defaulted copy assignment operator.
- `(4)` Converting copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized from it as in `(2)`. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively.
- `(5)` Converting move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized from it as in `(3)`. After the assignment, `rhs` does not contain a value, even if an exception is thrown. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. The converting move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to `(4)`.
- `(6)` Let `VP` be `std::decay_t<P>`. Sets the contained value to an object of type `VP`, direct-non-list-initialized with `std::forward<P>(ptr)`. If `*this` contains a value, `temp` is an object of type `VP`, and the contained value is direct-non-list-initialized with `std::move(temp)` if `std::is_move_constructible_v<VP>` is `true` and either `std::is_nothrow_move_constructible_v<VP>` is `true` or `std::is_nothrow_copy_constructible_v<VP>` is `false`, or with `std::as_const(temp)` otherwise. Participates in overload resolution only if `VP` is not a specialization of `proxy` and is a pointer-like type eligible for `proxy` (see [*ProxyFacade* requirements](../ProxyFacade.md)). *Since 3.3.0*: If [`proxiable<VP, F, MP>`](../proxiable.md) is `false`, the program is ill-formed and a diagnostic is generated.

## Return Value

Expand Down
74 changes: 44 additions & 30 deletions include/proxy/v5/detail/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ template <class T, class... Args>
concept nothrow_constructible =
constructible<T, Args...> &&
noexcept(::new (std::declval<void*>()) T(std::declval<Args>()...));
template <class T>
using move_or_copy_t =
std::conditional_t<std::is_move_constructible_v<T> &&
(std::is_nothrow_move_constructible_v<T> ||
!std::is_nothrow_copy_constructible_v<T>),
T&&, const T&>;

template <class T, lifetime_requirement LR>
struct copyability_traits : inapplicable_traits {};
Expand Down Expand Up @@ -1255,14 +1261,11 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
F::destructibility >= lifetime_requirement::supported)
{
if (this != std::addressof(rhs)) [[likely]] {
if constexpr (F::copyability == lifetime_requirement::nothrow) {
destroy();
initialize(rhs);
} else if constexpr (F::relocatability >=
lifetime_requirement::supported) {
*this = proxy{rhs};
} else {
if (meta_) {
proxy temp = rhs;
reset();
initialize(static_cast<detail::move_or_copy_t<proxy>>(temp));
} else {
initialize(rhs);
}
}
Expand All @@ -1277,8 +1280,13 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
F::copyability != lifetime_requirement::trivial)
{
if (this != std::addressof(rhs)) [[likely]] {
reset();
initialize(std::move(rhs));
if (meta_) {
proxy temp = std::move(rhs);
reset();
initialize(std::move(temp));
} else {
initialize(std::move(rhs));
}
}
return *this;
}
Expand All @@ -1292,13 +1300,11 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
F::copyability >= lifetime_requirement::supported &&
F::destructibility >= lifetime_requirement::supported)
{
if constexpr (F::copyability >= lifetime_requirement::nothrow) {
destroy();
initialize(rhs);
} else if constexpr (F::relocatability >= lifetime_requirement::supported) {
*this = proxy{rhs};
} else {
if (meta_) {
proxy temp = rhs;
reset();
initialize(static_cast<detail::move_or_copy_t<proxy>>(temp));
} else {
initialize(rhs);
}
return *this;
Expand All @@ -1314,8 +1320,13 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
F::destructibility >= lifetime_requirement::supported &&
F::copyability != lifetime_requirement::trivial)
{
reset();
initialize(std::move(rhs));
if (meta_) {
proxy temp = std::move(rhs);
reset();
initialize(std::move(temp));
} else {
initialize(std::move(rhs));
}
return *this;
}
template <class P>
Expand All @@ -1327,15 +1338,13 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
std::is_constructible_v<std::decay_t<P>, P> &&
F::destructibility >= lifetime_requirement::supported)
{
if constexpr (std::is_nothrow_constructible_v<std::decay_t<P>, P>) {
destroy();
initialize<std::decay_t<P>>(std::forward<P>(ptr));
} else if constexpr (F::relocatability >= lifetime_requirement::supported ||
F::copyability >= lifetime_requirement::nothrow) {
*this = proxy{std::forward<P>(ptr)};
} else {
using VP = std::decay_t<P>;
if (meta_) {
VP temp(std::forward<P>(ptr));
reset();
initialize<std::decay_t<P>>(std::forward<P>(ptr));
initialize<VP>(static_cast<detail::move_or_copy_t<VP>>(temp));
} else {
initialize<VP>(std::forward<P>(ptr));
}
return *this;
}
Expand Down Expand Up @@ -1410,14 +1419,16 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
if (meta_) {
if (rhs.meta_) {
proxy temp = *this;
*this = rhs;
rhs = temp;
reset();
initialize(rhs);
rhs.reset();
rhs.initialize(temp);
} else {
rhs = *this;
rhs.initialize(*this);
reset();
}
} else if (rhs.meta_) {
*this = rhs;
initialize(rhs);
rhs.reset();
}
}
Expand Down Expand Up @@ -1501,7 +1512,10 @@ class proxy : public detail::proxy_traits<F, MP>::direct_accessor,
}
}
template <facade F2>
void initialize(proxy<F2, MP>&& rhs) {
void initialize(proxy<F2, MP>&& rhs)
requires(F::relocatability >= lifetime_requirement::supported &&
F::copyability != lifetime_requirement::trivial)
{
PRO5D_DEBUG(std::ignore = &pro_symbol_guard;)
if (rhs.has_value()) {
detail::proxy_helper::meta_resetting_guard<F2, MP> guard{rhs};
Expand Down
Loading
Loading