diff --git a/libcxx/docs/OneRangesProposalStatus.csv b/libcxx/docs/OneRangesProposalStatus.csv --- a/libcxx/docs/OneRangesProposalStatus.csv +++ b/libcxx/docs/OneRangesProposalStatus.csv @@ -31,7 +31,7 @@ [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 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -16,6 +16,7 @@ __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 --- /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 --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -383,6 +383,9 @@ template // constexpr in C++17 constexpr move_iterator make_move_iterator(const Iterator& i); +// [default.sentinel], default sentinel +struct default_sentinel_t; +inline constexpr default_sentinel_t default_sentinel{}; template , class Distance = ptrdiff_t> class istream_iterator @@ -554,6 +557,7 @@ #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 --- /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 + +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + static_assert(std::is_empty_v); + static_assert(std::semiregular); + + static_assert(std::same_as); + + std::default_sentinel_t s1; + auto s2 = std::default_sentinel_t{}; + s2 = s1; + + return 0; +}