empty_view.h 1.6 KB

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