std::ranges...::empty_view(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

Hii bestie πŸ’– welcome to the std::ranges...::empty_view(3) page from the C++ Standard Libary manual β€” yes, the manual name is spelled exactly like that, and we're keeping it. This one is short, chaotic in the best way, and literally about a view that contains nothing. Let's go. πŸ¦‹

πŸ’– 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 ranges::empty is applicable to it. (C++20) (public member function of std::ranges::view_interface<D>).
  • front β€” returns the first element in the derived view. Provided if it satisfies forward_range. (C++20) (public member function of std::ranges::view_interface<D>).
  • back β€” returns the last element in the derived view. Provided if it satisfies bidirectional_range and common_range. (C++20) (public member function of std::ranges::view_interface<D>).
  • operator[] β€” returns the n^th element in the derived view. Provided if it satisfies random_access_range. (C++20) (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>> =
true;

(since C++20)

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; (class template) (C++20).
  • views::single β€” (customization point object) (C++20).
  • views::all_t β€” a view that includes all elements of a range; (alias template) (C++20).
  • views::all β€” (range adaptor object) (C++20).
  • ranges::ref_view β€” a view of the elements of some other range; (C++20) (class template).

kisses bestie πŸ’‹ β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::ranges...::empty_view(3).

πŸ“¦ where this page comes from