Skip to content

Commit 7756216

Browse files
committed
[libc++] NFCI: Remove code duplication and obsolete declarations in wrap_iter
Differential Revision: https://reviews.llvm.org/D105040
1 parent e63b18b commit 7756216

File tree

2 files changed

+35
-187
lines changed

2 files changed

+35
-187
lines changed

libcxx/include/__algorithm/inplace_merge.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
#define _LIBCPP___ALGORITHM_INPLACE_MERGE_H
1111

1212
#include <__config>
13-
#include <__algorithm/comp.h>
1413
#include <__algorithm/comp_ref_type.h>
15-
#include <__algorithm/rotate.h>
14+
#include <__algorithm/comp.h>
1615
#include <__algorithm/lower_bound.h>
1716
#include <__algorithm/min.h>
17+
#include <__algorithm/move.h>
18+
#include <__algorithm/rotate.h>
1819
#include <__algorithm/upper_bound.h>
1920
#include <__iterator/iterator_traits.h>
2021
#include <__utility/swap.h>

libcxx/include/__iterator/wrap_iter.h

Lines changed: 32 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,6 @@ _LIBCPP_PUSH_MACROS
2525

2626
_LIBCPP_BEGIN_NAMESPACE_STD
2727

28-
template <class _Iter> class __wrap_iter;
29-
30-
template <class _Iter1, class _Iter2>
31-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
32-
bool
33-
operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
34-
35-
template <class _Iter1, class _Iter2>
36-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
37-
bool
38-
operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
39-
40-
template <class _Iter1, class _Iter2>
41-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
42-
bool
43-
operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
44-
45-
template <class _Iter1, class _Iter2>
46-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
47-
bool
48-
operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
49-
50-
template <class _Iter1, class _Iter2>
51-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
52-
bool
53-
operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
54-
55-
template <class _Iter1, class _Iter2>
56-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
57-
bool
58-
operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
59-
60-
#ifndef _LIBCPP_CXX03_LANG
61-
template <class _Iter1, class _Iter2>
62-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
63-
auto
64-
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
65-
-> decltype(__x.base() - __y.base());
66-
#else
67-
template <class _Iter1, class _Iter2>
68-
_LIBCPP_INLINE_VISIBILITY
69-
typename __wrap_iter<_Iter1>::difference_type
70-
operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
71-
#endif
72-
73-
template <class _Iter>
74-
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
75-
__wrap_iter<_Iter>
76-
operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
77-
78-
template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
79-
template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
80-
template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
81-
template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
82-
8328
template <class _Iter>
8429
class __wrap_iter
8530
{
@@ -217,80 +162,18 @@ class __wrap_iter
217162
template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
218163
template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
219164
template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
220-
221-
template <class _Iter1, class _Iter2>
222-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
223-
bool
224-
operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
225-
226-
template <class _Iter1, class _Iter2>
227-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
228-
bool
229-
operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
230-
231-
template <class _Iter1, class _Iter2>
232-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
233-
bool
234-
operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
235-
236-
template <class _Iter1, class _Iter2>
237-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
238-
bool
239-
operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
240-
241-
template <class _Iter1, class _Iter2>
242-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
243-
bool
244-
operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
245-
246-
template <class _Iter1, class _Iter2>
247-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
248-
bool
249-
operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
250-
251-
#ifndef _LIBCPP_CXX03_LANG
252-
template <class _Iter1, class _Iter2>
253-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
254-
auto
255-
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
256-
-> decltype(__x.base() - __y.base());
257-
#else
258-
template <class _Iter1, class _Iter2>
259-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
260-
typename __wrap_iter<_Iter1>::difference_type
261-
operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
262-
#endif
263-
264-
template <class _Iter1>
265-
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
266-
__wrap_iter<_Iter1>
267-
operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
268165
};
269166

270-
#if _LIBCPP_STD_VER <= 17
271-
template <class _It>
272-
struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
273-
#endif
274-
275-
template <class _Iter>
276-
_LIBCPP_CONSTEXPR
277-
decltype(_VSTD::__to_address(declval<_Iter>()))
278-
__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
279-
return _VSTD::__to_address(__w.base());
280-
}
281-
282167
template <class _Iter1, class _Iter2>
283-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
284-
bool
285-
operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
168+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
169+
bool operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
286170
{
287171
return __x.base() == __y.base();
288172
}
289173

290174
template <class _Iter1, class _Iter2>
291-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
292-
bool
293-
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
175+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
176+
bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
294177
{
295178
#if _LIBCPP_DEBUG_LEVEL == 2
296179
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
@@ -300,106 +183,70 @@ operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC
300183
}
301184

302185
template <class _Iter1, class _Iter2>
303-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
304-
bool
305-
operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
186+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
187+
bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
306188
{
307189
return !(__x == __y);
308190
}
309191

310192
template <class _Iter1, class _Iter2>
311-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
312-
bool
313-
operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
193+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
194+
bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
314195
{
315196
return __y < __x;
316197
}
317198

318199
template <class _Iter1, class _Iter2>
319-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
320-
bool
321-
operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
200+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
201+
bool operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
322202
{
323203
return !(__x < __y);
324204
}
325205

326206
template <class _Iter1, class _Iter2>
327-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
328-
bool
329-
operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
330-
{
331-
return !(__y < __x);
332-
}
333-
334-
template <class _Iter1>
335-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
336-
bool
337-
operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
338-
{
339-
return !(__x == __y);
340-
}
341-
342-
template <class _Iter1>
343-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
344-
bool
345-
operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
346-
{
347-
return __y < __x;
348-
}
349-
350-
template <class _Iter1>
351-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
352-
bool
353-
operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
354-
{
355-
return !(__x < __y);
356-
}
357-
358-
template <class _Iter1>
359-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
360-
bool
361-
operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
207+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
208+
bool operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
362209
{
363210
return !(__y < __x);
364211
}
365212

366-
#ifndef _LIBCPP_CXX03_LANG
367213
template <class _Iter1, class _Iter2>
368-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
369-
auto
370-
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
371-
-> decltype(__x.base() - __y.base())
372-
{
373-
#if _LIBCPP_DEBUG_LEVEL == 2
374-
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
375-
"Attempted to subtract incompatible iterators");
376-
#endif
377-
return __x.base() - __y.base();
378-
}
214+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
215+
#ifndef _LIBCPP_CXX03_LANG
216+
auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
217+
-> decltype(__x.base() - __y.base())
379218
#else
380-
template <class _Iter1, class _Iter2>
381-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
382219
typename __wrap_iter<_Iter1>::difference_type
383220
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
221+
#endif // C++03
384222
{
385223
#if _LIBCPP_DEBUG_LEVEL == 2
386224
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
387225
"Attempted to subtract incompatible iterators");
388226
#endif
389227
return __x.base() - __y.base();
390228
}
391-
#endif
392229

393-
template <class _Iter>
394-
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
395-
__wrap_iter<_Iter>
396-
operator+(typename __wrap_iter<_Iter>::difference_type __n,
397-
__wrap_iter<_Iter> __x) _NOEXCEPT
230+
template <class _Iter1>
231+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
232+
__wrap_iter<_Iter1> operator+(typename __wrap_iter<_Iter1>::difference_type __n, __wrap_iter<_Iter1> __x) _NOEXCEPT
398233
{
399234
__x += __n;
400235
return __x;
401236
}
402237

238+
#if _LIBCPP_STD_VER <= 17
239+
template <class _It>
240+
struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
241+
#endif
242+
243+
template <class _Iter>
244+
_LIBCPP_CONSTEXPR
245+
decltype(_VSTD::__to_address(declval<_Iter>()))
246+
__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
247+
return _VSTD::__to_address(__w.base());
248+
}
249+
403250
_LIBCPP_END_NAMESPACE_STD
404251

405252
_LIBCPP_POP_MACROS

0 commit comments

Comments
 (0)