views:

1456

answers:

2

I'd like to use an STL set in my iPhone app (which is written in Objective-C in XCode). How do I include set and/or use the standard namespace?

In C++ I'd do this:

#include<set>
using namespace std;

// use the set<T> somewhere down here...

How can I do this in Objective-C?

+4  A: 

Just rename your source file so it ends in .mm and it should trigger the Objective-C++ front-end; you can then mix Objective-C and C++ in it. More information here.

Nicholas Riley
this is the right solution, but there are some issues with destructors, exceptions, RAII and memory management that don't really work 100% correctly, so although it's C++ and STL, there are lots of special surprises awaiting the brave souls that try .mm extension :)
Robert Gould
A: 

STL is not directly supported in objective-C. There appear to be several projects though that are attempting to port STL to objective-C. Objectivelib is one such and is available on sourceforge

JaredPar