26 #include <Availability.h>
27 #import <Foundation/Foundation.h>
29 #if defined(__OBJC__) && defined(__cplusplus)
38 template <
typename CastT,
typename ArgT>
39 static inline CastT* NSCheckedCast(ArgT arg) {
40 if (!arg || [arg isKindOfClass:[CastT
class]]) {
43 @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:
@"%@ is not of type %@", arg, NSStringFromClass([CastT
class])] userInfo:nil];
47 template <
typename CastT,
typename ArgT>
48 static inline CastT* CFCheckedCast(ArgT arg) {
49 if (!(__bridge CastT)arg || [(__bridge CastT)arg isKindOfClass:[CastT
class]]) {
50 return (__bridge CastT*)arg;
52 @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:
@"%@ is not of type %@", (__bridge CastT*)arg, NSStringFromClass([CastT
class])] userInfo:nil];