File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1353,6 +1353,15 @@ auto as(X const& x CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto) {
1353
1353
}
1354
1354
}
1355
1355
1356
+ template <typename T>
1357
+ struct is_optional : std::false_type {};
1358
+
1359
+ template <typename T>
1360
+ struct is_optional <std::optional<T>> : std::true_type {};
1361
+
1362
+ template <typename T>
1363
+ constexpr auto is_optional_v{is_optional<T>::value};
1364
+
1356
1365
template < typename C, typename X >
1357
1366
auto as ( X& x ) -> decltype(auto ) {
1358
1367
if constexpr (std::is_same_v<C, X>) {
@@ -1364,6 +1373,9 @@ auto as( X& x ) -> decltype(auto) {
1364
1373
else if constexpr (std::is_base_of_v<X, C>) {
1365
1374
return Dynamic_cast<C&>(x);
1366
1375
}
1376
+ else if constexpr (is_optional_v<X>) {
1377
+ return x.value ();
1378
+ }
1367
1379
else {
1368
1380
return as<C>(std::as_const (x));
1369
1381
}
You can’t perform that action at this time.
0 commit comments