Skip to content

Commit 6b1184d

Browse files
authored
Fix text editing capabilities (#96)
1 parent 60ba58d commit 6b1184d

15 files changed

Lines changed: 1255 additions & 195 deletions

File tree

modules/yup_core/misc/yup_ResultValue.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,36 @@ class YUP_API ResultValue
181181
return valueOrErrorMessage.index() != 1;
182182
}
183183

184+
/** Returns a copy of the value that was set when this result was created,
185+
or a value constructed from @p defaultValue if the result indicates a failure.
186+
187+
This overload is available when the held value can be copied. Use the
188+
rvalue-qualified overload when working with move-only value types.
189+
*/
190+
template <class U = T>
191+
auto valueOr (U&& defaultValue) const& -> std::enable_if_t<std::is_copy_constructible_v<T> && std::is_constructible_v<T, U&&>, T>
192+
{
193+
if (valueOrErrorMessage.index() == 1)
194+
return std::get<1> (valueOrErrorMessage);
195+
196+
return T (std::forward<U> (defaultValue));
197+
}
198+
199+
/** Returns the moved value that was set when this result was created,
200+
or a value constructed from @p defaultValue if the result indicates a failure.
201+
202+
This overload allows valueOr() to be used with move-only value types when
203+
the ResultValue itself is an rvalue.
204+
*/
205+
template <class U = T>
206+
auto valueOr (U&& defaultValue) && -> std::enable_if_t<std::is_move_constructible_v<T> && std::is_constructible_v<T, U&&>, T>
207+
{
208+
if (valueOrErrorMessage.index() == 1)
209+
return std::get<1> (std::move (valueOrErrorMessage));
210+
211+
return T (std::forward<U> (defaultValue));
212+
}
213+
184214
/** Returns a copy of the value that was set when this result was created. */
185215
T getValue() const&
186216
{

0 commit comments

Comments
 (0)