All pastes #962759 Raw Copy code Copy link Edit

Mine

public text v1 · immutable
#962759 ·published 2008-03-30 00:03 UTC
rendered paste body
#include <cassert>  // assert
#include <iostream> // cout, endl
#include <vector>   // vector
#include <algorithm>

struct A {
	const int i;
	
	A (int i) : i (i)
    {}
	
	A operator = (A other){
		A temp = A(other);
		//std::cout << "temp = " << temp << std::endl;
		return temp;
	}
	
	/*
	A& operator = (A other){
		A temp = A(other);
		//std::cout << "temp = " << temp << std::endl;
		std::swap(*this, temp);
		return *this;
	}
	*/
	
	friend std::ostream& operator << (std::ostream& lhs, const A& rhs)
	{	lhs << rhs.i;
        return lhs;
	}
};

int main () {
	using namespace std;
	A x(2); 
	A w(3);
	vector<A> y(10, x);
	vector<A> z(5,w);
	z[2]=y[4];
	
	//2 2 2 2 2 2 2 2 2 2 
	for(size_t i = 0; i < 10; ++i)
	{	cout << y[i] << " ";
	}
	cout << endl;
	
	//Problem - should be
	//3 3 2 3 3
	for(size_t i = 0; i < 5; ++i)
	{	cout << z[i] << " ";
	}
	cout << endl;
}