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 // UNSUPPORTED: libcpp-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12 
13 // static constexpr size_t size() noexcept;
14 
15 #include <ranges>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 constexpr bool test() {
21   {
22     auto sv = std::ranges::single_view<int>(42);
23     assert(sv.size() == 1);
24 
25     ASSERT_SAME_TYPE(decltype(sv.size()), size_t);
26     static_assert(noexcept(sv.size()));
27   }
28   {
29     const auto sv = std::ranges::single_view<int>(42);
30     assert(sv.size() == 1);
31 
32     ASSERT_SAME_TYPE(decltype(sv.size()), size_t);
33     static_assert(noexcept(sv.size()));
34   }
35   {
36     auto sv = std::ranges::single_view<int>(42);
37     assert(std::ranges::size(sv) == 1);
38 
39     ASSERT_SAME_TYPE(decltype(std::ranges::size(sv)), size_t);
40     static_assert(noexcept(std::ranges::size(sv)));
41   }
42   {
43     const auto sv = std::ranges::single_view<int>(42);
44     assert(std::ranges::size(sv) == 1);
45 
46     ASSERT_SAME_TYPE(decltype(std::ranges::size(sv)), size_t);
47     static_assert(noexcept(std::ranges::size(sv)));
48   }
49 
50   // Test that it's static.
51   {
52     assert(std::ranges::single_view<int>::size() == 1);
53 
54     ASSERT_SAME_TYPE(decltype(std::ranges::single_view<int>::size()), size_t);
55     static_assert(noexcept(std::ranges::single_view<int>::size()));
56   }
57 
58   return true;
59 }
60 
61 int main(int, char**) {
62   test();
63   static_assert(test());
64 
65   return 0;
66 }
67