Namespaces
Variants
Views
Actions

std::ranges::views::empty, std::ranges::empty_view

From cppreference.com
< cpp‎ | ranges
 
 
 
Defined in header <ranges>
template<class T>

    requires std::is_object_v<T>

class empty_view : public ranges::view_interface<empty_view<T>>
(1) (since C++20)
namespace views {

    template<class T> inline constexpr empty_view<T> empty{};

}
(2) (since C++20)
1) A range adaptor that produces a view of no elements of a particular type.
2) Variable template for empty_view.

Contents

[edit] Helper templates

template<class T>
inline constexpr bool enable_borrowed_range<ranges::empty_view<T>> = true;

This specialization of std::ranges::enable_borrowed_range makes empty_view satisfy borrowed_range.

[edit] Member functions

begin
[static]
returns nullptr
(public static member function)
end
[static]
returns nullptr
(public static member function)
data
[static]
returns nullptr
(public static member function)
size
[static]
returns 0 (zero)
(public static member function)
empty
[static]
returns true
(public static member function)

std::ranges::empty_view::begin

static constexpr T* begin() noexcept { return nullptr; }

empty_view does not reference any element.

std::ranges::empty_view::end

static constexpr T* end() noexcept { return nullptr; }

empty_view does not reference any element.

std::ranges::empty_view::data

static constexpr T* data() noexcept { return nullptr; }

empty_view does not reference any element.

std::ranges::empty_view::size

static constexpr std::size_t size() noexcept { return 0; }

empty_view is always empty.

std::ranges::empty_view::empty

static constexpr bool empty() noexcept { return true; }

empty_view is always empty.

[edit] Example

#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());
}

[edit] See also

a view that contains a single element of a specified value
(class template) (customization point object) [edit]
a view that includes all elements of a range
(alias template) (range adaptor object) [edit]
a view of the elements of some other range
(class template) [edit]