Club 15CC

Objective-C++ ~ 15CC Code

Task Code
Objective-C++ Custom Hash & Equals Functors for Using Objective-C Objects as Keys in C++ Containers »
template <typename T> struct ObjCHash {
    size_t operator()(const T s1) const { return (size_t)s1; }
};

template <typename T> struct ObjCEquals {
    size_t operator()(const T, const T b) const { return a==b; }
};

// Maps of NSInvocations to call count...
std::unordered_map< NSInovcation *, NSUInteger, ObjCHash<NSInvocation *>, ObjCEquals<NSInvocation *> >callCount;
intermediate Obj-C safe, forward declaration for a C++ class in an Obj-C++ header file »
// Let's say you have an Obj-C++ class which needs to reference a C++ class,
// perhaps for an instance variable, and you wish to include and use this
// Obj-C++ class in a regular Obj-C class. You can't include the C++ header in the
// Obj-C++ header file as this will cause problems with the importing Obj-C class.
// This snippet is the equivalent of @class for forward defining the C++ class
// in the Obj-C++ class in a way compatible with plain old Obj-C

/// Forward definition for C++ class
struct MyCPPClass;
typedef struct MyCPPClass MyCPPClass;

@interface MyObjCPPClass {
    MyCPPClass anIvar;
}

// ...

@end