65 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 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 20struct Empty {};21struct BigType {22 char buffer[64] = {10};23};24 25template <typename T>26constexpr void test_empty(T value) {27 using SingleView = std::ranges::single_view<T>;28 29 {30 std::same_as<bool> decltype(auto) result = SingleView::empty();31 assert(result == false);32 static_assert(noexcept(SingleView::empty()));33 }34 35 {36 SingleView sv{value};37 38 std::same_as<bool> decltype(auto) result = std::ranges::empty(sv);39 assert(result == false);40 static_assert(noexcept(std::ranges::empty(sv)));41 }42 {43 const SingleView sv{value};44 45 std::same_as<bool> decltype(auto) result = std::ranges::empty(sv);46 assert(result == false);47 static_assert(noexcept(std::ranges::empty(std::as_const(sv))));48 }49}50 51constexpr bool test() {52 test_empty<int>(92);53 test_empty<Empty>(Empty{});54 test_empty<BigType>(BigType{});55 56 return true;57}58 59int main(int, char**) {60 test();61 static_assert(test());62 63 return 0;64}65