[ANN] STL iterators/bridge to Cocoa (was: Re: Collection classes)
[ANN] STL iterators/bridge to Cocoa (was: Re: Collection classes)
- Subject: [ANN] STL iterators/bridge to Cocoa (was: Re: Collection classes)
- From: Allan Odgaard <email@hidden>
- Date: Thu, 8 Jan 2004 07:00:36 +0100
On 8. Jan 2004, at 4:02, Todd Blanchard wrote:
[...] Unless you have a really compelling reason to do a custom
collection, you're much better off using what's there - maybe with
some nifty add on methods.
I agree that when working with the Cocoa framework it is a really bad
idea to avoid the standard collection classes, because as you say, half
the API expect these (and they work with archiving, placing on the
pasteboard etc. etc.).
However, as an avid STL fan I constantly miss the flexibility, compact
syntax and algorithm choices I get from there, which is why I have
written some code to expose Cocoa to STL.
For example there is an NSArrayIterator which conforms to an STL random
access iterator but wraps for an NSArray, allowing code such as:
NSMutableArray* array = ...;
std::random_shuffle(beginof(array), endof(array));
There is also an NSBackInsertIterator, so one can use an NSMutableArray
as the output of an algorithm, and selector adaptors to create a
functor from an Objective C selector, allowing code like:
NSArray* array = ...;
char const* res[ [array count] ];
std::transform(beginof(array), endof(array), res,
method<char const*>(@selector(UTF8String)));
Which will send UTF8String to each object in the array and store the
results in the (stack allocated) res array.
I have put the header online together with some explanations, I even
wrote a tutorial for people not familiar with STL iterators (which I
highly encourage people to read :) ), it can be found here:
http://www.top-house.dk/~aae0030/cocoastl/
It's just torn out of another project, but if there is any interest, I
could make it into a "real" project on its own (which means updating it
now and then ;) ).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.