File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,14 @@ class Optional :
43
43
44
44
T & get ();
45
45
const T & get () const ;
46
+
47
+ constexpr const T & get_or (const T &default_value) const ;
48
+
46
49
T & operator *();
47
50
const T & operator *() const ;
51
+
48
52
T * operator ->();
49
- T * operator ->() const ;
53
+ const T * operator ->() const ;
50
54
51
55
std::string get_tag () const ;
52
56
@@ -170,6 +174,12 @@ const T & Optional<T>::get() const
170
174
return *ptr;
171
175
}
172
176
177
+ template <typename T>
178
+ constexpr const T & Optional<T>::get_or(const T &default_value) const
179
+ {
180
+ return valid ? get () : default_value;
181
+ }
182
+
173
183
template <typename T>
174
184
T & Optional<T>::operator *()
175
185
{
@@ -183,13 +193,13 @@ const T & Optional<T>::operator*() const
183
193
}
184
194
185
195
template <typename T>
186
- T * Optional<T>::operator ->() const
196
+ T * Optional<T>::operator ->()
187
197
{
188
198
return &get ();
189
199
}
190
200
191
201
template <typename T>
192
- T * Optional<T>::operator ->()
202
+ const T * Optional<T>::operator ->() const
193
203
{
194
204
return &get ();
195
205
}
You can’t perform that action at this time.
0 commit comments