Files
2025-10-25 03:02:53 +03:00

2.6 KiB
Raw Permalink Blame History

[range.nonprop.cache]

25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.4 Non-propagating cache [range.nonprop.cache]

1

#

Some types in [range.adaptors] are specified in terms of an exposition-only class template non-propagating-cache.

non-propagating-cache behaves exactly like optional with the following differences:

non-propagating-cache constrains its type parameter T with is_object_v.

The copy constructor is equivalent to:constexpr non-propagating-cache(const non-propagating-cache&) noexcept {}

The move constructor is equivalent to:constexpr non-propagating-cache(non-propagating-cache&& other) noexcept { other.reset();}

The copy assignment operator is equivalent to:constexpr non-propagating-cache& operator=(const non-propagating-cache& other) noexcept {if (addressof(other) != this) reset(); return *this;}

The move assignment operator is equivalent to:constexpr non-propagating-cache& operator=(non-propagating-cache&& other) noexcept { reset(); other.reset(); return *this;}

non-propagating-cache has an additional member function template specified as follows: 🔗 template<class I> constexpr T& emplace-deref(const I& i); // exposition only Mandates: The declaration T t(*i); is well-formed for some invented variable t. [Note 1: If *i is a prvalue of type cv T, there is no requirement that it is movable ([dcl.init.general]). — end note] Effects: Calls reset(). Then direct-non-list-initializes the contained value with *i. Postconditions: *this contains a value. Returns: A reference to the new contained value. Throws: Any exception thrown by the initialization of the contained value. Remarks: If an exception is thrown during the initialization of T,*this does not contain a value, and the previous value (if any) has been destroyed.

2

#

[Note 2:

non-propagating-cache enables an input view to temporarily cache values as it is iterated over.

— end note]