Merged for Boost 1.48

[SVN r74161]
This commit is contained in:
Ion Gaztañaga
2011-08-30 15:49:49 +00:00
parent f5db9a8d1f
commit 38805868fc
59 changed files with 8071 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
# Boost Container Library Example Jamfile
# (C) Copyright Ion Gaztanaga 2009
# Use, modification and distribution are subject to 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)
# Adapted from John Maddock's TR1 Jamfile.v2
# Copyright John Maddock 2005.
# Use, modification and distribution are subject to 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)
# this rule enumerates through all the sources and invokes
# the run rule for each source, the result is a list of all
# the run rules, which we can pass on to the test_suite rule:
rule test_all
{
local all_rules = ;
for local fileb in [ glob doc_*.cpp ]
{
all_rules += [ run $(fileb)
: # additional args
: # test-files
: # requirements
] ;
}
return $(all_rules) ;
}
test-suite container_example : [ test_all r ] : <threading>multi ;
+44
View File
@@ -0,0 +1,44 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2011. 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.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
//[doc_emplace
#include <boost/container/list.hpp>
#include <cassert>
//Non-copyable and non-movable class
class non_copy_movable
{
non_copy_movable(const non_copy_movable &);
non_copy_movable& operator=(const non_copy_movable &);
public:
non_copy_movable(int = 0) {}
};
int main ()
{
using namespace boost::container;
//Store non-copyable and non-movable objects in a list
list<non_copy_movable> l;
non_copy_movable ncm;
//A new element will be built calling non_copy_movable(int) contructor
l.emplace(l.begin(), 0);
assert(l.size() == 1);
//A new element will be built calling the default constructor
l.emplace(l.begin());
assert(l.size() == 2);
return 0;
}
//]
#include <boost/container/detail/config_end.hpp>
+54
View File
@@ -0,0 +1,54 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2011. 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.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
//[doc_move_containers
#include <boost/container/vector.hpp>
#include <boost/move/move.hpp>
#include <cassert>
//Non-copyable class
class non_copyable
{
BOOST_MOVABLE_BUT_NOT_COPYABLE(non_copyable)
public:
non_copyable(){}
non_copyable(BOOST_RV_REF(non_copyable)) {}
non_copyable& operator=(BOOST_RV_REF(non_copyable)) { return *this; }
};
int main ()
{
using namespace boost::container;
//Store non-copyable objects in a vector
vector<non_copyable> v;
non_copyable nc;
v.push_back(boost::move(nc));
assert(v.size() == 1);
//Reserve no longer needs copy-constructible
v.reserve(100);
assert(v.capacity() >= 100);
//This resize overload only needs movable and default constructible
v.resize(200);
assert(v.size() == 200);
//Containers are also movable
vector<non_copyable> v_other(boost::move(v));
assert(v_other.size() == 200);
assert(v.empty());
return 0;
}
//]
#include <boost/container/detail/config_end.hpp>
+61
View File
@@ -0,0 +1,61 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2011. 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.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
//[doc_recursive_containers
#include <boost/container/vector.hpp>
#include <boost/container/list.hpp>
#include <boost/container/map.hpp>
#include <boost/container/stable_vector.hpp>
#include <boost/container/string.hpp>
using namespace boost::container;
struct data
{
int i_;
//A vector holding still undefined class 'data'
vector<data> v_;
//A list holding still undefined 'data'
list<data> l_;
//A map holding still undefined 'data'
map<data, data> m_;
friend bool operator <(const data &l, const data &r)
{ return l.i_ < r.i_; }
};
struct tree_node
{
string name;
string value;
//children nodes of this node
list<tree_node> children_;
};
int main()
{
//a container holding a recursive data type
stable_vector<data> sv;
sv.resize(100);
//Let's build a tree based in
//a recursive data type
tree_node root;
root.name = "root";
root.value = "root_value";
root.children_.resize(7);
return 0;
}
//]
#include <boost/container/detail/config_end.hpp>
+91
View File
@@ -0,0 +1,91 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2011. 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.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
//[doc_type_erasure_MyClassHolder_h
#include <boost/container/vector.hpp>
//MyClassHolder.h
//We don't need to include "MyClass.h"
//to store vector<MyClass>
class MyClass;
class MyClassHolder
{
public:
void AddNewObject(const MyClass &o);
const MyClass & GetLastObject() const;
private:
::boost::container::vector<MyClass> vector_;
};
//]
//[doc_type_erasure_MyClass_h
//MyClass.h
class MyClass
{
private:
int value_;
public:
MyClass(int val = 0) : value_(val){}
friend bool operator==(const MyClass &l, const MyClass &r)
{ return l.value_ == r.value_; }
//...
};
//]
//[doc_type_erasure_main_cpp
//Main.cpp
//=#include "MyClassHolder.h"
//=#include "MyClass.h"
#include <cassert>
int main()
{
MyClass mc(7);
MyClassHolder myclassholder;
myclassholder.AddNewObject(mc);
return myclassholder.GetLastObject() == mc ? 0 : 1;
}
//]
//[doc_type_erasure_MyClassHolder_cpp
//MyClassHolder.cpp
//=#include "MyClassHolder.h"
//In the implementation MyClass must be a complete
//type so we include the appropriate header
//=#include "MyClass.h"
void MyClassHolder::AddNewObject(const MyClass &o)
{ vector_.push_back(o); }
const MyClass & MyClassHolder::GetLastObject() const
{ return vector_.back(); }
//]
#include <boost/container/detail/config_end.hpp>