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

📄 alg15.c

📁 C++ PRIME书中的原代码,看本书时可以学习的例子.
💻 C
字号:
#include <algorithm>
#include <list>
#include <iostream.h>
	
int odd_by_twos() { 
	static int seed = -1; 
	return seed += 2;
}

template <class Type>
void print_elements( Type elem ) { cout << elem << " "; }
	
int main()
{
	list< int, allocator > ilist( 10 );
	void (*pfi)( int ) = print_elements;
		
	generate( ilist.begin(), ilist.end(), odd_by_twos );

	// generates:
	// elements within list the first invocation:
	// 1 3 5 7 9 11 13 15 17 19 

	cout << "elements within list the first invocation:\n";
	for_each( ilist.begin(), ilist.end(), pfi );
		
	generate( ilist.begin(), ilist.end(), odd_by_twos );

	// generates: 
	// elements within list the second iteration:
	// 21 23 25 27 29 31 33 35 37 39 
	cout << "\n\nelements within list the second iteration:\n";
	for_each( ilist.begin(), ilist.end(), pfi );
		
	return 0;
}

⌨️ 快捷键说明

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