1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___RANGES_EMPTY_VIEW_H
11#define _LIBCPP___RANGES_EMPTY_VIEW_H
12
13#include <__config>
14#include <__ranges/enable_borrowed_range.h>
15#include <__ranges/view_interface.h>
16#include <__type_traits/is_object.h>
17#include <cstddef>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if _LIBCPP_STD_VER >= 20
26
27namespace ranges {
28template <class _Tp>
29 requires is_object_v<_Tp>
30class empty_view : public view_interface<empty_view<_Tp>> {
31public:
32 _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* begin() noexcept { return nullptr; }
33 _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* end() noexcept { return nullptr; }
34 _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* data() noexcept { return nullptr; }
35 _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; }
36 _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; }
37};
38
39template <class _Tp>
40inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true;
41
42namespace views {
43
44template <class _Tp>
45inline constexpr empty_view<_Tp> empty{};
46
47} // namespace views
48} // namespace ranges
49
50#endif // _LIBCPP_STD_VER >= 20
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___RANGES_EMPTY_VIEW_H
55