Skip to content

Commit 5637421

Browse files
committed
Improve parallelism in implementation
Improve the parallelism in t he declarations in the implementation to clarify that the difference in the overloads is due to the 'Other' parameter for removing it from consideration for overload since the U parameter is *already* a reference. Checking for 'const U&' is no longer the right thing to check.
1 parent 41ac3b7 commit 5637421

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

include/beman/optional26/optional.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ class optional {
283283
requires(!std::is_reference_v<U> && detail::enable_from_other<T, U, const U&>);
284284

285285
template <class U>
286-
constexpr explicit(!std::is_convertible_v<U&, T>) optional(const optional<U&>& rhs)
287-
requires(detail::enable_from_other<T, U&, U&>);
286+
constexpr explicit(!std::is_convertible_v<U, T>) optional(const optional<U>& rhs)
287+
requires(std::is_reference_v<U> && detail::enable_from_other<T, U, U>);
288288

289289
template <class U>
290290
constexpr explicit(!std::is_convertible_v<U, T>) optional(optional<U>&& rhs)
@@ -328,12 +328,12 @@ class optional {
328328
requires(!std::is_reference_v<U> && detail::enable_assign_from_other<T, U, const U&>);
329329

330330
template <class U>
331-
constexpr optional& operator=(optional<U>&& rhs)
332-
requires(!std::is_reference_v<U> && detail::enable_assign_from_other<T, U, U>);
331+
constexpr optional& operator=(const optional<U>& rhs)
332+
requires(std::is_reference_v<U> && detail::enable_assign_from_other<T, U, U>);
333333

334334
template <class U>
335-
constexpr optional& operator=(const optional<U&>& rhs)
336-
requires(detail::enable_assign_from_other<T, U&, U&>);
335+
constexpr optional& operator=(optional<U>&& rhs)
336+
requires(!std::is_reference_v<U> && detail::enable_assign_from_other<T, U, U>);
337337

338338
template <class... Args>
339339
constexpr T& emplace(Args&&... args);
@@ -477,8 +477,8 @@ inline constexpr optional<T>::optional(const optional<U>& rhs)
477477
/// Converting copy constructor for U&
478478
template <class T>
479479
template <class U>
480-
inline constexpr optional<T>::optional(const optional<U&>& rhs)
481-
requires(detail::enable_from_other<T, U&, U&>)
480+
inline constexpr optional<T>::optional(const optional<U>& rhs)
481+
requires(std::is_reference_v<U> && detail::enable_from_other<T, U, U>)
482482
{
483483
if (rhs.has_value()) {
484484
construct(*rhs);
@@ -585,8 +585,8 @@ inline constexpr optional<T>& optional<T>::operator=(const optional<U>& rhs)
585585

586586
template <class T>
587587
template <class U>
588-
inline constexpr optional<T>& optional<T>::operator=(const optional<U&>& rhs)
589-
requires(detail::enable_assign_from_other<T, U&, U&>)
588+
inline constexpr optional<T>& optional<T>::operator=(const optional<U>& rhs)
589+
requires(std::is_reference_v<U> && detail::enable_assign_from_other<T, U, U>)
590590
{
591591
if (has_value()) {
592592
if (rhs.has_value()) {
@@ -627,7 +627,6 @@ inline constexpr optional<T>& optional<T>::operator=(optional<U>&& rhs)
627627
return *this;
628628
}
629629

630-
631630
/// Constructs the value in-place, destroying the current one if there is
632631
/// one.
633632
template <class T>

0 commit comments

Comments
 (0)