[libcxx-commits] [libcxx] [libc++] Include range access headers in `<optional>` only since C++26 (PR #214688)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 7 03:38:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

<details>
<summary>Changes</summary>

Inclusions of internal range access headers address LWG4131 which patches P3168R2 "Give `std::optional` Range Support". As P3168R2 is certainly a new feature in C++26, these includes are unnecessary in old modes.

It was reported that these increased the size of `<optional>` by ~8%, so probably it is better to avoid such cost in old modes.

---
Full diff: https://github.com/llvm/llvm-project/pull/214688.diff


1 Files Affected:

- (modified) libcxx/include/optional (+7-5) 


``````````diff
diff --git a/libcxx/include/optional b/libcxx/include/optional
index bb12247b69083..0d0409ee8e2b3 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -275,12 +275,14 @@ namespace std {
 // [optional.syn]
 #  include <compare>
 
+#  if _LIBCPP_STD_VER >= 26
 // [iterator.range]
-#  include <__iterator/access.h>
-#  include <__iterator/data.h>
-#  include <__iterator/empty.h>
-#  include <__iterator/reverse_access.h>
-#  include <__iterator/size.h>
+#    include <__iterator/access.h>
+#    include <__iterator/data.h>
+#    include <__iterator/empty.h>
+#    include <__iterator/reverse_access.h>
+#    include <__iterator/size.h>
+#  endif // _LIBCPP_STD_VER >= 26
 
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #    pragma GCC system_header

``````````

</details>


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


More information about the libcxx-commits mailing list