From 883b50a8d4b1c75f71c66585f2bc4321c9b6cbbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 21 Jun 2008 09:15:00 +0000 Subject: [PATCH] gcc 4.3 fixes for normal and -std=c++0x modes [SVN r46577] --- example/doc_any_hook.cpp | 62 ++++++++++ proj/vc7ide/any_test/any_test.vcproj | 133 ++++++++++++++++++++ test/any_test.cpp | 178 +++++++++++++++++++++++++++ 3 files changed, 373 insertions(+) create mode 100644 example/doc_any_hook.cpp create mode 100644 proj/vc7ide/any_test/any_test.vcproj create mode 100644 test/any_test.cpp diff --git a/example/doc_any_hook.cpp b/example/doc_any_hook.cpp new file mode 100644 index 0000000..15220dc --- /dev/null +++ b/example/doc_any_hook.cpp @@ -0,0 +1,62 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2008 +// +// 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/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// +//[doc_any_hook +#include +#include +#include +#include + +using namespace boost::intrusive; + +class MyClass : public any_base_hook<> //Base hook +{ + int int_; + + public: + any_member_hook<> member_hook_; //Member hook + + MyClass(int i = 0) : int_(i) + {} +}; + +int main() +{ + //Define a base hook option that converts any_base_hook to a slist hook + typedef any_to_slist_hook < base_hook< any_base_hook<> > > BaseSlistOption; + typedef slist BaseSList; + + //Define a member hook option that converts any_base_hook to a list hook + typedef any_to_list_hook< member_hook + < MyClass, any_member_hook<>, &MyClass::member_hook_> > MemberListOption; + typedef list MemberList; + + //Create several MyClass objects, each one with a different value + std::vector values; + for(int i = 0; i < 100; ++i){ values.push_back(MyClass(i)); } + + BaseSList base_slist; MemberList member_list; + + //Now insert them in reverse order in the slist and in order in the list + for(std::vector::iterator it(values.begin()), itend(values.end()); it != itend; ++it) + base_slist.push_front(*it), member_list.push_back(*it); + + //Now test lists + BaseSList::iterator bit(base_slist.begin()), bitend(base_slist.end()); + MemberList::reverse_iterator mrit(member_list.rbegin()), mritend(member_list.rend()); + std::vector::reverse_iterator rit(values.rbegin()), ritend(values.rend()); + + //Test the objects inserted in the base hook list + for(; rit != ritend; ++rit, ++bit, ++mrit) + if(&*bit != &*rit || &*mrit != &*rit) return 1; + return 0; +} +//] diff --git a/proj/vc7ide/any_test/any_test.vcproj b/proj/vc7ide/any_test/any_test.vcproj new file mode 100644 index 0000000..b053349 --- /dev/null +++ b/proj/vc7ide/any_test/any_test.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/any_test.cpp b/test/any_test.cpp new file mode 100644 index 0000000..9c24c56 --- /dev/null +++ b/test/any_test.cpp @@ -0,0 +1,178 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (C) Copyright Ion Gaztanaga 2006-2007. +// +// 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/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //std::vector +#include //std::size_t + +using namespace boost::intrusive; + +class MyClass : public any_base_hook<> +{ + int int_; + + public: + //This is a member hook + any_member_hook<> member_hook_; + + MyClass(int i = 0) + : int_(i) + {} + + int get() const + { return this->int_; } + + friend bool operator < (const MyClass &l, const MyClass &r) + { return l.int_ < r.int_; } + + friend bool operator == (const MyClass &l, const MyClass &r) + { return l.int_ == r.int_; } + + friend std::size_t hash_value(const MyClass &o) + { return boost::hash()(o.get()); } +}; + +void instantiation_test() +{ + typedef member_hook< MyClass, any_member_hook<>, &MyClass::member_hook_> MemberHook; + typedef base_hook< any_base_hook<> > BaseHook; + + MyClass myclass; + { + slist < MyClass, any_to_slist_hook< BaseHook > > slist_base; + slist_base.push_front(myclass); + } + { + slist < MyClass, any_to_slist_hook< MemberHook > > slist_member; + slist_member.push_front(myclass); + } + { + list < MyClass, any_to_list_hook< BaseHook > > list_base; + list_base.push_front(myclass); + } + { + list < MyClass, any_to_list_hook< MemberHook > > list_member; + list_member.push_front(myclass); + } + { + rbtree < MyClass, any_to_set_hook< BaseHook > > rbtree_base; + rbtree_base.insert_unique(myclass); + } + { + rbtree < MyClass, any_to_set_hook< MemberHook > > rbtree_member; + rbtree_member.insert_unique(myclass); + } + { + avltree < MyClass, any_to_avl_set_hook< BaseHook > > avltree_base; + avltree_base.insert_unique(myclass); + } + { + avltree < MyClass, any_to_avl_set_hook< MemberHook > > avltree_member; + avltree_member.insert_unique(myclass); + } + { + sgtree < MyClass, any_to_bs_set_hook< BaseHook > > sgtree_base; + sgtree_base.insert_unique(myclass); + } + { + sgtree < MyClass, any_to_bs_set_hook< MemberHook > > sgtree_member; + sgtree_member.insert_unique(myclass); + } + { + splaytree < MyClass, any_to_bs_set_hook< BaseHook > > splaytree_base; + splaytree_base.insert_unique(myclass); + } + { + splaytree < MyClass, any_to_bs_set_hook< MemberHook > > splaytree_member; + splaytree_member.insert_unique(myclass); + } + typedef unordered_bucket >::type bucket_type; + typedef unordered_default_bucket_traits >::type bucket_traits; + bucket_type buckets[2]; + { + hashtable < MyClass, any_to_unordered_set_hook< BaseHook > > + hashtable_base(bucket_traits(&buckets[0], 1)); + hashtable_base.insert_unique(myclass); + } + { + hashtable < MyClass, any_to_unordered_set_hook< MemberHook > > + hashtable_member(bucket_traits(&buckets[1], 1)); + hashtable_member.insert_unique(myclass); + } +} + +bool simple_slist_test() +{ + //Define an slist that will store MyClass using the public base hook + typedef any_to_slist_hook< base_hook< any_base_hook<> > >BaseOption; + typedef slist > BaseList; + + //Define an slist that will store MyClass using the public member hook + typedef any_to_slist_hook< member_hook, &MyClass::member_hook_> > MemberOption; + typedef slist MemberList; + + typedef std::vector::iterator VectIt; + typedef std::vector::reverse_iterator VectRit; + + //Create several MyClass objects, each one with a different value + std::vector values; + for(int i = 0; i < 100; ++i) values.push_back(MyClass(i)); + + BaseList baselist; + MemberList memberlist; + + //Now insert them in the reverse order in the base hook list + for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) + baselist.push_front(*it); + + //Now insert them in the same order as in vector in the member hook list + for(BaseList::iterator it(baselist.begin()), itend(baselist.end()) + ; it != itend; ++it){ + memberlist.push_front(*it); + } + + //Now test lists + { + BaseList::iterator bit(baselist.begin()), bitend(baselist.end()); + MemberList::iterator mit(memberlist.begin()), mitend(memberlist.end()); + VectRit rit(values.rbegin()), ritend(values.rend()); + VectIt it(values.begin()), itend(values.end()); + + //Test the objects inserted in the base hook list + for(; rit != ritend; ++rit, ++bit) + if(&*bit != &*rit) return false; + + //Test the objects inserted in the member hook list + for(; it != itend; ++it, ++mit) + if(&*mit != &*it) return false; + } + return true; +} + +int main() +{ + if(!simple_slist_test()) + return 1; + instantiation_test(); + return 0; +} + +#include