//Thinking in C++ p659 2020年06月16日 22时39分22秒
//: :purge.h
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
// Delete pointers in an STL sequence container.
#ifndef PURGE_H
#define PURGE_H
#include <algorithm>
template<class Seq> void purge(Seq& c) {
typename Seq::iterator i;
for(i = c.begin(); i != c.end(); ++i) {
delete *i;
*i = 0;
}
}
// Iterator version:
template<class InpIt> void purge(InpIt begin, InpIt end) {
while(begin != end) {
delete *begin;
*begin = 0;
++begin;
}
}
#endif // PURGE_H ///:~
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>
//int d[] = { 123, 94, 10, 314, 315 };
//const int DSZ = sizeof d / sizeof *d;
double d[] = { 01.23, 91.370, 56.661,
023.230, 19.959, 1.0, 3.14159 };
const int DSZ = sizeof d / sizeof *d;
bool isEven(int x) { return x % 2 == 0; }
class Shape{
public:
virtual void draw() = 0;
virtual ~Shape() {}
};
class Circle : public Shape{
public:
virtual void draw() {std::cout << "Circle::Draw()" << std::endl; }
~Circle() {std::cout << "Circle::~Circle()" << std::endl;}
};
class Square : public Shape{
public:
virtual void draw() {std::cout << "Square::Draw(