From Jason Turner

[optional.optional.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpr3e5n7r8/{from.md → to.md} +33 -21
tmp/tmpr3e5n7r8/{from.md → to.md} RENAMED
@@ -4,21 +4,23 @@
4
  namespace std {
5
  template<class T>
6
  class optional {
7
  public:
8
  using value_type = T;
 
 
9
 
10
  // [optional.ctor], constructors
11
  constexpr optional() noexcept;
12
  constexpr optional(nullopt_t) noexcept;
13
  constexpr optional(const optional&);
14
  constexpr optional(optional&&) noexcept(see below);
15
  template<class... Args>
16
  constexpr explicit optional(in_place_t, Args&&...);
17
  template<class U, class... Args>
18
  constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
19
- template<class U = T>
20
  constexpr explicit(see below) optional(U&&);
21
  template<class U>
22
  constexpr explicit(see below) optional(const optional<U>&);
23
  template<class U>
24
  constexpr explicit(see below) optional(optional<U>&&);
@@ -28,34 +30,40 @@ namespace std {
28
 
29
  // [optional.assign], assignment
30
  constexpr optional& operator=(nullopt_t) noexcept;
31
  constexpr optional& operator=(const optional&);
32
  constexpr optional& operator=(optional&&) noexcept(see below);
33
- template<class U = T> constexpr optional& operator=(U&&);
34
  template<class U> constexpr optional& operator=(const optional<U>&);
35
  template<class U> constexpr optional& operator=(optional<U>&&);
36
  template<class... Args> constexpr T& emplace(Args&&...);
37
  template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...);
38
 
39
  // [optional.swap], swap
40
  constexpr void swap(optional&) noexcept(see below);
41
 
 
 
 
 
 
 
42
  // [optional.observe], observers
43
  constexpr const T* operator->() const noexcept;
44
  constexpr T* operator->() noexcept;
45
  constexpr const T& operator*() const & noexcept;
46
  constexpr T& operator*() & noexcept;
47
  constexpr T&& operator*() && noexcept;
48
  constexpr const T&& operator*() const && noexcept;
49
  constexpr explicit operator bool() const noexcept;
50
  constexpr bool has_value() const noexcept;
51
- constexpr const T& value() const &;
52
- constexpr T& value() &;
53
- constexpr T&& value() &&;
54
- constexpr const T&& value() const &&;
55
- template<class U> constexpr T value_or(U&&) const &;
56
- template<class U> constexpr T value_or(U&&) &&;
57
 
58
  // [optional.monadic], monadic operations
59
  template<class F> constexpr auto and_then(F&& f) &;
60
  template<class F> constexpr auto and_then(F&& f) &&;
61
  template<class F> constexpr auto and_then(F&& f) const &;
@@ -77,21 +85,25 @@ namespace std {
77
  template<class T>
78
  optional(T) -> optional<T>;
79
  }
80
  ```
81
 
82
- Any instance of `optional<T>` at any given time either contains a value
83
- or does not contain a value. When an instance of `optional<T>` *contains
84
- a value*, it means that an object of type `T`, referred to as the
85
- optional object’s *contained value*, is allocated within the storage of
86
- the optional object. Implementations are not permitted to use additional
87
- storage, such as dynamic memory, to allocate its contained value. When
88
- an object of type `optional<T>` is contextually converted to `bool`, the
89
- conversion returns `true` if the object contains a value; otherwise the
90
- conversion returns `false`.
91
 
92
- When an `optional<T>` object contains a value, member `val` points to
93
- the contained value.
94
 
95
- `T` shall be a type other than cv `in_place_t` or cv `nullopt_t` that
96
- meets the *Cpp17Destructible* requirements ([[cpp17.destructible]]).
 
 
 
 
 
97
 
 
4
  namespace std {
5
  template<class T>
6
  class optional {
7
  public:
8
  using value_type = T;
9
+ using iterator = implementation-defined; // see~[optional.iterators]
10
+ using const_iterator = implementation-defined; // see~[optional.iterators]
11
 
12
  // [optional.ctor], constructors
13
  constexpr optional() noexcept;
14
  constexpr optional(nullopt_t) noexcept;
15
  constexpr optional(const optional&);
16
  constexpr optional(optional&&) noexcept(see below);
17
  template<class... Args>
18
  constexpr explicit optional(in_place_t, Args&&...);
19
  template<class U, class... Args>
20
  constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
21
+ template<class U = remove_cv_t<T>>
22
  constexpr explicit(see below) optional(U&&);
23
  template<class U>
24
  constexpr explicit(see below) optional(const optional<U>&);
25
  template<class U>
26
  constexpr explicit(see below) optional(optional<U>&&);
 
30
 
31
  // [optional.assign], assignment
32
  constexpr optional& operator=(nullopt_t) noexcept;
33
  constexpr optional& operator=(const optional&);
34
  constexpr optional& operator=(optional&&) noexcept(see below);
35
+ template<class U = remove_cv_t<T>> constexpr optional& operator=(U&&);
36
  template<class U> constexpr optional& operator=(const optional<U>&);
37
  template<class U> constexpr optional& operator=(optional<U>&&);
38
  template<class... Args> constexpr T& emplace(Args&&...);
39
  template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...);
40
 
41
  // [optional.swap], swap
42
  constexpr void swap(optional&) noexcept(see below);
43
 
44
+ // [optional.iterators], iterator support
45
+ constexpr iterator begin() noexcept;
46
+ constexpr const_iterator begin() const noexcept;
47
+ constexpr iterator end() noexcept;
48
+ constexpr const_iterator end() const noexcept;
49
+
50
  // [optional.observe], observers
51
  constexpr const T* operator->() const noexcept;
52
  constexpr T* operator->() noexcept;
53
  constexpr const T& operator*() const & noexcept;
54
  constexpr T& operator*() & noexcept;
55
  constexpr T&& operator*() && noexcept;
56
  constexpr const T&& operator*() const && noexcept;
57
  constexpr explicit operator bool() const noexcept;
58
  constexpr bool has_value() const noexcept;
59
+ constexpr const T& value() const &; // freestanding-deleted
60
+ constexpr T& value() &; // freestanding-deleted
61
+ constexpr T&& value() &&; // freestanding-deleted
62
+ constexpr const T&& value() const &&; // freestanding-deleted
63
+ template<class U = remove_cv_t<T>> constexpr T value_or(U&&) const &;
64
+ template<class U = remove_cv_t<T>> constexpr T value_or(U&&) &&;
65
 
66
  // [optional.monadic], monadic operations
67
  template<class F> constexpr auto and_then(F&& f) &;
68
  template<class F> constexpr auto and_then(F&& f) &&;
69
  template<class F> constexpr auto and_then(F&& f) const &;
 
85
  template<class T>
86
  optional(T) -> optional<T>;
87
  }
88
  ```
89
 
90
+ An object of type `optional<T>` at any given time either contains a
91
+ value or does not contain a value. When an object of type `optional<T>`
92
+ *contains a value*, it means that an object of type `T`, referred to as
93
+ the optional object’s *contained value*, is nested within
94
+ [[intro.object]] the optional object. When an object of type
95
+ `optional<T>` is contextually converted to `bool`, the conversion
96
+ returns `true` if the object contains a value; otherwise the conversion
97
+ returns `false`.
 
98
 
99
+ When an object of type `optional<T>` contains a value, member `val`
100
+ points to the contained value.
101
 
102
+ A type `X` is a *valid contained type* for `optional` if `X` is an
103
+ lvalue reference type or a complete non-array object type, and
104
+ `remove_cvref_t<X>` is a type other than `in_place_t` or `nullopt_t`. If
105
+ a specialization of `optional` is instantiated with a type `T` that is
106
+ not a valid contained type for `optional`, the program is ill-formed. If
107
+ `T` is an object type, `T` shall meet the *Cpp17Destructible*
108
+ requirements ([[cpp17.destructible]]).
109