35 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// REQUIRES: std-at-least-c++2610 11// <optional>12 13// template <class T> class optional<T&>::iterator;14// template <class T> class optional<T&>::const_iterator;15// template <class T>16// constexpr bool ranges::enable_borrowed_range<optional<T&>> = true;17 18#include <cassert>19#include <optional>20#include <ranges>21 22template <typename T>23void borrowed_range() {24 static_assert(std::ranges::enable_borrowed_range<std::optional<T&>>);25 static_assert(std::ranges::range<std::optional<T&>> == std::ranges::borrowed_range<std::optional<T&>>);26}27 28void test_borrowed_range() {29 borrowed_range<int>();30 borrowed_range<const int>();31 borrowed_range<int[]>();32 borrowed_range<int[10]>();33 borrowed_range<int()>();34}35