123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- ///////////////////////////////////////////////////////////////////////////
- //
- // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
- // Software License, Version 1.0. (See accompanying file
- // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- // See http://www.boost.org/libs/container for documentation.
- //
- ///////////////////////////////////////////////////////////////////////////
- #ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
- #define BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
- #include <boost/container/detail/config_begin.hpp>
- #include <boost/container/detail/workaround.hpp>
- #include <boost/move/utility_core.hpp>
- #include <ostream>
- #include <climits>
- #include <boost/assert.hpp>
- namespace boost {
- namespace container {
- namespace test {
- template<class T>
- struct is_copyable;
- template<>
- struct is_copyable<int>
- {
- static const bool value = true;
- };
- 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; ++count; }
- movable_int & operator= (BOOST_RV_REF(movable_int) mmi)
- { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
- movable_int & operator= (int i)
- { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
- ~movable_int()
- {
- //Double destructor called
- BOOST_ASSERT(this->m_int != INT_MIN);
- this->m_int = INT_MIN;
- --count;
- }
- 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; }
- 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; }
- 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(); }
- 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(); }
- friend std::size_t hash_value(const movable_int &v)
- { return (std::size_t)v.get_int(); }
- private:
- int m_int;
- };
- unsigned int movable_int::count = 0;
- inline movable_int produce_movable_int()
- { return movable_int(); }
- template<class E, class T>
- std::basic_ostream<E, T> & operator<<
- (std::basic_ostream<E, T> & os, movable_int const & p)
- {
- os << p.get_int();
- return os;
- }
- template<>
- struct is_copyable<movable_int>
- {
- static const bool value = false;
- };
- 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; ++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; }
- movable_and_copyable_int & operator= (BOOST_RV_REF(movable_and_copyable_int) mmi)
- { this->m_int = mmi.m_int; mmi.m_int = 0; return *this; }
- movable_and_copyable_int & operator= (int i)
- { this->m_int = i; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
- friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
- { return l.m_int == r.m_int; }
- friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
- { return l.m_int != r.m_int; }
- friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
- { return l.m_int < r.m_int; }
- friend bool operator <=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
- { return l.m_int <= r.m_int; }
- friend bool operator >=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
- { return l.m_int >= r.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(); }
- 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(); }
- friend std::size_t hash_value(const movable_and_copyable_int &v)
- { return (std::size_t)v.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<class E, class T>
- std::basic_ostream<E, T> & operator<<
- (std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
- {
- os << p.get_int();
- return os;
- }
- template<>
- struct is_copyable<movable_and_copyable_int>
- {
- static const bool value = true;
- };
- 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; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
- copyable_int & operator= (const copyable_int &ci)
- { this->m_int = ci.m_int; BOOST_ASSERT(this->m_int != INT_MIN); return *this; }
- ~copyable_int()
- {
- //Double destructor called
- BOOST_ASSERT(this->m_int != INT_MIN);
- this->m_int = INT_MIN;
- --count;
- }
- 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; }
- 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(); }
- 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(); }
- friend std::size_t hash_value(const copyable_int &v)
- { return (std::size_t)v.get_int(); }
- private:
- int m_int;
- };
- unsigned int copyable_int::count = 0;
- inline copyable_int produce_copyable_int()
- { return copyable_int(); }
- template<class E, class T>
- std::basic_ostream<E, T> & operator<<
- (std::basic_ostream<E, T> & os, copyable_int const & p)
- {
- os << p.get_int();
- return os;
- }
- template<>
- struct is_copyable<copyable_int>
- {
- static const bool value = true;
- };
- class non_copymovable_int
- {
- non_copymovable_int(const non_copymovable_int& mmi);
- 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; }
- bool operator !=(const non_copymovable_int &mi) const
- { return this->m_int != mi.m_int; }
- bool operator <(const non_copymovable_int &mi) const
- { return this->m_int < mi.m_int; }
- bool operator <=(const non_copymovable_int &mi) const
- { return this->m_int <= mi.m_int; }
- bool operator >=(const non_copymovable_int &mi) const
- { return this->m_int >= mi.m_int; }
- bool operator >(const non_copymovable_int &mi) const
- { return this->m_int > mi.m_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(); }
- 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(); }
- friend std::size_t hash_value(const non_copymovable_int &v)
- { return (std::size_t)v.get_int(); }
- private:
- int m_int;
- };
- unsigned int non_copymovable_int::count = 0;
- template<class T>
- 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 {
- #include <boost/container/detail/config_end.hpp>
- #endif //#ifndef BOOST_CONTAINER_TEST_MOVABLE_INT_HEADER
|