std::ranges::borrowed_range, std::ranges::enable_borrowed_range

< cpp‎ | ranges
Defined in header <ranges>
template<class R>

concept borrowed_range =
    ranges::range<R> &&

    (std::is_lvalue_reference_v<R> || ranges::enable_borrowed_range<std::remove_cvref_t<R>>);
Defined in header <ranges>
Defined in header <span>
Defined in header <string_view>
template<class R>
inline constexpr bool enable_borrowed_range = false;
1) The concept borrowed_range defines the requirements of a range such that a function can take it by value and return iterators obtained from it without danger of dangling.
2) The enable_borrowed_range variable template is used to indicate whether a range is a borrowed_range. The primary template is defined as false.

[edit] Semantic requirements

Given an expression e such that decltype((e)) is T, T models borrowed_range only if the validity of iterators obtained from the object denoted by e is not tied to the lifetime of that object.

[edit] Specializations

Specializations of enable_borrow_range for all specializations of the following standard templates are defined as true:

Specialization of enable_borrow_range for the following standard range adaptors are defined as true if and only if std::ranges::enable_borrowed_range<V> is true, where V is the underlying view type:

Users may specialize enable_borrowed_range to true for cv-unqualified program-defined types which model borrowed_range, and false for types which do not. Such specializations shall be usable in constant expressions and have type const bool.