[range.single] (original) (raw)

25.6.3.1 Overview [range.single.overview]

single_view produces a view that contains exactly one element of a specified value.

Given a subexpression E, the expressionviews​::​single(E) is expression-equivalent tosingle_view<decay_t<decltype((E))>>(E).

[Example 1: for (int i : views::single(4)) cout << i; — _end example_]

25.6.3.2 Class template single_view [range.single.view]

namespace std::ranges { template<move_constructible T> requires is_object_v<T> class single_view : public view_interface<single_view<T>> { private: movable-box<T> value_; public: single_view() requires default_initializable<T> = default;constexpr explicit single_view(const T& t) requires copy_constructible<T>;constexpr explicit single_view(T&& t);template<class... Args> requires constructible_from<T, Args...> constexpr explicit single_view(in_place_t, Args&&... args);constexpr T* begin() noexcept;constexpr const T* begin() const noexcept;constexpr T* end() noexcept;constexpr const T* end() const noexcept;static constexpr bool empty() noexcept;static constexpr size_t size() noexcept;constexpr T* data() noexcept;constexpr const T* data() const noexcept;};template<class T> single_view(T) -> single_view<T>;}

Effects: Initializes value_ with t.

constexpr explicit single_view(T&& t);

Effects: Initializes value_ with std​::​move(t).

template<class... Args> requires [constructible_from](concept.constructible#concept:constructible%5Ffrom "18.4.11 Concept constructible_­from [concept.constructible]")<T, Args...> constexpr explicit single_view(in_place_t, Args&&... args);

Effects: Initializes value_ as if by_value__{in_place, std​::​forward<Args>(args)...}.

constexpr T* begin() noexcept;constexpr const T* begin() const noexcept;

Effects: Equivalent to: return data();

constexpr T* end() noexcept;constexpr const T* end() const noexcept;

Effects: Equivalent to: return data() + 1;

static constexpr bool empty() noexcept;

Effects: Equivalent to: return false;

static constexpr size_t size() noexcept;

Effects: Equivalent to: return 1;

constexpr T* data() noexcept;constexpr const T* data() const noexcept;

Effects: Equivalent to: return value_.operator->();