Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@import Foundation; | ||
#import <array> | ||
#include <vector> | ||
|
||
@interface IntegerArray : NSObject { | ||
std::vector<NSUInteger> _numbers; | ||
} | ||
@property(readonly) NSUInteger count; | ||
|
||
- (instancetype)initWithNumbers:(NSUInteger *)numbers count:(NSUInteger)count; | ||
- (NSUInteger)numberAtIndex:(NSUInteger)index; | ||
@end | ||
|
||
int main(int argc, char **argv) { | ||
auto numbers = std::array<NSUInteger, 3>{1, 2, 3}; | ||
NSLog(@"%@", [[IntegerArray alloc] initWithNumbers:numbers.data() count:numbers.size()]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
@import Foundation; | ||
#include <cheader.h> | ||
#include <cppheader> | ||
#import <objective-cheader.h> | ||
|
||
@class ForwardDeclare; | ||
|
||
@interface BaseClass : NSObject | ||
- (instancetype)initWithForwardDeclare(ForwardDeclare *)ForwardDeclare NS_DESIGNATED_INITIALIZER; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GenericClass<__covariant Type : id<NSCopying>> : NSObject { | ||
std::unique_ptr<Type> _storage; | ||
} | ||
|
||
- (void)takesABlock:(void * (^_Nullable)(NSString *, T *, ...))block __attribute__((deprecated)); | ||
@end | ||
|
||
@implementation GenericClass { | ||
@private | ||
struct { | ||
int a; | ||
NSArray<NSNumber *> b; | ||
} _moreStuff; | ||
} | ||
@end | ||
|
||
template <typename T, typename Lambda> | ||
auto takesALambda(GenericClass<T *> *generic, Lambda lambda) -> decltype(generic.class) { | ||
[generic takesABlock:^(@"Hello, world!", new T(), 3) { | ||
lambda(@{ | ||
@"A" : @YES, | ||
@"literal" : @1, | ||
@"test" : @[ reinterpret_cast<NSArray *>(generic) ], | ||
}) | ||
}]; | ||
return generic.class; | ||
} | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
void function() { | ||
static_assert(sizeof(id) == 8, "ILP static assert"); | ||
auto result = takesALambda([GenericClass new], [&](NSDictionary<NSString *, id> things) { | ||
[things ? things : [BaseClass initWithForwardDeclare:ForwardDeclare.sharedForwardDeclare] | ||
keysSortedByValueUsingSelector:@selector(class)]; | ||
}); | ||
@try { | ||
throw throw std::exception(); | ||
} | ||
@catch (NSException *exception) { | ||
std::cout << std::string(exception.description.UTF8String) << std::endl; | ||
} | ||
} | ||
|
||
template <class F, class... Args> | ||
explicit thread(F &&f, Args &&... args); |