File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
test/std/ranges/range.factories/range.single.view Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS single_view : public view_interface<s
70
70
71
71
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp* end () const noexcept { return data () + 1 ; }
72
72
73
+ _LIBCPP_HIDE_FROM_ABI static constexpr bool empty () noexcept { return false ; }
74
+
73
75
_LIBCPP_HIDE_FROM_ABI static constexpr size_t size () noexcept { return 1 ; }
74
76
75
77
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* data () noexcept { return __value_.operator ->(); }
Original file line number Diff line number Diff line change
1
+ // ===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ // UNSUPPORTED: c++03, c++11, c++14, c++17
10
+
11
+ // static constexpr bool empty() noexcept;
12
+
13
+ #include < cassert>
14
+ #include < concepts>
15
+ #include < ranges>
16
+ #include < utility>
17
+
18
+ #include " test_macros.h"
19
+
20
+ struct Empty {};
21
+ struct BigType {
22
+ char buffer[64 ] = {10 };
23
+ };
24
+
25
+ template <typename T>
26
+ constexpr void test_empty (T value) {
27
+ using SingleView = std::ranges::single_view<T>;
28
+ SingleView sv{value};
29
+
30
+ assert (!SingleView::empty ());
31
+ static_assert (noexcept (SingleView::empty ()));
32
+ static_assert (noexcept (std::ranges::empty (sv)));
33
+ static_assert (noexcept (std::ranges::empty (std::as_const (sv))));
34
+ }
35
+
36
+ constexpr bool test () {
37
+ test_empty<int >(92 );
38
+ test_empty<Empty>(Empty{});
39
+ test_empty<BigType>(BigType{});
40
+
41
+ return true ;
42
+ }
43
+
44
+ int main (int , char **) {
45
+ test ();
46
+ static_assert (test ());
47
+
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments