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 #ifndef _LIBCPP___RANGES_EMPTY_VIEW_H
10 #define _LIBCPP___RANGES_EMPTY_VIEW_H
11 
12 #include <__config>
13 #include <__ranges/enable_borrowed_range.h>
14 #include <__ranges/view_interface.h>
15 #include <type_traits>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
24 
25 namespace ranges {
26   template<class _Tp>
27     requires is_object_v<_Tp>
28   class empty_view : public view_interface<empty_view<_Tp>> {
29   public:
30     _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* begin() noexcept { return nullptr; }
31     _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* end() noexcept { return nullptr; }
32     _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* data() noexcept { return nullptr; }
33     _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; }
34     _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; }
35   };
36 
37   template<class _Tp>
38   inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true;
39 
40   namespace views {
41 
42   template <class _Tp>
43   inline constexpr empty_view<_Tp> empty{};
44 
45   } // namespace views
46 } // namespace ranges
47 
48 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
49 
50 _LIBCPP_END_NAMESPACE_STD
51 
52 #endif // _LIBCPP___RANGES_EMPTY_VIEW_H
53