mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Added test for containers using scoped allocator
[SVN r77915]
This commit is contained in:
@@ -47,6 +47,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scoped_allocator_adaptor_te
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scoped_allocator_usage_test", "scoped_allocator_usage_test.vcproj", "{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
@@ -103,6 +107,10 @@ Global
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Debug.Build.0 = Debug|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Release.ActiveCfg = Release|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Release.Build.0 = Release|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Debug.ActiveCfg = Debug|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Debug.Build.0 = Debug|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Release.ActiveCfg = Release|Win32
|
||||
{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}.Release.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
|
139
proj/vc7ide/scoped_allocator_usage_test.vcproj
Normal file
139
proj/vc7ide/scoped_allocator_usage_test.vcproj
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="scoped_allocator_usage_test"
|
||||
ProjectGUID="{B4E9FB12-7D7C-4461-83A9-5EB2C78E608F}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="../../Bin/Win32/Debug"
|
||||
IntermediateDirectory="Debug/scoped_allocator_usage_test"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../../.."
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
|
||||
GeneratePreprocessedFile="0"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="FALSE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/scoped_allocator_usage_test_d.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/scoped_allocator_usage_test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
FixedBaseAddress="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="../../Bin/Win32/Release"
|
||||
IntermediateDirectory="Release/scoped_allocator_usage_test"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../../../.."
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
|
||||
RuntimeLibrary="2"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="FALSE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="winmm.lib"
|
||||
OutputFile="$(OutDir)/scoped_allocator_usage_test.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../../stage/lib"
|
||||
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="{41737BCF-4312-7AC5-A066-32D75A32A2AF}">
|
||||
<File
|
||||
RelativePath="..\..\test\scoped_allocator_usage_test.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93815995-89BD-b043-5E8B-65FBE52E2AFB}">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
95
test/scoped_allocator_usage_test.cpp
Normal file
95
test/scoped_allocator_usage_test.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <boost/move/move.hpp>
|
||||
#include <boost/container/map.hpp>
|
||||
#include <boost/container/scoped_allocator.hpp>
|
||||
|
||||
template <typename Ty>
|
||||
class SimpleAllocator
|
||||
{
|
||||
public:
|
||||
typedef Ty value_type;
|
||||
typedef typename std::allocator<Ty>::pointer pointer;
|
||||
typedef typename std::allocator<Ty>::size_type size_type;
|
||||
|
||||
SimpleAllocator(int value)
|
||||
: _value(value)
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
SimpleAllocator(const SimpleAllocator<T> &other)
|
||||
: _value(other._value)
|
||||
{}
|
||||
|
||||
pointer allocate(size_type n)
|
||||
{
|
||||
return _allocator.allocate(n);
|
||||
}
|
||||
void deallocate(pointer p, size_type n)
|
||||
{
|
||||
_allocator.deallocate(p, n);
|
||||
}
|
||||
private:
|
||||
int _value;
|
||||
std::allocator<Ty> _allocator;
|
||||
|
||||
template <typename T> friend class SimpleAllocator;
|
||||
};
|
||||
|
||||
template <typename Ty>
|
||||
class ScopedAllocator : public boost::container::scoped_allocator_adaptor<SimpleAllocator<Ty> >
|
||||
{
|
||||
private:
|
||||
typedef boost::container::scoped_allocator_adaptor<SimpleAllocator<Ty> > Base;
|
||||
|
||||
public:
|
||||
ScopedAllocator(int value)
|
||||
: Base(SimpleAllocator<Ty>(value))
|
||||
{}
|
||||
};
|
||||
|
||||
class Resource
|
||||
{
|
||||
private: // Not copyable
|
||||
Resource(const Resource &);
|
||||
Resource &operator=(const Resource &);
|
||||
public:
|
||||
typedef SimpleAllocator<int> allocator_type;
|
||||
|
||||
Resource(BOOST_RV_REF(Resource)other)
|
||||
: _value(other._value), _allocator(boost::move(other._allocator))
|
||||
{
|
||||
other._value = -1;
|
||||
}
|
||||
|
||||
Resource(BOOST_RV_REF(Resource)other, const allocator_type &allocator)
|
||||
: _value(other._value), _allocator(allocator)
|
||||
{
|
||||
other._value = -1;
|
||||
}
|
||||
|
||||
Resource(int value, const allocator_type &allocator)
|
||||
: _value(value), _allocator(allocator)
|
||||
{}
|
||||
private:
|
||||
int _value;
|
||||
allocator_type _allocator;
|
||||
};
|
||||
|
||||
typedef std::pair<const std::string, Resource> MapNode;
|
||||
|
||||
typedef boost::container::scoped_allocator_adaptor<SimpleAllocator<MapNode> > MapAllocator;
|
||||
|
||||
typedef boost::container::map<std::string, Resource, std::less<std::string>, MapAllocator> Map;
|
||||
|
||||
int main()
|
||||
{
|
||||
Map map1(std::less<std::string>(), SimpleAllocator<MapNode>(5));
|
||||
|
||||
map1.emplace("foo", 42);
|
||||
map1.emplace("bar", 11);
|
||||
|
||||
//Map map2 = map1;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user