xref: /llvm-project/libcxx/include/__algorithm/iterator_operations.h (revision 96b674f23cd66e8fee9efde6003dc2032acf58b6)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___ALGORIHTM_ITERATOR_OPERATIONS_H
10 #define _LIBCPP___ALGORIHTM_ITERATOR_OPERATIONS_H
11 
12 #include <__config>
13 #include <__iterator/advance.h>
14 #include <__iterator/distance.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__iterator/next.h>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #  pragma GCC system_header
20 #endif
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
25 struct _RangesIterOps {
26   static constexpr auto advance = ranges::advance;
27   static constexpr auto distance = ranges::distance;
28   static constexpr auto next = ranges::next;
29 };
30 #endif
31 
32 struct _StdIterOps {
33 
34   template <class _Iterator, class _Distance>
35   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 void advance(_Iterator& __iter, _Distance __count) {
36     return std::advance(__iter, __count);
37   }
38 
39   template <class _Iterator>
40   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
41   typename iterator_traits<_Iterator>::difference_type distance(_Iterator __first, _Iterator __last) {
42     return std::distance(__first, __last);
43   }
44 
45   template <class _Iterator>
46   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11
47   _Iterator next(_Iterator, _Iterator __last) {
48     return __last;
49   }
50 
51 };
52 
53 _LIBCPP_END_NAMESPACE_STD
54 
55 #endif // _LIBCPP___ALGORIHTM_ITERATOR_OPERATIONS_H
56