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

71 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[range.nonprop.cache]
# 25 Ranges library [[ranges]](./#ranges)
## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.nonprop.cache)
### 25.7.4 Non-propagating cache [range.nonprop.cache]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4371)
Some types in [[range.adaptors]](range.adaptors "25.7Range adaptors") are specified in terms of
an exposition-only class template *non-propagating-cache*[.](#1.sentence-1)
*non-propagating-cache*<T> behaves exactly like optional<T> with the following differences:
- [(1.1)](#1.1)
*non-propagating-cache*<T> constrains its type parameter T with is_object_v<T>.
- [(1.2)](#1.2)
The copy constructor is equivalent to:constexpr *non-propagating-cache*(const *non-propagating-cache*&) noexcept {}
- [(1.3)](#1.3)
The move constructor is equivalent to:constexpr *non-propagating-cache*(*non-propagating-cache*&& other) noexcept { other.reset();}
- [(1.4)](#1.4)
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;}
- [(1.5)](#1.5)
The move assignment operator is equivalent to:constexpr *non-propagating-cache*& operator=(*non-propagating-cache*&& other) noexcept { reset();
other.reset(); return *this;}
- [(1.6)](#1.6)
*non-propagating-cache*<T> has an additional member function template
specified as follows:
[🔗](#1.6.itemdecl:1)
`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[.](#1.6.sentence-2)
[*Note [1](#note-1)*:
If *i is a prvalue of type cv T,
there is no requirement that it is movable ([[dcl.init.general]](dcl.init.general "9.5.1General"))[.](#1.6.sentence-3)
— *end note*]
*Effects*: Calls reset()[.](#1.6.sentence-4)
Then direct-non-list-initializes the contained value with *i[.](#1.6.sentence-5)
*Postconditions*: *this contains a value[.](#1.6.sentence-6)
*Returns*: A reference to the new contained value[.](#1.6.sentence-7)
*Throws*: Any exception thrown by the initialization of the contained value[.](#1.6.sentence-8)
*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[.](#1.6.sentence-9)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4449)
[*Note [2](#note-2)*:
*non-propagating-cache* enables an input view
to temporarily cache values as it is iterated over[.](#2.sentence-1)
— *end note*]