Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | // -*- C++ -*- |
|---|---|
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CXX03___ITERATOR_DISTANCE_H |
| 11 | #define _LIBCPP___CXX03___ITERATOR_DISTANCE_H |
| 12 | |
| 13 | #include <__cxx03/__config> |
| 14 | #include <__cxx03/__iterator/iterator_traits.h> |
| 15 | #include <__cxx03/__type_traits/decay.h> |
| 16 | #include <__cxx03/__type_traits/remove_cvref.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 | template <class _InputIter> |
| 25 | inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_InputIter>::difference_type |
| 26 | __distance(_InputIter __first, _InputIter __last, input_iterator_tag) { |
| 27 | typename iterator_traits<_InputIter>::difference_type __r(0); |
| 28 | for (; __first != __last; ++__first) |
| 29 | ++__r; |
| 30 | return __r; |
| 31 | } |
| 32 | |
| 33 | template <class _RandIter> |
| 34 | inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_RandIter>::difference_type |
| 35 | __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) { |
| 36 | return __last - __first; |
| 37 | } |
| 38 | |
| 39 | template <class _InputIter> |
| 40 | inline _LIBCPP_HIDE_FROM_ABI typename iterator_traits<_InputIter>::difference_type |
| 41 | distance(_InputIter __first, _InputIter __last) { |
| 42 | return std::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); |
| 43 | } |
| 44 | |
| 45 | _LIBCPP_END_NAMESPACE_STD |
| 46 | |
| 47 | #endif // _LIBCPP___CXX03___ITERATOR_DISTANCE_H |
| 48 |
Warning: This file is not a C or C++ file. It does not have highlighting.
