[libcxx-commits] [libcxx] 065cf3f - [libcxx][ranges] Add `default_sentinel` and `default_sentinel_t`.
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 1 14:07:16 PDT 2021
Author: zoecarver
Date: 2021-06-01T14:03:54-07:00
New Revision: 065cf3f9d70374d0a02f1e15be32eaaa59f01466
URL: https://github.com/llvm/llvm-project/commit/065cf3f9d70374d0a02f1e15be32eaaa59f01466
DIFF: https://github.com/llvm/llvm-project/commit/065cf3f9d70374d0a02f1e15be32eaaa59f01466.diff
LOG: [libcxx][ranges] Add `default_sentinel` and `default_sentinel_t`.
Refs https://eel.is/c++draft/default.sentinel and https://eel.is/c++draft/iterator.synopsis
Differential Revision: https://reviews.llvm.org/D103487
Added:
libcxx/include/__iterator/default_sentinel.h
libcxx/test/std/iterators/predef.iterators/default.sentinel/default.sentinel.pass.cpp
Modified:
libcxx/docs/OneRangesProposalStatus.csv
libcxx/include/CMakeLists.txt
libcxx/include/iterator
Removed:
################################################################################
diff --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv
index 0917282c70dd2..95e3030f6e295 100644
--- a/libcxx/docs/OneRangesProposalStatus.csv
+++ b/libcxx/docs/OneRangesProposalStatus.csv
@@ -31,7 +31,7 @@ bidirectional_iterator: `D100278 <https://llvm.org/D100278>`_",
[predef.iterators],Updates to predefined iterators.,"[iterator.concepts], [iterator.cust.swap], [iterator.cust.move]",,,
[move.sentinel],,[concepts] … Note: for testing it may be beneficial to have completed [predef.iterators]. ,,,
[common.iterator],,"[iterator.concepts], [iterator.cust.swap], [iterator.cust.move]",Zoe Carver,,
-[default.sentinels],The empty std::default_sentinel_t.,,,,
+[default.sentinels],The empty std::default_sentinel_t.,,Zoe Carver,,✅
[counted.iterator],,"[iterator.concepts], [iterator.cust.swap], [iterator.cust.move], [default.sentinels]",,,
[stream.iterators],,[default.sentinels],,,
[ranges.syn]: pt. 1,All the stuff not specified elsewhere. ,"[range.access], [iterator.concepts], [range.all], [range.subrange], unreachable, [range.empty]",,,
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 89b996671b23e..b0c7b47958f30 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -16,6 +16,7 @@ set(files
__hash_table
__iterator/advance.h
__iterator/concepts.h
+ __iterator/default_sentinel.h
__iterator/incrementable_traits.h
__iterator/indirect_concepts.h
__iterator/iter_move.h
diff --git a/libcxx/include/__iterator/default_sentinel.h b/libcxx/include/__iterator/default_sentinel.h
new file mode 100644
index 0000000000000..934a56fd9e29b
--- /dev/null
+++ b/libcxx/include/__iterator/default_sentinel.h
@@ -0,0 +1,35 @@
+// -*- 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___ITERATOR_DEFAULT_SENTINEL_H
+#define _LIBCPP___ITERATOR_DEFAULT_SENTINEL_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_RANGES)
+
+struct default_sentinel_t { };
+inline constexpr default_sentinel_t default_sentinel{};
+
+#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ITERATOR_DEFAULT_SENTINEL_H
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index 364c74325b180..9d9a5532a2c63 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -383,6 +383,9 @@ constexpr move_iterator<Iterator> operator+( // constexpr in C++17
template <class Iterator> // constexpr in C++17
constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
+// [default.sentinel], default sentinel
+struct default_sentinel_t;
+inline constexpr default_sentinel_t default_sentinel{};
template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptr
diff _t>
class istream_iterator
@@ -554,6 +557,7 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#include <__functional_base>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/indirect_concepts.h>
#include <__iterator/iter_move.h>
diff --git a/libcxx/test/std/iterators/predef.iterators/default.sentinel/default.sentinel.pass.cpp b/libcxx/test/std/iterators/predef.iterators/default.sentinel/default.sentinel.pass.cpp
new file mode 100644
index 0000000000000..8c8487950f287
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/default.sentinel/default.sentinel.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: gcc-10
+
+// struct default_sentinel_t;
+// inline constexpr default_sentinel_t default_sentinel;
+
+#include <iterator>
+
+#include <concepts>
+#include <type_traits>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ static_assert(std::is_empty_v<std::default_sentinel_t>);
+ static_assert(std::semiregular<std::default_sentinel_t>);
+
+ static_assert(std::same_as<decltype(std::default_sentinel), const std::default_sentinel_t>);
+
+ std::default_sentinel_t s1;
+ auto s2 = std::default_sentinel_t{};
+ s2 = s1;
+
+ return 0;
+}
More information about the libcxx-commits
mailing list