Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Examples

Example: FlagNth. Here is the classic example from [Sutter02], which is intended to remove the third element from a container v:

class FlagNth {
public:
 FlagNth( size_t n ) : current_(0), n_(n) { }

 // evaluate to true if and only if this is the n-th invocation
 template<typename T>
 bool operator()( const T& ) { return ++current_ == n_; }     // bad: non-const

private:
 size_t current_, n_;
};

// ... later ...

v.erase( remove_if( v.begin(), v.end(), FlagNth(3) ) );

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial