hckr83 wrote:hmm...smart pointers just seem like too much overhead for such a commonly done thing(I tend to use too many pointers though)
What is such a commonly-done thing? Calling new and delete? Managing reference counts...? The overhead added by a smart pointer is negligible, because any worthwhile compiler will inline most of the smart pointer's methods. On the other hand, the benefits of using smart pointers are tremendous as they make it much more difficult to inject subtle memory leaks into your code during development.
function objects?! I didn't even know you could do that! I don't see any practical application right now, but I'm sure there is some good use for it..
You should spend some time learning how to use the algorithms in the STL. In a nutshell, function objects make it easy to apply a custom operation over a collection in a generic way. For example, let's say you have a vector<Foo*>, and each Foo has a method getBar() that returns a pointer to the Bar belonging to that Foo. If you want to "strip" the Foos off and end up with a vector<Bar*>, you can do that easily by writing a short function object that just calls getBar() on a Foo, and then call std::transform() on your input and output vectors. It's quite nifty, at least for C++.
This kind of technique is actually extremely common in functional programming languages, but they offer much better support for such things directly in the language via "lambda functions" (I don't want to oversimplify too much, but basically they're anonymous functions).
++ and -- I can actually see a use for in my list thingy...like being able to override the = operator and such....meh...kidna complicated though..lol
Yeah, iterators are complicated to implement properly. I wouldn't even bother. The point is that without overloading operator ++ and -- it would be impossible for the STL to provide generic algorithms that work on all kinds of containers, including plain-jane C arrays. But as far as implementing iterators goes, better the STL guys than me.
btw, Are templates well optimized? If they aren't, with each call to a template, you'd reproduce code...and with many calls, it could eventually be MBs of duplicate wasted code! (if your not careful)
In terms of speed, templates are very well optimized. Everything basically gets inlined. In terms of space, if you instantiate a template with many different types, then yes, it can consume a lot of space. As others have said, it's not per "call" though, it's per unique instantiation. For example, if you have a vector<Foo> and a vector<Bar>, the code for vector will be replicated once for each.
I've heard horror stories about crappy old C++ compilers on really old flavours of UNIX (which, unfortunately for me, are still in active use) that will copy template code for a particular instantiation once per .cpp file, and the linker fails to eliminate the duplicate code. I haven't verified this myself yet though.