From 7bfb7c8a6160a43bf9f830395d6fc54b1831d867 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 20 Aug 2008 08:25:23 +0000 Subject: [PATCH] Added a data member to swap_test_class and made it EqualityComparable, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php [SVN r48245] --- swap/test/swap_test_class.hpp | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp index aa68444..8cf1fe9 100644 --- a/swap/test/swap_test_class.hpp +++ b/swap/test/swap_test_class.hpp @@ -12,8 +12,11 @@ class swap_test_class { + int m_data; public: - swap_test_class() + explicit swap_test_class(int arg = 0) + : + m_data(arg) { ++constructCount(); } @@ -23,24 +26,40 @@ public: ++destructCount(); } - swap_test_class(const swap_test_class&) + swap_test_class(const swap_test_class& arg) + : + m_data(arg.m_data) { ++copyCount(); ++destructCount(); } - swap_test_class& operator=(const swap_test_class&) + swap_test_class& operator=(const swap_test_class& arg) { + m_data = arg.m_data; ++copyCount(); return *this; } void swap(swap_test_class& other) { + const int temp = m_data; + m_data = other.m_data; + other.m_data = temp; + ++swapCount(); } + int get_data() const + { + return m_data; + } + void set_data(int arg) + { + m_data = arg; + } + static unsigned int swap_count(){ return swapCount(); } static unsigned int copy_count(){ return copyCount(); } static unsigned int construct_count(){ return constructCount(); } @@ -81,4 +100,15 @@ private: }; + +inline bool operator==(const swap_test_class & lhs, const swap_test_class & rhs) +{ + return lhs.get_data() == rhs.get_data(); +} + +inline bool operator!=(const swap_test_class & lhs, const swap_test_class & rhs) +{ + return !(lhs == rhs); +} + #endif