| 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 <__cstddef/size_t.h> |
| 15 | #include <__ranges/enable_borrowed_range.h> |
| 16 | #include <__ranges/view_interface.h> |
| 17 | #include <__type_traits/is_object.h> |
| 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 | |
| 27 | namespace ranges { |
| 28 | template <class _Tp> |
| 29 | requires is_object_v<_Tp> |
| 30 | class empty_view : public view_interface<empty_view<_Tp>> { |
| 31 | public: |
| 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 | |
| 39 | template <class _Tp> |
| 40 | inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true; |
| 41 | |
| 42 | namespace views { |
| 43 | |
| 44 | template <class _Tp> |
| 45 | inline 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 |