forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d7f846fc6b
commit
065cf3f9d7
|
@ -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]",,,
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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 = ptrdiff_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>
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue