Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:01

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___RANGES_COUNTED_H
0011 #define _LIBCPP___RANGES_COUNTED_H
0012 
0013 #include <__concepts/convertible_to.h>
0014 #include <__config>
0015 #include <__cstddef/size_t.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/counted_iterator.h>
0018 #include <__iterator/default_sentinel.h>
0019 #include <__iterator/incrementable_traits.h>
0020 #include <__iterator/iterator_traits.h>
0021 #include <__memory/pointer_traits.h>
0022 #include <__ranges/subrange.h>
0023 #include <__type_traits/decay.h>
0024 #include <__utility/forward.h>
0025 #include <__utility/move.h>
0026 #include <span>
0027 
0028 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0029 #  pragma GCC system_header
0030 #endif
0031 
0032 _LIBCPP_PUSH_MACROS
0033 #include <__undef_macros>
0034 
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036 
0037 #if _LIBCPP_STD_VER >= 20
0038 
0039 namespace ranges::views {
0040 
0041 namespace __counted {
0042 
0043 struct __fn {
0044   template <contiguous_iterator _It>
0045   _LIBCPP_HIDE_FROM_ABI static constexpr auto
0046   __go(_It __it,
0047        iter_difference_t<_It> __count) noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))
0048   // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly
0049   {
0050     return span(std::to_address(__it), static_cast<size_t>(__count));
0051   }
0052 
0053   template <random_access_iterator _It>
0054   _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(
0055       noexcept(subrange(__it, __it + __count))) -> decltype(subrange(__it, __it + __count)) {
0056     return subrange(__it, __it + __count);
0057   }
0058 
0059   template <class _It>
0060   _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(
0061       noexcept(subrange(counted_iterator(std::move(__it), __count), default_sentinel)))
0062       -> decltype(subrange(counted_iterator(std::move(__it), __count), default_sentinel)) {
0063     return subrange(counted_iterator(std::move(__it), __count), default_sentinel);
0064   }
0065 
0066   template <class _It, convertible_to<iter_difference_t<_It>> _Diff>
0067     requires input_or_output_iterator<decay_t<_It>>
0068   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_It&& __it, _Diff&& __count) const
0069       noexcept(noexcept(__go(std::forward<_It>(__it), std::forward<_Diff>(__count))))
0070           -> decltype(__go(std::forward<_It>(__it), std::forward<_Diff>(__count))) {
0071     return __go(std::forward<_It>(__it), std::forward<_Diff>(__count));
0072   }
0073 };
0074 
0075 } // namespace __counted
0076 
0077 inline namespace __cpo {
0078 inline constexpr auto counted = __counted::__fn{};
0079 } // namespace __cpo
0080 
0081 } // namespace ranges::views
0082 
0083 #endif // _LIBCPP_STD_VER >= 20
0084 
0085 _LIBCPP_END_NAMESPACE_STD
0086 
0087 _LIBCPP_POP_MACROS
0088 
0089 #endif // _LIBCPP___RANGES_COUNTED_H