Skip to content

Commit

Permalink
Add demo and sample files
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed Jan 5, 2020
1 parent b806d62 commit 97ad269
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/rouge/demos/objective_cpp
@@ -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()]);
}
59 changes: 59 additions & 0 deletions spec/visual/samples/objective_cpp
@@ -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);

0 comments on commit 97ad269

Please sign in to comment.