Skip to content

Commit 56d061c

Browse files
authored
[libc++][NFC] Add optional<T&> synopsis (#170043)
1 parent c103d61 commit 56d061c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

libcxx/include/optional

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,71 @@ namespace std {
186186
template<class T>
187187
optional(T) -> optional<T>;
188188
189+
template<class T>
190+
class optional<T&> { // since C++26
191+
public:
192+
using value_type = T;
193+
using iterator = implementation-defined; // see [optional.ref.iterators]
194+
195+
public:
196+
// [optional.ref.ctor], constructors
197+
constexpr optional() noexcept = default;
198+
constexpr optional(nullopt_t) noexcept : optional() {}
199+
constexpr optional(const optional& rhs) noexcept = default;
200+
201+
template<class Arg>
202+
constexpr explicit optional(in_place_t, Arg&& arg);
203+
template<class U>
204+
constexpr explicit(see below) optional(U&& u) noexcept(see below);
205+
template<class U>
206+
constexpr explicit(see below) optional(optional<U>& rhs) noexcept(see below);
207+
template<class U>
208+
constexpr explicit(see below) optional(const optional<U>& rhs) noexcept(see below);
209+
template<class U>
210+
constexpr explicit(see below) optional(optional<U>&& rhs) noexcept(see below);
211+
template<class U>
212+
constexpr explicit(see below) optional(const optional<U>&& rhs) noexcept(see below);
213+
214+
constexpr ~optional() = default;
215+
216+
// [optional.ref.assign], assignment
217+
constexpr optional& operator=(nullopt_t) noexcept;
218+
constexpr optional& operator=(const optional& rhs) noexcept = default;
219+
220+
template<class U> constexpr T& emplace(U&& u) noexcept(see below);
221+
222+
// [optional.ref.swap], swap
223+
constexpr void swap(optional& rhs) noexcept;
224+
225+
// [optional.ref.iterators], iterator support
226+
constexpr iterator begin() const noexcept;
227+
constexpr iterator end() const noexcept;
228+
229+
// [optional.ref.observe], observers
230+
constexpr T* operator->() const noexcept;
231+
constexpr T& operator*() const noexcept;
232+
constexpr explicit operator bool() const noexcept;
233+
constexpr bool has_value() const noexcept;
234+
constexpr T& value() const; // freestanding-deleted
235+
template<class U = remove_cv_t<T>>
236+
constexpr remove_cv_t<T> value_or(U&& u) const;
237+
238+
// [optional.ref.monadic], monadic operations
239+
template<class F> constexpr auto and_then(F&& f) const;
240+
template<class F> constexpr optional<invoke_result_t<F, T&>> transform(F&& f) const;
241+
template<class F> constexpr optional or_else(F&& f) const;
242+
243+
// [optional.ref.mod], modifiers
244+
constexpr void reset() noexcept;
245+
246+
private:
247+
T* val = nullptr; // exposition only
248+
249+
// [optional.ref.expos], exposition only helper functions
250+
template<class U>
251+
constexpr void convert-ref-init-val(U&& u); // exposition only
252+
};
253+
189254
} // namespace std
190255
191256
*/

0 commit comments

Comments
 (0)