/*
 * Copyright (c) 1999 Johnny C. Lam.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  The author makes no representations
 * about the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 */

#include <auto_vector>
#include <iostream>
#include <memory>

using namespace std;

class Foo {
    static int count;
public:
    int i;

    Foo() { i = count++; cout << i << endl; }
    ~Foo() { cout << "~" << i << endl; }
};

int Foo::count = 0;

auto_ptr<Foo>
source()
{
    return auto_ptr<Foo>(new Foo());
}

void
sink(auto_ptr<Foo>)
{}

int
main()
{
    auto_ptr<Foo> strong_ptr(new Foo());
    auto_ptr<Foo> p( source() );

    sink(p);
    sink(source());

    auto_vector<Foo> strong_vec;
    for (unsigned int i = 0; i < 10; ++i) {
	auto_ptr<Foo> sp(new Foo());
	strong_vec.push_back(sp);
    }
    auto_vector<Foo>::const_iterator f = strong_vec.begin();
    auto_vector<Foo>::const_iterator end = strong_vec.end();

    while (f != end) {
	cout << "\t" << f->i << endl;
	++f;
    }

    auto_vector<Foo> sv2;
    auto_vector<Foo> sv3(20);

    return 0;
}
