We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 09e08ea commit 90ad999Copy full SHA for 90ad999
include/cpp2util.h
@@ -1352,6 +1352,18 @@ auto as( X* x ) -> C {
1352
return Dynamic_cast<C>(x);
1353
}
1354
1355
+template <pointer_like T>
1356
+using pointee_t = CPP2_TYPEOF(*std::declval<T>());
1357
+
1358
+template < typename C, pointer_like X>
1359
+ requires std::same_as<pointee_t<X>, C>
1360
+auto as (X const & x) -> decltype(auto) {
1361
+ if (x) {
1362
+ return *x;
1363
+ }
1364
+ Throw( std::runtime_error("'as' cast failed for empty 'pointer_like'"), "'as' cast failed for empty 'pointer_like'");
1365
+}
1366
1367
//-------------------------------------------------------------------------------------------------------------
1368
// std::variant is and as
1369
//
0 commit comments