empty_view.h 1.6 KB

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