Skip to content

Commit

Permalink
My Little Operator: Friendship Is Magic (microsoft#2797)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored and fsb4000 committed Aug 13, 2022
1 parent 48f9d8c commit edabf43
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 385 deletions.
25 changes: 11 additions & 14 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _CONSTEXPR17 _Array_const_iterator operator+(
const ptrdiff_t _Off, _Array_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

#if !_HAS_CXX20
_NODISCARD _CONSTEXPR17 bool operator!=(const _Array_const_iterator& _Right) const noexcept {
return !(*this == _Right);
Expand Down Expand Up @@ -281,13 +287,6 @@ constexpr void _Verify_range(
}
#endif // _ITERATOR_DEBUG_LEVEL != 0

template <class _Ty, size_t _Size>
_NODISCARD _CONSTEXPR17 _Array_const_iterator<_Ty, _Size> operator+(
const ptrdiff_t _Off, _Array_const_iterator<_Ty, _Size> _Next) noexcept {
_Next += _Off;
return _Next;
}

#if _HAS_CXX20
template <class _Ty, size_t _Size>
struct pointer_traits<_Array_const_iterator<_Ty, _Size>> {
Expand Down Expand Up @@ -362,6 +361,11 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _CONSTEXPR17 _Array_iterator operator+(const ptrdiff_t _Off, _Array_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

_CONSTEXPR17 _Array_iterator& operator-=(const ptrdiff_t _Off) noexcept {
_Mybase::operator-=(_Off);
return *this;
Expand All @@ -386,13 +390,6 @@ public:
}
};

template <class _Ty, size_t _Size>
_NODISCARD _CONSTEXPR17 _Array_iterator<_Ty, _Size> operator+(
const ptrdiff_t _Off, _Array_iterator<_Ty, _Size> _Next) noexcept {
_Next += _Off;
return _Next;
}

#if _HAS_CXX20
template <class _Ty, size_t _Size>
struct pointer_traits<_Array_iterator<_Ty, _Size>> {
Expand Down
43 changes: 20 additions & 23 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,12 @@ namespace chrono {

_Time_parse_iomanip_c_str(_Time_parse_iomanip_c_str&&) = delete;

friend basic_istream<_CharT, _Traits>& operator>>(
basic_istream<_CharT, _Traits>& _Is, _Time_parse_iomanip_c_str&& _Tpi) {
from_stream(_Is, _Tpi._Fmt, _Tpi._Tp, _Tpi._Abbrev, _Tpi._Offset); // intentional ADL
return _Is;
}

const _CharT* _Fmt;
_Parsable& _Tp;
basic_string<_CharT, _Traits, _Alloc>* _Abbrev;
Expand All @@ -4494,6 +4500,12 @@ namespace chrono {

_Time_parse_iomanip(_Time_parse_iomanip&&) = delete;

friend basic_istream<_CharT, _Traits>& operator>>(
basic_istream<_CharT, _Traits>& _Is, _Time_parse_iomanip&& _Tpi) {
from_stream(_Is, _Tpi._Fmt.c_str(), _Tpi._Tp, _Tpi._Abbrev, _Tpi._Offset); // intentional ADL
return _Is;
}

const basic_string<_CharT, _Traits, _Alloc>& _Fmt;
_Parsable& _Tp;
basic_string<_CharT, _Traits, _Alloc>* _Abbrev;
Expand Down Expand Up @@ -4555,21 +4567,6 @@ namespace chrono {
basic_string<_CharT, _Traits, _Alloc>& _Abbrev, minutes& _Offset) {
return _Time_parse_iomanip{_Fmt, _Tp, _STD addressof(_Abbrev), &_Offset};
}

template <class _CharT, class _Traits, class _Alloc, class _Parsable>
basic_istream<_CharT, _Traits>& operator>>(
basic_istream<_CharT, _Traits>& _Is, _Time_parse_iomanip_c_str<_CharT, _Traits, _Alloc, _Parsable>&& _Tpi) {
from_stream(_Is, _Tpi._Fmt, _Tpi._Tp, _Tpi._Abbrev, _Tpi._Offset); // intentional ADL
return _Is;
}

template <class _CharT, class _Traits, class _Alloc, class _Parsable>
basic_istream<_CharT, _Traits>& operator>>(
basic_istream<_CharT, _Traits>& _Is, _Time_parse_iomanip<_CharT, _Traits, _Alloc, _Parsable>&& _Tpi) {
from_stream(_Is, _Tpi._Fmt.c_str(), _Tpi._Tp, _Tpi._Abbrev, _Tpi._Offset); // intentional ADL
return _Is;
}

} // namespace chrono

#ifdef __cpp_lib_format
Expand Down Expand Up @@ -4813,6 +4810,14 @@ namespace chrono {
local_time<_Duration> _Time;
const string* _Abbrev = nullptr;
const seconds* _Offset_sec = nullptr;

template <class _CharT, class _Traits>
friend basic_ostream<_CharT, _Traits>& operator<<(
basic_ostream<_CharT, _Traits>& _Os, const _Local_time_format_t& _Val) {
// Doesn't appear in the Standard, but allowed by N4885 [global.functions]/2.
// Implements N4885 [time.zone.zonedtime.nonmembers]/2 for zoned_time.
return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), _Val);
}
};

template <class _Duration>
Expand Down Expand Up @@ -5145,14 +5150,6 @@ namespace chrono {
return _Os << sys_time<_Duration>{_Val.time_since_epoch()};
}

template <class _CharT, class _Traits, class _Duration>
basic_ostream<_CharT, _Traits>& operator<<(
basic_ostream<_CharT, _Traits>& _Os, const _Local_time_format_t<_Duration>& _Val) {
// Doesn't appear in the Standard, but allowed by N4885 [global.functions]/2.
// Implements N4885 [time.zone.zonedtime.nonmembers]/2 for zoned_time.
return _Os << _STD format(_Os.getloc(), _STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), _Val);
}

template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr>
basic_ostream<_CharT, _Traits>& operator<<(
basic_ostream<_CharT, _Traits>& _Os, const zoned_time<_Duration, _TimeZonePtr>& _Val) {
Expand Down
53 changes: 23 additions & 30 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_unchecked_const_iterator operator+(
const difference_type _Off, _Deque_unchecked_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

_Deque_unchecked_const_iterator& operator-=(const difference_type _Off) noexcept {
_Myoff -= _Off;
return *this;
Expand Down Expand Up @@ -142,14 +148,6 @@ public:
_Size_type _Myoff; // offset of element in deque
};

template <class _Mydeque>
_NODISCARD _Deque_unchecked_const_iterator<_Mydeque> operator+(
typename _Deque_unchecked_const_iterator<_Mydeque>::difference_type _Off,
_Deque_unchecked_const_iterator<_Mydeque> _Next) noexcept {
_Next += _Off;
return _Next;
}

template <class _Mydeque>
class _Deque_unchecked_iterator : public _Deque_unchecked_const_iterator<_Mydeque> {
private:
Expand Down Expand Up @@ -207,6 +205,12 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_unchecked_iterator operator+(
const difference_type _Off, _Deque_unchecked_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

_Deque_unchecked_iterator& operator-=(const difference_type _Off) noexcept {
_Mybase::operator-=(_Off);
return *this;
Expand All @@ -227,14 +231,6 @@ public:
}
};

template <class _Mydeque>
_NODISCARD _Deque_unchecked_iterator<_Mydeque> operator+(
typename _Deque_unchecked_iterator<_Mydeque>::difference_type _Off,
_Deque_unchecked_iterator<_Mydeque> _Next) noexcept {
_Next += _Off;
return _Next;
}

template <class _Mydeque>
class _Deque_const_iterator : public _Iterator_base12 {
private:
Expand Down Expand Up @@ -332,6 +328,12 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_const_iterator operator+(
const difference_type _Off, _Deque_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

_Deque_const_iterator& operator-=(const difference_type _Off) noexcept {
return *this += -_Off;
}
Expand Down Expand Up @@ -430,13 +432,6 @@ public:
_Size_type _Myoff; // offset of element in deque
};

template <class _Mydeque>
_NODISCARD _Deque_const_iterator<_Mydeque> operator+(
typename _Deque_const_iterator<_Mydeque>::difference_type _Off, _Deque_const_iterator<_Mydeque> _Next) noexcept {
_Next += _Off;
return _Next;
}

template <class _Mydeque>
class _Deque_iterator : public _Deque_const_iterator<_Mydeque> {
private:
Expand Down Expand Up @@ -495,6 +490,11 @@ public:
return _Tmp;
}

_NODISCARD_FRIEND _Deque_iterator operator+(const difference_type _Off, _Deque_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}

_Deque_iterator& operator-=(const difference_type _Off) noexcept {
_Mybase::operator-=(_Off);
return *this;
Expand All @@ -519,13 +519,6 @@ public:
}
};

template <class _Mydeque>
_NODISCARD _Deque_iterator<_Mydeque> operator+(
typename _Deque_iterator<_Mydeque>::difference_type _Off, _Deque_iterator<_Mydeque> _Next) noexcept {
_Next += _Off;
return _Next;
}

template <class _Value_type, class _Size_type, class _Difference_type, class _Pointer, class _Const_pointer,
class _Reference, class _Const_reference, class _Mapptr_type>
struct _Deque_iter_types {
Expand Down
Loading

0 comments on commit edabf43

Please sign in to comment.