⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alg6.c

📁 C++ Primer的第三版结合了Stanley Lippman的实践经验和Josée Lajoie对于ANSI/ISO标准C++的深入理解。这本指导书的第三版已经被重新改写过
💻 C
字号:
#include <algorithm>
#include <list>
#include <iostream.h>
#include <assert.h>
	
class Even {
public:
	bool operator()( int val ) 
		{ return val%2 ? false : true; }
};
	
int main() 
{
	int ia[] = {0,1,1,2,3,5,8,13,21,34};
	list< int,allocator > ilist( ia, ia+10 );
		
        /*
         * unsupported in current implementation
         *****************************************************
	 typedef 
	    iterator_traits<InputIterator>::distance_type
	    distance_type;
	
	    distance_type ia_count, list_count;
		
	    // count even elements: 4 
	    ia_count = count_if( &ia[0], &ia[10], Even() );
	    list_count = count_if( ilist.begin(), ilist_end(),
			           bind2nd(less<int>(),10) );
	  ******************************************************
	  */

	int ia_count = 0;
        count_if( &ia[0], &ia[10], Even(), ia_count );

	// generates: 
	//   count_if(): there are 4 elements that are even.

	cout << "count_if(): there are "
	     << ia_count << " elements that are even.\n";

	int list_count = 0;
        count_if( ilist.begin(), ilist.end(),
	          bind2nd(less<int>(),10), list_count );


	// generates: 
	//   count_if(): there are 7 elements that are less than 10.

	cout << "count_if(): there are "
	     << list_count 
	     << " elements that are less than 10.\n";
		
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -