File indexing completed on 2026-05-03 08:13:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_UNWRAP_ITER_H
0010 #define _LIBCPP___ALGORITHM_UNWRAP_ITER_H
0011
0012 #include <__config>
0013 #include <__iterator/iterator_traits.h>
0014 #include <__memory/pointer_traits.h>
0015 #include <__type_traits/enable_if.h>
0016 #include <__type_traits/is_constructible.h>
0017 #include <__utility/declval.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
0030
0031
0032
0033
0034
0035
0036
0037 template <class _Iter, bool = __libcpp_is_contiguous_iterator<_Iter>::value>
0038 struct __unwrap_iter_impl {
0039 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter, _Iter __iter) { return __iter; }
0040 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __unwrap(_Iter __i) _NOEXCEPT { return __i; }
0041 };
0042
0043
0044
0045
0046
0047 template <class _Iter>
0048 struct __unwrap_iter_impl<_Iter, true> {
0049 using _ToAddressT _LIBCPP_NODEBUG = decltype(std::__to_address(std::declval<_Iter>()));
0050
0051 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) {
0052 return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter));
0053 }
0054
0055 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToAddressT __unwrap(_Iter __i) _NOEXCEPT {
0056 return std::__to_address(__i);
0057 }
0058 };
0059
0060 template <class _Iter,
0061 class _Impl = __unwrap_iter_impl<_Iter>,
0062 __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
0063 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>()))
0064 __unwrap_iter(_Iter __i) _NOEXCEPT {
0065 return _Impl::__unwrap(__i);
0066 }
0067
0068
0069 #if _LIBCPP_STD_VER >= 20
0070 template <class _Iter, __enable_if_t<!is_copy_constructible<_Iter>::value, int> = 0>
0071 inline _LIBCPP_HIDE_FROM_ABI constexpr _Iter __unwrap_iter(_Iter __i) noexcept {
0072 return __i;
0073 }
0074 #endif
0075
0076 template <class _OrigIter, class _Iter, class _Impl = __unwrap_iter_impl<_OrigIter> >
0077 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT {
0078 return _Impl::__rewrap(std::move(__orig_iter), std::move(__iter));
0079 }
0080
0081 _LIBCPP_END_NAMESPACE_STD
0082
0083 _LIBCPP_POP_MACROS
0084
0085 #endif