Andrew Wingorodov <ma**@andr.cawrote:
im made subj like this:
inline
bool isnt_space (int sp) { return (::isspace (sp)) ? false : true; }
The above could have been written more compactly as:
inline bool isnt_space( int sp ) { return !::isspace( sp ); }
str.erase (
std.begin ()
, std::find_if ( str.begin(), str.end(), isnt_space)
);
How i can use std for better away?
Can i invert result of the ::isspace by means of bind2nd?
Try this:
str.erase( str.begin(), find_if( str.begin(), str.end(),
not1( ptr_fun( &::isspace ) ) ) );
ptr_fun turns the function into an adaptable unary function
(
http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html)
not1 creates a unary_negate object, which inverts the result of the
function passed to it.
(
http://www.sgi.com/tech/stl/unary_negate.html)
There may be a question as to whether what I provided is a "better way"
than what you did.
Of course you could always do both...
const unary_negate<pointer_to_unary_function<int, int
isnt_space = not1( ptr_fun( &::isspace ) );
str.erase( str.begin(),
find_if( str.begin(), str.end(), isnt_space ) );