Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___ALGORITHM_FOR_EACH_H
0011 #define _LIBCPP___ALGORITHM_FOR_EACH_H
0012 
0013 #include <__algorithm/for_each_segment.h>
0014 #include <__config>
0015 #include <__iterator/segmented_iterator.h>
0016 #include <__ranges/movable_box.h>
0017 #include <__utility/in_place.h>
0018 #include <__utility/move.h>
0019 
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 #  pragma GCC system_header
0022 #endif
0023 
0024 _LIBCPP_PUSH_MACROS
0025 #include <__undef_macros>
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 template <class _InputIterator, class _Function>
0030 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
0031 for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
0032   for (; __first != __last; ++__first)
0033     __f(*__first);
0034   return __f;
0035 }
0036 
0037 // __movable_box is available in C++20, but is actually a copyable-box, so optimization is only correct in C++23
0038 #if _LIBCPP_STD_VER >= 23
0039 template <class _SegmentedIterator, class _Function>
0040   requires __is_segmented_iterator<_SegmentedIterator>::value
0041 _LIBCPP_HIDE_FROM_ABI constexpr _Function
0042 for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) {
0043   ranges::__movable_box<_Function> __wrapped_func(in_place, std::move(__func));
0044   std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
0045     __wrapped_func =
0046         ranges::__movable_box<_Function>(in_place, std::for_each(__lfirst, __llast, std::move(*__wrapped_func)));
0047   });
0048   return std::move(*__wrapped_func);
0049 }
0050 #endif // _LIBCPP_STD_VER >= 23
0051 
0052 _LIBCPP_END_NAMESPACE_STD
0053 
0054 _LIBCPP_POP_MACROS
0055 
0056 #endif // _LIBCPP___ALGORITHM_FOR_EACH_H