5.2 KiB
[range.single]
25 Ranges library [ranges]
25.6 Range factories [range.factories]
25.6.3 Single view [range.single]
25.6.3.1 Overview [range.single.overview]
single_view produces a view that contains exactly one element of a specified value.
The name views::single denotes a customization point object ([customization.point.object]).
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; // prints 4 â end example]
25.6.3.2 Class template single_view [range.single.view]
namespace std::ranges {template<move_constructible T>requires is_object_vclass single_view : public view_interface<single_view> {private:movable-box value_; // exposition only (see [range.move.wrap])public: single_view() requires default_initializable = default; constexpr explicit single_view(const T& t) requires copy_constructible; 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 single_view(T) -> single_view;}
constexpr explicit single_view(const T& t) requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]")<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_from "18.4.11 Concept constructible_from [concept.constructible]")<T, Args...> constexpr explicit single_view(in_place_t, Args&&... args);
Effects: Initializes value_ as if byvalue_{in_place, std::forward(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->();