[libcxx-commits] [libcxx] [libc++] Add a compact, bounded iterator (PR #208271)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 12 14:11:04 PDT 2026


================
@@ -0,0 +1,254 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP__STATIC_PACKED_BOUNDED_ITER_H
+#define _LIBCPP__STATIC_PACKED_BOUNDED_ITER_H
+
+#include <__assert>
+#include <__bit/bit_cast.h>
+#include <__bit/countr.h>
+#include <__compare/ordering.h>
+#include <__compare/three_way_comparable.h>
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__iterator/concepts.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iterator_traits.h>
+#include <__type_traits/is_constructible.h>
+#include <__type_traits/is_pointer.h>
+
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 26
+
+// static_packed_bounded_iter is a bounded, contiguous iterator that is aware of its container's (compile-time) maximum
+// capacity. It reuses the bottom unused bits of a pointer to keep track of its current position.
----------------
ldionne wrote:

You can find better wording, but I think it would be nice to have a few words about the iterator's representation (basically the fact that it's base + offset, both packed into the same `uintptr_t`).

```suggestion
// capacity. It reuses the bottom unused bits of a pointer to keep track of its current position. The iterator is represented as a base + the offset.
```

https://github.com/llvm/llvm-project/pull/208271


More information about the libcxx-commits mailing list