Skip to content

Commit

Permalink
Use conditional explicit unconditionally (microsoft#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored and fsb4000 committed Aug 13, 2022
1 parent 47ff24b commit 48f9d8c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 393 deletions.
47 changes: 0 additions & 47 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,9 @@ public:
using _AllowDirectConversion = bool_constant<conjunction_v<negation<is_same<_Remove_cvref_t<_Ty2>, optional>>,
negation<is_same<_Remove_cvref_t<_Ty2>, in_place_t>>, is_constructible<_Ty, _Ty2>>>;

#if _HAS_CONDITIONAL_EXPLICIT
template <class _Ty2 = _Ty, enable_if_t<_AllowDirectConversion<_Ty2>::value, int> = 0>
constexpr explicit(!is_convertible_v<_Ty2, _Ty>) optional(_Ty2&& _Right)
: _Mybase(in_place, _STD forward<_Ty2>(_Right)) {}
#else // ^^^ _HAS_CONDITIONAL_EXPLICIT ^^^ / vvv !_HAS_CONDITIONAL_EXPLICIT vvv
template <class _Ty2 = _Ty,
enable_if_t<conjunction_v<_AllowDirectConversion<_Ty2>, is_convertible<_Ty2, _Ty>>, int> = 0>
constexpr optional(_Ty2&& _Right) : _Mybase(in_place, _STD forward<_Ty2>(_Right)) {}
template <class _Ty2 = _Ty,
enable_if_t<conjunction_v<_AllowDirectConversion<_Ty2>, negation<is_convertible<_Ty2, _Ty>>>, int> = 0>
constexpr explicit optional(_Ty2&& _Right) : _Mybase(in_place, _STD forward<_Ty2>(_Right)) {}
#endif // ^^^ !_HAS_CONDITIONAL_EXPLICIT ^^^

template <class _Ty2>
struct _AllowUnwrapping : bool_constant<!disjunction_v<is_same<_Ty, _Ty2>, is_constructible<_Ty, optional<_Ty2>&>,
Expand All @@ -252,58 +243,20 @@ public:
is_convertible<optional<_Ty2>&, _Ty>, is_convertible<const optional<_Ty2>&, _Ty>,
is_convertible<const optional<_Ty2>, _Ty>, is_convertible<optional<_Ty2>, _Ty>>> {};

#if _HAS_CONDITIONAL_EXPLICIT
template <class _Ty2,
enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, const _Ty2&>>, int> = 0>
_CONSTEXPR20 explicit(!is_convertible_v<const _Ty2&, _Ty>) optional(const optional<_Ty2>& _Right) {
if (_Right) {
this->_Construct(*_Right);
}
}
#else // ^^^ _HAS_CONDITIONAL_EXPLICIT ^^^ / vvv !_HAS_CONDITIONAL_EXPLICIT vvv
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, const _Ty2&>,
is_convertible<const _Ty2&, _Ty>>,
int> = 0>
optional(const optional<_Ty2>& _Right) {
if (_Right) {
this->_Construct(*_Right);
}
}
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, const _Ty2&>,
negation<is_convertible<const _Ty2&, _Ty>>>,
int> = 0>
explicit optional(const optional<_Ty2>& _Right) {
if (_Right) {
this->_Construct(*_Right);
}
}
#endif // ^^^ !_HAS_CONDITIONAL_EXPLICIT ^^^

#if _HAS_CONDITIONAL_EXPLICIT
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, _Ty2>>, int> = 0>
_CONSTEXPR20 explicit(!is_convertible_v<_Ty2, _Ty>) optional(optional<_Ty2>&& _Right) {
if (_Right) {
this->_Construct(_STD move(*_Right));
}
}
#else // ^^^ _HAS_CONDITIONAL_EXPLICIT ^^^ / vvv !_HAS_CONDITIONAL_EXPLICIT vvv
template <class _Ty2,
enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, _Ty2>, is_convertible<_Ty2, _Ty>>,
int> = 0>
optional(optional<_Ty2>&& _Right) {
if (_Right) {
this->_Construct(_STD move(*_Right));
}
}
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, _Ty2>,
negation<is_convertible<_Ty2, _Ty>>>,
int> = 0>
explicit optional(optional<_Ty2>&& _Right) {
if (_Right) {
this->_Construct(_STD move(*_Right));
}
}
#endif // ^^^ !_HAS_CONDITIONAL_EXPLICIT ^^^

#if _HAS_CXX23
template <class _Fn, class _Ux>
Expand Down
Loading

0 comments on commit 48f9d8c

Please sign in to comment.