mirror of
https://github.com/boostorg/intrusive.git
synced 2025-05-09 23:03:56 +00:00
gcc 4.3 fixes for normal and -std=c++0x modes
[SVN r46577]
This commit is contained in:
parent
e9cdb500d6
commit
883b50a8d4
62
example/doc_any_hook.cpp
Normal file
62
example/doc_any_hook.cpp
Normal file
@ -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 <vector>
|
||||
#include <boost/intrusive/any_hook.hpp>
|
||||
#include <boost/intrusive/slist.hpp>
|
||||
#include <boost/intrusive/list.hpp>
|
||||
|
||||
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<MyClass, BaseSlistOption> 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<MyClass, MemberListOption> MemberList;
|
||||
|
||||
//Create several MyClass objects, each one with a different value
|
||||
std::vector<MyClass> 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<MyClass>::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<MyClass>::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;
|
||||
}
|
||||
//]
|
133
proj/vc7ide/any_test/any_test.vcproj
Normal file
133
proj/vc7ide/any_test/any_test.vcproj
Normal file
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="any_hook"
|
||||
ProjectGUID="{97B61B24-4C97-9681-50BF-243175A813B6}"
|
||||
RootNamespace="any_hook"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../../../../"
|
||||
PreprocessorDefinitions="BOOST_DATE_TIME_NO_LIB"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="FALSE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
DisableLanguageExtensions="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/any_hook.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/any_hook.pdb"
|
||||
GenerateMapFile="FALSE"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../../../../../"
|
||||
PreprocessorDefinitions="BOOST_DATE_TIME_NO_LIB"
|
||||
RuntimeLibrary="4"
|
||||
DisableLanguageExtensions="FALSE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/any_hook.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4737FFC1-76A6-A5C7-4376-2EA02C41523F}">
|
||||
<File
|
||||
RelativePath="..\..\..\test\any_test.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
178
test/any_test.cpp
Normal file
178
test/any_test.cpp
Normal file
@ -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<boost/intrusive/detail/config_begin.hpp>
|
||||
#include<boost/intrusive/any_hook.hpp>
|
||||
#include<boost/intrusive/slist.hpp>
|
||||
#include<boost/intrusive/rbtree.hpp>
|
||||
#include<boost/intrusive/list.hpp>
|
||||
#include<boost/intrusive/avltree.hpp>
|
||||
#include<boost/intrusive/sgtree.hpp>
|
||||
#include<boost/intrusive/splaytree.hpp>
|
||||
#include<boost/intrusive/hashtable.hpp>
|
||||
#include<boost/functional/hash.hpp>
|
||||
#include <vector> //std::vector
|
||||
#include <cstddef> //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<int>()(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<any_to_unordered_set_hook< BaseHook > >::type bucket_type;
|
||||
typedef unordered_default_bucket_traits<any_to_unordered_set_hook< BaseHook > >::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<MyClass, BaseOption, constant_time_size<false> > BaseList;
|
||||
|
||||
//Define an slist that will store MyClass using the public member hook
|
||||
typedef any_to_slist_hook< member_hook<MyClass, any_member_hook<>, &MyClass::member_hook_> > MemberOption;
|
||||
typedef slist<MyClass, MemberOption> MemberList;
|
||||
|
||||
typedef std::vector<MyClass>::iterator VectIt;
|
||||
typedef std::vector<MyClass>::reverse_iterator VectRit;
|
||||
|
||||
//Create several MyClass objects, each one with a different value
|
||||
std::vector<MyClass> 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 <boost/intrusive/detail/config_end.hpp>
|
Loading…
x
Reference in New Issue
Block a user