std::ranges::views::empty,std::ranges::empty_view(3)

NAME
std::ranges::views::empty,std::ranges::empty_view - std::ranges::views::empty,std::ranges::empty_view

Synopsis
   Defined in header <ranges>
   template<class T>
       requires std::is_object_v<T> (1) (since C++20)
   class empty_view : public ranges::view_interface<empty_view<T>>
   namespace views {
       template<class T> inline constexpr empty_view<T> empty{}; (2) (since C++20)
   }
   1) A range factory that produces a view of no elements of a particular type.
   2) Variable template for empty_view.

Member functions
   begin returns nullptr
   [static] (C++20) (public static member function)
   end returns nullptr
   [static] (C++20) (public static member function)
   data returns nullptr
   [static] (C++20) (public static member function)
   size returns 0 (zero)
   [static] (C++20) (public static member function)
   empty returns true
   [static] (C++20) (public static member function)
         Inherited from std::ranges::view_interface
   cbegin returns a constant iterator to the beginning of the range.
   (C++23) (public member function of std::ranges::view_interface<D>)
   cend returns a sentinel for the constant iterator of the range.
   (C++23) (public member function of std::ranges::view_interface<D>)
   operator bool returns whether the derived view is not empty. Provided if
   (C++20) ranges::empty is applicable to it.
                    (public member function of std::ranges::view_interface<D>)
   front returns the first element in the derived view. Provided if it
   (C++20) satisfies forward_range.
                    (public member function of std::ranges::view_interface<D>)
   back returns the last element in the derived view. Provided if it
   (C++20) satisfies bidirectional_range and common_range.
                    (public member function of std::ranges::view_interface<D>)
   operator[] returns the n^th element in the derived view. Provided if it
   (C++20) satisfies random_access_range.
                    (public member function of std::ranges::view_interface<D>) std::ranges::empty_view::begin
   static constexpr T* begin() noexcept { return nullptr; } (since C++20)
   empty_view does not reference any element. std::ranges::empty_view::end
   static constexpr T* end() noexcept { return nullptr; } (since C++20)
   empty_view does not reference any element. std::ranges::empty_view::data
   static constexpr T* data() noexcept { return nullptr; } (since C++20)
   empty_view does not reference any element. std::ranges::empty_view::size
   static constexpr std::size_t size() noexcept { return 0; } (since C++20)
   empty_view is always empty. std::ranges::empty_view::empty
   static constexpr bool empty() noexcept { return true; } (since C++20)
   empty_view is always empty.
   Helper templates
   template<class T>
   inline constexpr bool enable_borrowed_range<ranges::empty_view<T>> = (since C++20)
   true;
   This specialization of std::ranges::enable_borrowed_range makes empty_view satisfy
   borrowed_range.

Notes
   Although empty_view obtains front, back, and operator[] member functions from
   view_interface, calls to them always result in undefined behavior since an
   empty_view is always empty.
   The inherited operator bool conversion function always returns false.

Example
// Run this code
 #include <ranges>
 int main()
 {
     std::ranges::empty_view<long> e;
     static_assert(std::ranges::empty(e));
     static_assert(0 == e.size());
     static_assert(nullptr == e.data());
     static_assert(nullptr == e.begin());
     static_assert(nullptr == e.end());
 }

See also
   ranges::single_view a view that contains a single element of a specified value
   views::single (class template) (customization point object)
   (C++20)
   views::all_t a view that includes all elements of a range
   views::all (alias template) (range adaptor object)
   (C++20)
   ranges::ref_view a view of the elements of some other range
   (C++20) (class template)