But I didn't buy it to use it, I bought it to learn from. I had written my own cross platform networking library which ran on SunOS, HPUX, SGI IRIX, Ultrix, BSD and Windows NT; and it worked really well. But I was now slowly delving into threading and didn't want to suffer through same five year learning curve as I had with networking. I had scratched the surface of pthreads, and I figured if I could get a Rosetta stone, I'd be most of the way there. So several hundred dollars later, I had the Object Space C++ cross platform libraries in my hands.
Their code for threads was great, because windows gives you a lot of high level calls while pthreads was basically parts; and it showed how you could make the windows things out of the pthread parts. But there was more on the CD besides this. There were these strange template things called Containers and Algorithms. These things warped my brain the way Flatland does the first time you read it, and for ten minutes you can visualize four dimensions in your head. But like my grasp of the thermal cycle of a propane refrigerator, after a night of rest, it was gone.
Some time down the road, I was ready to come back to Algorithms, and started off trying to do this:
void someclass::somemethod(int x) { struct { bool operator(something * ptr) { return ptr->sometest( x ) ; } } anon_test ; something * foundptr = stl::find_if( somelist.begin(), somelist.end(), anon_test) ; }This didn't work for all kinds of reasons, but even when I knocked down the easy ones (like creating local storage in the struct for x), I ended up hitting language limits like not being able to have an un-named struct, and I abandoned the whole thing.
There were really ugly work-arounds involving horrible bind macros and worse types so that just to compare a list of ints against x, you'd end up doing something like:
binder2ndIck. Wasn't going to happen, and for the most part, didn't. Not one project, or company I worked at in the next 15 years ever used STL containers, or algorithms. I'm sure somewhere, somebody used it, but I never ran into it.testor = bind2nd( greater(), x) ;
Thankfully, the standards body took up all the patchwork that boost had been doing for ten years, and cleaned up C++ to make things easier and better. We got lambdas, closures, and a lot of duct tape like auto and range-for.
So now I can do my previous example in a much cleaner way, and even better, its readable:
void someclass::somemethod( int x) { something * foundptr= std::find_if( somelist.begin(), somelist.end(), [x](something * ptr){ return ptr->sometest( x) ; } ) ; }The worst part of this is the little magic: [x] but you can go read about lambda syntax and you'll get it. And for performance, if you're going to use that predicate a lot, you can save it away ahead of time with just a tad more effort:
auto xtest = [x](something * ptr){ return ptr->sometest( x) ; } ;I think this is big.
Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.
Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect
Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job
May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids