// circle and shape are user-defined types
circle* p = new circle( 42 );
vector<shape*> v = load_shapes();
for( vector<circle*>::iterator i = v.begin(); i != v.end(); ++i ) {
if( *i && **i == *p )
cout << **i << “ is a match\n”;
}
for( vector<circle*>::iterator i = v.begin();
i != v.end(); ++i ) {
delete *i; // not exception safe
}
delete p;
The new modern C++ looks like this: #include <memory>
#include <vector>
// ...
// circle and shape are user-defined types
auto p = make_shared<circle>( 42 );
vector<shared_ptr<shape>> v = load_shapes();
for_each( begin(v), end(v), [&]( const shared_ptr<shape>& s ) {
if( s && *s == *p )
cout << *s << " is a match\n";
} );
To be honest, as a C++ programmer who dates back to the days of Turbo C++ (i.e. before the days of STL), I can honestly say I no longer have any time for the old or new STL based C++.The modern day C++ language is just too full of noise!
To remain relevant C++ needs to try to become a nice, easy to use language without the massive level of noise.
To be honest, as a 10 year+ veteran of C++, I have to say I don't miss it one bit.