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