X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libs%2Fcontainer%2Ftest%2Fmovable_int.hpp;h=38678d74743225dc00e1c8427bd43a1970b1b592;hb=08c1e93fa36a49f49325a07fe91ff92c964c2b6c;hp=9402b163bc93d1165d10dda63c5763697ba03dba;hpb=bb4dd8289b351fae6b55e303f189127a394a1edd;p=platform%2Fupstream%2Fboost.git diff --git a/libs/container/test/movable_int.hpp b/libs/container/test/movable_int.hpp index 9402b16..38678d7 100644 --- a/libs/container/test/movable_int.hpp +++ b/libs/container/test/movable_int.hpp @@ -13,7 +13,10 @@ #include #include -#include +#include +#include +#include +#include namespace boost { namespace container { @@ -34,49 +37,75 @@ class movable_int BOOST_MOVABLE_BUT_NOT_COPYABLE(movable_int) public: + + static unsigned int count; + movable_int() : m_int(0) - {} + { ++count; } explicit movable_int(int a) : m_int(a) - {} + { + //Disallow INT_MIN + BOOST_ASSERT(this->m_int != INT_MIN); + ++count; + } movable_int(BOOST_RV_REF(movable_int) mmi) : m_int(mmi.m_int) - { mmi.m_int = 0; } + { mmi.m_int = 0; ++count; } movable_int & operator= (BOOST_RV_REF(movable_int) mmi) - { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } + { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } movable_int & operator= (int i) - { this->m_int = i; return *this; } + { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; } - bool operator ==(const movable_int &mi) const - { return this->m_int == mi.m_int; } + ~movable_int() + { + //Double destructor called + BOOST_ASSERT(this->m_int != INT_MIN); + this->m_int = INT_MIN; + --count; + } - bool operator !=(const movable_int &mi) const - { return this->m_int != mi.m_int; } + friend bool operator ==(const movable_int &l, const movable_int &r) + { return l.m_int == r.m_int; } - bool operator <(const movable_int &mi) const - { return this->m_int < mi.m_int; } + friend bool operator !=(const movable_int &l, const movable_int &r) + { return l.m_int != r.m_int; } - bool operator <=(const movable_int &mi) const - { return this->m_int <= mi.m_int; } + friend bool operator <(const movable_int &l, const movable_int &r) + { return l.m_int < r.m_int; } - bool operator >=(const movable_int &mi) const - { return this->m_int >= mi.m_int; } + friend bool operator <=(const movable_int &l, const movable_int &r) + { return l.m_int <= r.m_int; } - bool operator >(const movable_int &mi) const - { return this->m_int > mi.m_int; } + friend bool operator >=(const movable_int &l, const movable_int &r) + { return l.m_int >= r.m_int; } + + friend bool operator >(const movable_int &l, const movable_int &r) + { return l.m_int > r.m_int; } int get_int() const { return m_int; } + friend bool operator==(const movable_int &l, int r) + { return l.get_int() == r; } + + friend bool operator==(int l, const movable_int &r) + { return l == r.get_int(); } + private: int m_int; }; +unsigned int movable_int::count = 0; + +inline movable_int produce_movable_int() +{ return movable_int(); } + template std::basic_ostream & operator<< (std::basic_ostream & os, movable_int const & p) @@ -86,7 +115,6 @@ std::basic_ostream & operator<< return os; } - template<> struct is_copyable { @@ -98,21 +126,36 @@ class movable_and_copyable_int BOOST_COPYABLE_AND_MOVABLE(movable_and_copyable_int) public: + + static unsigned int count; + movable_and_copyable_int() : m_int(0) - {} + { ++count; } explicit movable_and_copyable_int(int a) : m_int(a) - {} + { + //Disallow INT_MIN + BOOST_ASSERT(this->m_int != INT_MIN); + ++count; + } movable_and_copyable_int(const movable_and_copyable_int& mmi) : m_int(mmi.m_int) - {} - + { ++count; } + movable_and_copyable_int(BOOST_RV_REF(movable_and_copyable_int) mmi) : m_int(mmi.m_int) - { mmi.m_int = 0; } + { mmi.m_int = 0; ++count; } + + ~movable_and_copyable_int() + { + //Double destructor called + BOOST_ASSERT(this->m_int != INT_MIN); + this->m_int = INT_MIN; + --count; + } movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi) { this->m_int = mi.m_int; return *this; } @@ -121,33 +164,44 @@ class movable_and_copyable_int { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; } movable_and_copyable_int & operator= (int i) - { this->m_int = i; return *this; } + { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; } - bool operator ==(const movable_and_copyable_int &mi) const - { return this->m_int == mi.m_int; } + friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int == r.m_int; } - bool operator !=(const movable_and_copyable_int &mi) const - { return this->m_int != mi.m_int; } + friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int != r.m_int; } - bool operator <(const movable_and_copyable_int &mi) const - { return this->m_int < mi.m_int; } + friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int < r.m_int; } - bool operator <=(const movable_and_copyable_int &mi) const - { return this->m_int <= mi.m_int; } + friend bool operator <=(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int <= r.m_int; } - bool operator >=(const movable_and_copyable_int &mi) const - { return this->m_int >= mi.m_int; } + friend bool operator >=(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int >= r.m_int; } - bool operator >(const movable_and_copyable_int &mi) const - { return this->m_int > mi.m_int; } + friend bool operator >(const movable_and_copyable_int &l, const movable_and_copyable_int &r) + { return l.m_int > r.m_int; } int get_int() const { return m_int; } + friend bool operator==(const movable_and_copyable_int &l, int r) + { return l.get_int() == r; } + + friend bool operator==(int l, const movable_and_copyable_int &r) + { return l == r.get_int(); } + private: int m_int; }; +unsigned int movable_and_copyable_int::count = 0; + +inline movable_and_copyable_int produce_movable_and_copyable_int() +{ return movable_and_copyable_int(); } + template std::basic_ostream & operator<< (std::basic_ostream & os, movable_and_copyable_int const & p) @@ -166,46 +220,75 @@ struct is_copyable class copyable_int { public: + + static unsigned int count; + copyable_int() : m_int(0) - {} + { ++count; } explicit copyable_int(int a) : m_int(a) - {} + { + //Disallow INT_MIN + BOOST_ASSERT(this->m_int != INT_MIN); + ++count; + } copyable_int(const copyable_int& mmi) : m_int(mmi.m_int) - {} - + { ++count; } + copyable_int & operator= (int i) - { this->m_int = i; return *this; } + { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; } - bool operator ==(const copyable_int &mi) const - { return this->m_int == mi.m_int; } + copyable_int & operator= (const copyable_int &ci) + { this->m_int = ci.m_int; BOOST_ASSERT(this->m_int != INT_MIN); return *this; } - bool operator !=(const copyable_int &mi) const - { return this->m_int != mi.m_int; } + ~copyable_int() + { + //Double destructor called + BOOST_ASSERT(this->m_int != INT_MIN); + this->m_int = INT_MIN; + --count; + } - bool operator <(const copyable_int &mi) const - { return this->m_int < mi.m_int; } + friend bool operator ==(const copyable_int &l, const copyable_int &r) + { return l.m_int == r.m_int; } - bool operator <=(const copyable_int &mi) const - { return this->m_int <= mi.m_int; } + friend bool operator !=(const copyable_int &l, const copyable_int &r) + { return l.m_int != r.m_int; } - bool operator >=(const copyable_int &mi) const - { return this->m_int >= mi.m_int; } + friend bool operator <(const copyable_int &l, const copyable_int &r) + { return l.m_int < r.m_int; } - bool operator >(const copyable_int &mi) const - { return this->m_int > mi.m_int; } + friend bool operator <=(const copyable_int &l, const copyable_int &r) + { return l.m_int <= r.m_int; } + + friend bool operator >=(const copyable_int &l, const copyable_int &r) + { return l.m_int >= r.m_int; } + + friend bool operator >(const copyable_int &l, const copyable_int &r) + { return l.m_int > r.m_int; } int get_int() const { return m_int; } + friend bool operator==(const copyable_int &l, int r) + { return l.get_int() == r; } + + friend bool operator==(int l, const copyable_int &r) + { return l == r.get_int(); } + private: int m_int; }; +unsigned int copyable_int::count = 0; + +inline copyable_int produce_copyable_int() +{ return copyable_int(); } + template std::basic_ostream & operator<< (std::basic_ostream & os, copyable_int const & p) @@ -227,13 +310,19 @@ class non_copymovable_int non_copymovable_int & operator= (const non_copymovable_int &mi); public: + + static unsigned int count; + non_copymovable_int() : m_int(0) - {} + { ++count; } explicit non_copymovable_int(int a) : m_int(a) - {} + { ++count; } + + ~non_copymovable_int() + { m_int = 0; --count; } bool operator ==(const non_copymovable_int &mi) const { return this->m_int == mi.m_int; } @@ -256,10 +345,53 @@ class non_copymovable_int int get_int() const { return m_int; } + friend bool operator==(const non_copymovable_int &l, int r) + { return l.get_int() == r; } + + friend bool operator==(int l, const non_copymovable_int &r) + { return l == r.get_int(); } + private: int m_int; }; +unsigned int non_copymovable_int::count = 0; + +template +struct life_count +{ + static unsigned check(unsigned) { return true; } +}; + +template<> +struct life_count< movable_int > +{ + static unsigned check(unsigned c) + { return c == movable_int::count; } +}; + +template<> +struct life_count< copyable_int > +{ + static unsigned check(unsigned c) + { return c == copyable_int::count; } +}; + +template<> +struct life_count< movable_and_copyable_int > +{ + static unsigned check(unsigned c) + { return c == movable_and_copyable_int::count; } +}; + +template<> +struct life_count< non_copymovable_int > +{ + static unsigned check(unsigned c) + { return c == non_copymovable_int::count; } +}; + + } //namespace test { } //namespace container { } //namespace boost {