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

source code of libcxx/test/std/ranges/range.factories/range.single.view/size.pass.cpp