Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:08

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H
0010 #define _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H
0011 
0012 #include <__config>
0013 #include <__iterator/segmented_iterator.h>
0014 
0015 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0016 #  pragma GCC system_header
0017 #endif
0018 
0019 _LIBCPP_BEGIN_NAMESPACE_STD
0020 
0021 // __for_each_segment is a utility function for optimizing iterating over segmented iterators linearly.
0022 // __first and __last are expected to be a segmented range. __func is expected to take a range of local iterators.
0023 // Anything that is returned from __func is ignored.
0024 
0025 template <class _SegmentedIterator, class _Functor>
0026 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
0027 __for_each_segment(_SegmentedIterator __first, _SegmentedIterator __last, _Functor __func) {
0028   using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
0029 
0030   auto __sfirst = _Traits::__segment(__first);
0031   auto __slast  = _Traits::__segment(__last);
0032 
0033   // We are in a single segment, so we might not be at the beginning or end
0034   if (__sfirst == __slast) {
0035     __func(_Traits::__local(__first), _Traits::__local(__last));
0036     return;
0037   }
0038 
0039   // We have more than one segment. Iterate over the first segment, since we might not start at the beginning
0040   __func(_Traits::__local(__first), _Traits::__end(__sfirst));
0041   ++__sfirst;
0042   // iterate over the segments which are guaranteed to be completely in the range
0043   while (__sfirst != __slast) {
0044     __func(_Traits::__begin(__sfirst), _Traits::__end(__sfirst));
0045     ++__sfirst;
0046   }
0047   // iterate over the last segment
0048   __func(_Traits::__begin(__sfirst), _Traits::__local(__last));
0049 }
0050 
0051 _LIBCPP_END_NAMESPACE_STD
0052 
0053 #endif // _LIBCPP___ALGORITHM_FOR_EACH_SEGMENT_H