1 //----------------------------------------------------------------------------- 2 // boost-libs variant/test/class_a.cpp source file 3 // See http://www.boost.org for updates, documentation, and revision history. 4 //----------------------------------------------------------------------------- 5 // 6 // Copyright (c) 2003 7 // Eric Friedman, Itay Maman 8 // 9 // Distributed under the Boost Software License, Version 1.0. (See 10 // accompanying file LICENSE_1_0.txt or copy at 11 // http://www.boost.org/LICENSE_1_0.txt) 12 13 #include <algorithm> // for std::swap 14 #include <sstream> 15 #include <iostream> 16 #include <assert.h> 17 18 #include "class_a.h" 19 20 21 using namespace std; 22 ~class_a()23class_a::~class_a() 24 { 25 assert(self_p_ == this); 26 } 27 class_a(int n)28class_a::class_a(int n) 29 { 30 n_ = n; 31 self_p_ = this; 32 } 33 class_a(const class_a & other)34class_a::class_a(const class_a& other) 35 { 36 n_ = other.n_; 37 self_p_ = this; 38 } 39 40 operator =(const class_a & rhs)41class_a& class_a::operator=(const class_a& rhs) 42 { 43 class_a temp(rhs); 44 swap(temp); 45 46 return *this; 47 } 48 swap(class_a & other)49void class_a::swap(class_a& other) 50 { 51 std::swap(n_, other.n_); 52 } 53 get() const54int class_a::get() const 55 { 56 return n_; 57 } 58 59 60 61 operator <<(std::ostream & strm,const class_a & a)62std::ostream& operator<<(std::ostream& strm, const class_a& a) 63 { 64 return strm << "class_a(" << a.get() << ")"; 65 } 66