00-1.cpp

来自「effective stl 源代码 code」· C++ 代码 · 共 41 行

CPP
41
字号
//
// Examples from Introduction
//

#include <iostream>
#include <vector>

#include "ESTLUtil.h"


template<typename C>
bool lastGreaterThanFirst(const C& container)
{
	if (container.empty()) return false;
	typename C::const_iterator begin(container.begin());
	typename C::const_iterator end(container.end());
	return *--end > *begin;
}

int main()
{
	using namespace std;
	using namespace ESTLUtils;

	const int ints[] = { -30, 102, 55, -19, 0, 222, -3000, 4000, 8, -2 };
	const size_t nints = sizeof ints / sizeof (int);

	vector<int> v(ints, ints + nints);
	printContainer("v", v);

	cout << "lastGreaterThanFirst(v) returns: " <<
				lastGreaterThanFirst(v) << endl;

	v[0] = 5;

	cout << "lastGreaterThanFirst(v) returns: " <<
				lastGreaterThanFirst(v) << endl;

	return 0;
}

⌨️ 快捷键说明

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