Path: blob/main/contrib/llvm-project/libcxx/include/__ranges/counted.h
35236 views
// -*- C++ -*-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-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___RANGES_COUNTED_H10#define _LIBCPP___RANGES_COUNTED_H1112#include <__concepts/convertible_to.h>13#include <__config>14#include <__iterator/concepts.h>15#include <__iterator/counted_iterator.h>16#include <__iterator/default_sentinel.h>17#include <__iterator/incrementable_traits.h>18#include <__iterator/iterator_traits.h>19#include <__memory/pointer_traits.h>20#include <__ranges/subrange.h>21#include <__type_traits/decay.h>22#include <__utility/forward.h>23#include <__utility/move.h>24#include <cstddef>25#include <span>2627#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)28# pragma GCC system_header29#endif3031_LIBCPP_PUSH_MACROS32#include <__undef_macros>3334_LIBCPP_BEGIN_NAMESPACE_STD3536#if _LIBCPP_STD_VER >= 203738namespace ranges::views {3940namespace __counted {4142struct __fn {43template <contiguous_iterator _It>44_LIBCPP_HIDE_FROM_ABI static constexpr auto45__go(_It __it,46iter_difference_t<_It> __count) noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count))))47// Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly48{49return span(std::to_address(__it), static_cast<size_t>(__count));50}5152template <random_access_iterator _It>53_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(54noexcept(subrange(__it, __it + __count))) -> decltype(subrange(__it, __it + __count)) {55return subrange(__it, __it + __count);56}5758template <class _It>59_LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_It __it, iter_difference_t<_It> __count) noexcept(60noexcept(subrange(counted_iterator(std::move(__it), __count), default_sentinel)))61-> decltype(subrange(counted_iterator(std::move(__it), __count), default_sentinel)) {62return subrange(counted_iterator(std::move(__it), __count), default_sentinel);63}6465template <class _It, convertible_to<iter_difference_t<_It>> _Diff>66requires input_or_output_iterator<decay_t<_It>>67[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_It&& __it, _Diff&& __count) const68noexcept(noexcept(__go(std::forward<_It>(__it), std::forward<_Diff>(__count))))69-> decltype(__go(std::forward<_It>(__it), std::forward<_Diff>(__count))) {70return __go(std::forward<_It>(__it), std::forward<_Diff>(__count));71}72};7374} // namespace __counted7576inline namespace __cpo {77inline constexpr auto counted = __counted::__fn{};78} // namespace __cpo7980} // namespace ranges::views8182#endif // _LIBCPP_STD_VER >= 208384_LIBCPP_END_NAMESPACE_STD8586_LIBCPP_POP_MACROS8788#endif // _LIBCPP___RANGES_COUNTED_H899091