diff options
Diffstat (limited to 'src/boost/libs/ptr_container')
35 files changed, 5118 insertions, 0 deletions
diff --git a/src/boost/libs/ptr_container/Jamfile b/src/boost/libs/ptr_container/Jamfile new file mode 100644 index 00000000..23973f5a --- /dev/null +++ b/src/boost/libs/ptr_container/Jamfile @@ -0,0 +1,10 @@ +# Boost.PtrContainer Library Jamfile +# +# Copyright (c) 2018 James E. King III +# +# 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) + +# please order by name to ease maintenance +build-project test ; diff --git a/src/boost/libs/ptr_container/LICENSE b/src/boost/libs/ptr_container/LICENSE new file mode 100644 index 00000000..36b7cd93 --- /dev/null +++ b/src/boost/libs/ptr_container/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/src/boost/libs/ptr_container/README.md b/src/boost/libs/ptr_container/README.md new file mode 100644 index 00000000..f25dbebb --- /dev/null +++ b/src/boost/libs/ptr_container/README.md @@ -0,0 +1,33 @@ +PtrContainer, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), provides containers for holding heap-allocated objects in an exception-safe manner and with minimal overhead. + +### License + +Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). + +### Properties + +* C++03 +* Header Only + +### Build Status + +Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/ptr_container/tree/master) | [![Build Status](https://travis-ci.org/boostorg/ptr_container.svg?branch=master)](https://travis-ci.org/boostorg/ptr_container) | [![Build status](https://ci.appveyor.com/api/projects/status/xsoiss46xfe6ilig/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/ptr-container-lviqw/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/15842/badge.svg)](https://scan.coverity.com/projects/boostorg-ptr_container) | [![codecov](https://codecov.io/gh/boostorg/ptr_container/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/ptr_container/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/ptr_container.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/ptr_container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/ptr_container.html) +[`develop`](https://github.com/boostorg/ptr_container/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/ptr_container.svg?branch=develop)](https://travis-ci.org/boostorg/ptr_container) | [![Build status](https://ci.appveyor.com/api/projects/status/xsoiss46xfe6ilig/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/ptr-container-lviqw/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/15842/badge.svg)](https://scan.coverity.com/projects/boostorg-ptr_container) | [![codecov](https://codecov.io/gh/boostorg/ptr_container/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/ptr_container/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/ptr_container.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/ptr_container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/ptr_container.html) + +### Directories + +| Name | Purpose | +| ----------- | ------------------------------ | +| `doc` | documentation | +| `include` | headers | +| `test` | unit tests | + +### More information + +* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-ptr_container) +* [Report bugs](https://github.com/boostorg/ptr_container/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). +* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[ptr_container]` tag at the beginning of the subject line. + diff --git a/src/boost/libs/ptr_container/index.html b/src/boost/libs/ptr_container/index.html new file mode 100644 index 00000000..9c8de621 --- /dev/null +++ b/src/boost/libs/ptr_container/index.html @@ -0,0 +1,20 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> + +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<meta http-equiv="refresh" content="0; URL=doc/ptr_container.html"> +<title>Boost.Pointer Container Documentation</title> +<link rel="stylesheet" href="doc/default.css" type="text/css"> +</head> + +<body> +Automatic redirection failed, please go to +<a href="doc/ptr_container.html">doc/pointer_container.html</a> +<hr> +<p>© Copyright Beman Dawes, 2001</p> +<p>Distributed under the Boost Software License, Version 1.0. (See accompanying +file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy +at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> +</body> +</html>
\ No newline at end of file diff --git a/src/boost/libs/ptr_container/meta/libraries.json b/src/boost/libs/ptr_container/meta/libraries.json new file mode 100644 index 00000000..7691bf0e --- /dev/null +++ b/src/boost/libs/ptr_container/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "ptr_container", + "name": "Pointer Container", + "authors": [ + "Thorsten Ottosen" + ], + "description": "Containers for storing heap-allocated polymorphic objects to ease OO-programming.", + "category": [ + "Containers", + "Data" + ], + "maintainers": [ + "Thorsten Ottosen <nesotto -at- cs.auc.dk>" + ] +} diff --git a/src/boost/libs/ptr_container/test/Jamfile.v2 b/src/boost/libs/ptr_container/test/Jamfile.v2 new file mode 100644 index 00000000..9a3e8908 --- /dev/null +++ b/src/boost/libs/ptr_container/test/Jamfile.v2 @@ -0,0 +1,47 @@ +#// +#// Boost.Pointer Container +#// +#// Copyright Thorsten Ottosen 2003-2008. Use, modification and +#// distribution is 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) +#// +#// For more information, see http://www.boost.org/libs/ptr_container/ +#// + +import testing ; + +rule sc-test ( name : extra-sources * ) +{ + return [ + run $(name).cpp /boost/test//boost_unit_test_framework/<link>static $(extra-sources) ] + ; +} + + +test-suite ptr_container : + [ sc-test ptr_inserter ] + [ sc-test ptr_vector ] + [ sc-test ptr_list ] + [ sc-test ptr_deque ] + [ sc-test ptr_set ] + [ sc-test ptr_map ] + [ sc-test ptr_map_adapter ] + [ sc-test ptr_array ] + [ sc-test tree_test ] + [ sc-test incomplete_type_test ] + [ run view_example.cpp ] + [ sc-test iterator_test ] + [ run tut1.cpp ] + [ sc-test indirect_fun ] + [ sc-test serialization : /boost/serialization//boost_serialization ] + [ sc-test no_exceptions ] + + [ sc-test ptr_unordered_set ] + [ sc-test ptr_unordered_map ] + [ sc-test ptr_circular_buffer ] + [ compile const_element_containers.cpp ] + # [ sc-test null_filter_iterator ] + + [ compile issue_23.cpp ] + ; diff --git a/src/boost/libs/ptr_container/test/associative_test_data.hpp b/src/boost/libs/ptr_container/test/associative_test_data.hpp new file mode 100644 index 00000000..e6368635 --- /dev/null +++ b/src/boost/libs/ptr_container/test/associative_test_data.hpp @@ -0,0 +1,216 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/exception.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/range/sub_range.hpp> + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +template< typename C, typename B, typename T, bool Ordered > +void ptr_set_test(); + +template< class T, bool Ordered > +struct test_algorithms +{ + template< class Cont > + void operator()( Cont& c, const Cont& c2 ) const + { + typename Cont::iterator i; + typename Cont::const_iterator ci; + + T* t = new T; + i = c.lower_bound( *t ); + ci = c2.lower_bound( *t ); + i = c.upper_bound( *t ); + ci = c2.upper_bound( *t ); + delete t; + + BOOST_DEDUCED_TYPENAME Cont::reverse_iterator ri = c.rbegin(); + hide_warning(ri); + BOOST_DEDUCED_TYPENAME Cont::const_reverse_iterator cri = c2.rbegin(); + BOOST_DEDUCED_TYPENAME Cont::reverse_iterator rv2 = c.rend(); + hide_warning(rv2); + BOOST_DEDUCED_TYPENAME Cont::const_reverse_iterator cvr2 = c2.rend(); + hide_warning(cvr2); + cri = c.crbegin(); + cri = c.crend(); + } +}; + +template< class T > +struct test_algorithms<T,false> +{ + template< class Cont> + void operator()( Cont& c, const Cont& c2 ) const + { + } +}; + +template< typename C, typename B, typename T, bool Ordered > +void ptr_set_test() +{ + using namespace boost; + + BOOST_TEST_MESSAGE( "starting associative container test" ); + enum { max_cnt = 10, size = 100 }; + C c; + BOOST_CHECK( c.size() == 0 ); + c.insert( c.end(), new T ); + c.insert( c.end(), new T ); + + const C c2( c.begin(), c.end() ); + BOOST_CHECK( c.size() == c2.size() ); + + C c3; + + BOOST_TEST_MESSAGE( "finished construction test" ); + + C a_copy( c ); + BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); + a_copy = a_copy; + BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); + c.clear(); + a_copy = c; + a_copy = a_copy; + BOOST_CHECK( a_copy.empty() ); + + BOOST_TEST_MESSAGE( "finished copying test" ); + + BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); + BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); + BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); + ci = c.cbegin(); + ci = c.cend(); + BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); + hide_warning(i2); + BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); + hide_warning(ci2); + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); + BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); + hide_warning(s2); + BOOST_CHECK_EQUAL( c.size(), s ); + bool b = c.empty(); + hide_warning(b); + BOOST_TEST_MESSAGE( "finished accessors test" ); + + T* t = new T; + c.insert( c.end(), t ); + c.insert( new T ); +#ifndef BOOST_NO_AUTO_PTR + c.insert( c.end(), std::auto_ptr<T>( new T ) ); + std::auto_ptr<T> ap( new T ); + c.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( c.end(), std::unique_ptr<T>( new T ) ); + std::unique_ptr<T> up( new T ); + c.insert( std::move( up ) ); +#endif + c3.insert( c.begin(), c.end() ); + c.erase( c.begin() ); + c3.erase( c3.begin(), c3.end() ); + t = new T; + c.insert( new T ); + c.erase( *t ); + delete t; + + BOOST_CHECK( c3.empty() ); + c.swap( c3 ); + BOOST_CHECK( !c3.empty() ); + BOOST_CHECK( c.empty() ); + c3.clear(); + + // + // remark: we cannot pass c3 directly as it would + // extract const iterators ... and the + // current standard does not allow erase() + // to be given const iterators + // + c3.erase( boost::make_iterator_range(c3) ); + BOOST_CHECK( c3.empty() ); + BOOST_TEST_MESSAGE( "finished modifiers test" ); + + c.insert( c.end(), new T ); + typename C::auto_type ptr2 = c.release( c.begin() ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<C> ap2 = c.release(); +#else + std::unique_ptr<C> up2 = c.release(); +#endif + c = c2.clone(); + BOOST_TEST_MESSAGE( "finished release/clone test" ); + + c3.insert( new T ); + c3.insert( new T ); + BOOST_CHECK_EQUAL( c3.size(), 2u ); +#if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) +#else + c3.insert( make_iterator_range( c ) ); +// BOOST_CHECK_EQUAL( c3.size(), 4u ); +#endif + c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); + BOOST_CHECK( c3.empty() == false ); + c.clear(); + unsigned long c3size = c3.size(); + hide_warning( c3size ); + unsigned long num = c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), + c3.end(), + c3 ); + + BOOST_CHECK( num > 0 ); + BOOST_CHECK_EQUAL( num, c.size() ); + BOOST_CHECK( c3.empty() ); + BOOST_CHECK( !c.empty() ); + c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); + BOOST_CHECK( !c3.empty() ); + BOOST_CHECK( c.empty() ); +#ifdef BOOST_NO_SFINAE +#else + c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range( c3 ), c3 ); + BOOST_CHECK( !c.empty() ); + BOOST_CHECK( c3.empty() ); +#endif + + BOOST_TEST_MESSAGE( "finished transfer test" ); + + C c4; + c4.swap(c3); + swap(c4,c3); + BOOST_TEST_MESSAGE( "finished set/map interface test" ); + + sub_range<C> sub; + sub_range<const C> csub; + + t = new T; + i = c.find( *t ); + ci = c2.find( *t ); + c2.count( *t ); + + test_algorithms<T,Ordered>()( c, c2 ); + sub = c.equal_range( *t ); + csub = c2.equal_range( *t ); + delete t; + + BOOST_TEST_MESSAGE( "finished algorithms interface test" ); + +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif diff --git a/src/boost/libs/ptr_container/test/const_element_containers.cpp b/src/boost/libs/ptr_container/test/const_element_containers.cpp new file mode 100644 index 00000000..ee75a498 --- /dev/null +++ b/src/boost/libs/ptr_container/test/const_element_containers.cpp @@ -0,0 +1,45 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2009. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_container.hpp> + +// force instantiation of all members + +template class boost::ptr_array<const int, 42>; +template class boost::ptr_array<boost::nullable<const int>, 42>; + +template class boost::ptr_deque<const int>; +template class boost::ptr_deque< boost::nullable<const int> >; + +template class boost::ptr_list<const int>; +template class boost::ptr_list< boost::nullable<const int> >; + +template class boost::ptr_map<int, const int>; +template class boost::ptr_map<int, boost::nullable<const int> >; + +template class boost::ptr_vector<const int>; +template class boost::ptr_vector< boost::nullable<const int> >; + +//@todo problem with constructor forwarding +// +//template class boost::ptr_unordered_map<int,T>; + +// @todo: there seems to be some problems with +// argument passing in circular_buffer +// +//boost::ptr_circular_buffer<T> buffer(32); +//buffer.push_back( new int(42) ); + +template class boost::ptr_set<const int>; + +// @todo: problem with constructor forwarding +// +//template class boost::ptr_unordered_set<T>; diff --git a/src/boost/libs/ptr_container/test/incomplete_type_test.cpp b/src/boost/libs/ptr_container/test/incomplete_type_test.cpp new file mode 100644 index 00000000..b8afbd4c --- /dev/null +++ b/src/boost/libs/ptr_container/test/incomplete_type_test.cpp @@ -0,0 +1,186 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/utility.hpp> +#include <algorithm> +#include <iostream> + +using namespace std; +using namespace boost; + +// +// Forward declare 'allocate_clone()' to be able +// use clonability of 'Composite' inline in the class. +// This is normally not needed when using .hpp + .cpp files. +// +class Composite; +Composite* new_clone( const Composite& ); + + +class Composite +{ + typedef ptr_vector<Composite> composite_t; + typedef composite_t::iterator iterator; + typedef composite_t::const_iterator const_iterator; + typedef composite_t::size_type size_type; + composite_t elements_; + + // + // only used internally for 'clone()' + // + Composite( const Composite& r ) : elements_( r.elements_.clone() ) + { } + + // + // this class is not Copyable nor Assignable + // + void operator=( const Composite& ); + +public: + Composite() + { } + + // + // of course detructor is virtual + // + virtual ~Composite() + { } + + // + // one way of adding new elements + // + void add( Composite* c ) + { + elements_.push_back( c ); + } + + // + // second way of adding new elements + // + void add( Composite& c ) + { + elements_.push_back( new_clone( c ) ); + } + + void remove( iterator where ) + { + elements_.erase( where ); + } + + // + // recusively count the elements + // + size_type size() const + { + size_type res = 0; + for( const_iterator i = elements_.begin(); i != elements_.end(); ++i ) + res += i->size(); + return 1 /* this */ + res; + } + + void foo() + { + do_foo(); + for( iterator i = elements_.begin(); i != elements_.end(); ++i ) + i->foo(); + } + + // + // this class is clonable and this is the callback for 'allocate_clone()' + // + Composite* clone() const + { + return do_clone(); + } + +private: + virtual void do_foo() + { + cout << "composite base" << "\n"; + } + + virtual Composite* do_clone() const + { + return new Composite( *this ); + } +}; + +// +// make 'Composite' clonable; note that we do not need to overload +// the function in the 'boost' namespace. +// +Composite* new_clone( const Composite& c ) +{ + return c.clone(); +} + + +class ConcreteComposite1 : public Composite +{ + virtual void do_foo() + { + cout << "composite 1" << "\n"; + } + + virtual Composite* do_clone() const + { + return new ConcreteComposite1(); + } +}; + + +class ConcreteComposite2 : public Composite +{ + virtual void do_foo() + { + cout << "composite 2" << "\n"; + } + + virtual Composite* do_clone() const + { + return new ConcreteComposite2(); + } +}; + +void test_incomplete() +{ + Composite c; + c.add( new ConcreteComposite1 ); + c.add( new ConcreteComposite2 ); + BOOST_CHECK_EQUAL( c.size(), 3u ); + c.add( new_clone( c ) ); // add c to itself + BOOST_CHECK_EQUAL( c.size(), 6u ); + c.add( c ); // add c to itself + BOOST_CHECK_EQUAL( c.size(), 12u ); + c.foo(); +} + +using namespace boost; + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_incomplete ) ); + + return test; +} + +// +// todo: remake example with shared_ptr +// + diff --git a/src/boost/libs/ptr_container/test/indirect_fun.cpp b/src/boost/libs/ptr_container/test/indirect_fun.cpp new file mode 100644 index 00000000..85b72489 --- /dev/null +++ b/src/boost/libs/ptr_container/test/indirect_fun.cpp @@ -0,0 +1,82 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/indirect_fun.hpp> +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/assign/list_inserter.hpp> +#include <boost/test/test_tools.hpp> +#include <algorithm> +#include <functional> +#include <string> + +bool lesser_than( const std::string& l, const std::string& r ) +{ + return l < r; +} + + +void test_fun() +{ + using namespace boost; + ptr_vector<std::string> vec; + + indirect_fun< std::less<std::string> > fun; + + std::string s1("bar"); + std::string* ptr1 = &s1; + std::string s2("foo"); + std::string* ptr2 = &s2; + BOOST_CHECK( fun( ptr1, ptr2 ) == true ); + + void* vptr1 = ptr1; + void* vptr2 = ptr2; + + void_ptr_indirect_fun< std::less<std::string>, std::string> cast_fun; + BOOST_CHECK( cast_fun( vptr1, vptr2 ) == true ); + + assign::push_back( vec )( new std::string("aa") ) + ( new std::string("bb") ) + ( new std::string("dd") ) + ( new std::string("cc") ) + ( new std::string("a") ); + + std::sort( vec.begin().base(), vec.end().base(), cast_fun ); + BOOST_CHECK( vec[0] == "a" ); + BOOST_CHECK( vec[4] == "dd" ); + + std::sort( vec.begin().base(), vec.end().base(), + make_void_ptr_indirect_fun<std::string>( &lesser_than ) ); + BOOST_CHECK( vec[1] == "aa" ); + BOOST_CHECK( vec[2] == "bb" ); + + int i1 = 2; + void *iptr1 = &i1; + int i2 = 3; + void* iptr2 = &i2; + + void_ptr_indirect_fun<std::less<int>, int> int_cast_fun; + BOOST_CHECK( int_cast_fun(iptr1,iptr2) ); + +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_fun ) ); + + return test; +} + + diff --git a/src/boost/libs/ptr_container/test/issue_23.cpp b/src/boost/libs/ptr_container/test/issue_23.cpp new file mode 100644 index 00000000..66e8b817 --- /dev/null +++ b/src/boost/libs/ptr_container/test/issue_23.cpp @@ -0,0 +1,18 @@ +// Use, modification and distribution is subject to the +// Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include <boost/ptr_container/ptr_vector.hpp> + +template<class T> struct Foo +{ + static void test(boost::ptr_vector<Foo<T> >& /*t*/) + { + } +}; + +int main() +{ + boost::ptr_vector<Foo<double> > ptr; + return 0; +} diff --git a/src/boost/libs/ptr_container/test/iterator_test.cpp b/src/boost/libs/ptr_container/test/iterator_test.cpp new file mode 100644 index 00000000..6df97496 --- /dev/null +++ b/src/boost/libs/ptr_container/test/iterator_test.cpp @@ -0,0 +1,78 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/ptr_container/ptr_map.hpp> +#include <boost/test/test_tools.hpp> + +void test_iterator() +{ + using namespace boost; + ptr_vector<int> vec; + vec.push_back( new int(0) ); + ptr_vector<int>::iterator mutable_i = vec.begin(); + ptr_vector<int>::const_iterator const_i = vec.begin(); + + BOOST_CHECK( mutable_i == const_i ); + BOOST_CHECK( ! (mutable_i != const_i ) ); + BOOST_CHECK( const_i == mutable_i ); + BOOST_CHECK( ! ( const_i != mutable_i ) ); + + BOOST_CHECK( !( mutable_i < const_i ) ); + BOOST_CHECK( mutable_i <= const_i ); + BOOST_CHECK( ! ( mutable_i > const_i ) ); + BOOST_CHECK( mutable_i >= const_i ); + BOOST_CHECK( !( const_i < mutable_i ) ); + BOOST_CHECK( const_i <= mutable_i ); + BOOST_CHECK( ! ( const_i > mutable_i ) ); + BOOST_CHECK( const_i >= mutable_i ); + + BOOST_CHECK( const_i - mutable_i == 0 ); + BOOST_CHECK( mutable_i - const_i == 0 ); + + const ptr_vector<int>& rvec = vec; + const_i = rvec.begin(); + + ptr_map<int,int> map; + int i = 0; + map.insert( i, new int(0) ); + ptr_map<int,int>::iterator map_mutable_i = map.begin(); + ptr_map<int,int>::const_iterator map_const_i = map.begin(); + +#if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006)) + // This only works for library implementations which conform to the + // proposed resolution of the C++ Standard Library DR#179. See + // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179. + BOOST_CHECK( map_mutable_i == map_const_i ); + BOOST_CHECK( ! ( map_mutable_i != map_const_i ) ); + BOOST_CHECK( map_const_i == map_mutable_i ); + BOOST_CHECK( ! ( map_const_i != map_mutable_i ) ); +#endif + + const ptr_map<int,int>& rmap = map; + map_const_i = rmap.begin(); +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_iterator ) ); + + return test; +} + + + + diff --git a/src/boost/libs/ptr_container/test/no_exceptions.cpp b/src/boost/libs/ptr_container/test/no_exceptions.cpp new file mode 100644 index 00000000..d7cfa43d --- /dev/null +++ b/src/boost/libs/ptr_container/test/no_exceptions.cpp @@ -0,0 +1,21 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2006. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#define BOOST_PTR_CONTAINER_NO_EXCEPTIONS 1 + +#include "ptr_vector.cpp" + + + + + + + diff --git a/src/boost/libs/ptr_container/test/pointainer_speed.cpp b/src/boost/libs/ptr_container/test/pointainer_speed.cpp new file mode 100644 index 00000000..716a5a0c --- /dev/null +++ b/src/boost/libs/ptr_container/test/pointainer_speed.cpp @@ -0,0 +1,205 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/progress.hpp> + + +using namespace boost; +using namespace std; + + +typedef shared_ptr<Base> PolyPtr; + +struct PolyPtrOps +{ + void operator()( const PolyPtr& a ) + { a->foo(); } +}; + +struct less_than +{ + bool operator()( const PolyPtr& l, const PolyPtr& r ) const + { + return *l < *r; + } + + bool operator()( const Base* l, const Base* r ) const + { + return *l < *r; + } +}; + +struct greater_than +{ + bool operator()( const PolyPtr& l, const PolyPtr& r ) const + { + return *l > *r; + } + + bool operator()( const Base* l, const Base* r ) const + { + return *l > *r; + } +}; + +struct data_less_than +{ + bool operator()( const PolyPtr& l, const PolyPtr& r ) const + { + return l->data_less_than(*r); + } + + bool operator()( const Base* l, const Base* r ) const + { + return l->data_less_than(*r); + } +}; + +struct data_less_than2 +{ + bool operator()( const PolyPtr& l, const PolyPtr& r ) const + { + return l->data_less_than2(*r); + } + + bool operator()( const Base* l, const Base* r ) const + { + return l->data_less_than2(*r); + } +}; + + +void test_speed() +{ + enum { size = 50000 }; + vector<PolyPtr> svec; + ptr_vector<Base> pvec; + + { + progress_timer timer; + for( int i = 0; i < size; ++i ) + svec.push_back( PolyPtr( new Derived ) ); + cout << "\n shared_ptr call new: "; + } + + { + progress_timer timer; + for( int i = 0; i < size; ++i ) + pvec.push_back( new Derived ); + cout << "\n smart container call new: "; + } + + { + progress_timer timer; + for_each( svec.begin(), svec.end(), PolyPtrOps() ); + cout << "\n shared_ptr call foo(): "; + } + + { + progress_timer timer; + for_each( pvec.begin(), pvec.end(), mem_fun_ref( &Base::foo ) ); + cout << "\n smart container call foo(): "; + } + + { + progress_timer timer; + sort( svec.begin(), svec.end(), less_than() ); + cout << "\n shared_ptr call sort(): "; + } + + { + progress_timer timer; + sort( pvec.ptr_begin(), pvec.ptr_end(), less_than() ); + cout << "\n smart container call sort(): "; + } + + { + progress_timer timer; + sort( svec.begin(), svec.end(), greater_than() ); + cout << "\n shared_ptr call sort() #2: "; + } + + { + progress_timer timer; + sort( pvec.ptr_begin(), pvec.ptr_end(), greater_than() ); + cout << "\n smart container call sort() #2: "; + } + + { + progress_timer timer; + sort( svec.begin(), svec.end(), data_less_than() ); + cout << "\n shared_ptr call sort() #3: "; + } + + { + progress_timer timer; + sort( pvec.ptr_begin(), pvec.ptr_end(), data_less_than() ); + cout << "\n smart container call sort() #3: "; + } + + { + progress_timer timer; + sort( svec.begin(), svec.end(), data_less_than2() ); + cout << "\n shared_ptr call sort() #4: "; + } + + { + progress_timer timer; + sort( pvec.ptr_begin(), pvec.ptr_end(), data_less_than2() ); + cout << "\n smart container call sort() #4: "; + } + + vector<Base*> copy1; + for( ptr_vector<Base>::ptr_iterator i = pvec.ptr_begin(); i != pvec.ptr_end(); ++ i ) + copy1.push_back( *i ); + + sort( pvec.ptr_begin(), pvec.ptr_end() ); + + + vector<Base*> copy2; + for( ptr_vector<Base>::ptr_iterator i = pvec.ptr_begin(); i != pvec.ptr_end(); ++ i ) + copy2.push_back( *i ); + + + for( unsigned int i = 0; i < copy1.size(); ++i ) + { + bool found = false; + for( int j = 0; j < copy1.size(); ++ j ) + if( copy1[i] == copy2[j] ) + found = true; + + if( !found ) + cout << copy1[i] << endl; + } + + BOOST_REQUIRE( pvec.size() == size ); + cout << endl; +} + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_speed ) ); + + return test; +} + + + + diff --git a/src/boost/libs/ptr_container/test/ptr_array.cpp b/src/boost/libs/ptr_container/test/ptr_array.cpp new file mode 100644 index 00000000..9c5c28e2 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_array.cpp @@ -0,0 +1,197 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "test_data.hpp" +#include <boost/ptr_container/ptr_array.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/utility.hpp> +#include <boost/array.hpp> +#include <algorithm> +#include <iostream> +#include <cstddef> +#include <string> + +using namespace std; +using namespace boost; + +template< class Node, size_t N > +class n_ary_tree : boost::noncopyable +{ + typedef n_ary_tree<Node,N> this_type; + typedef ptr_array<this_type,N> tree_t; + + tree_t tree; + Node data; + +public: + n_ary_tree() { } + n_ary_tree( const Node& r ) : data(r) { } + +public: // modifers + void set_data( const Node& r ) { data = r; } + template< size_t idx > + void set_child( this_type* r ) { tree. BOOST_NESTED_TEMPLATE replace<idx>(r); } + +public: // accessors + void print( std::ostream&, std::string indent = " " ); + template< size_t idx > + this_type& child() { return tree. BOOST_NESTED_TEMPLATE at<idx>(); } + template< size_t idx > + const this_type& child() const { return tree. BOOST_NESTED_TEMPLATE at<idx>(); } + +}; + + + +template< class Node, size_t N > +void n_ary_tree<Node,N>::print( std::ostream& out, std::string indent ) +{ + out << indent << data << "\n"; + indent += " "; + for( size_t i = 0; i != N; ++i ) + if( !tree.is_null(i) ) + tree[i].print( out, indent + " " ); +} + + +template< class C, class B, class T > +void test_array_interface(); + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_array() +{ + typedef n_ary_tree<std::string,2> binary_tree; + binary_tree tree; + tree.set_data( "root" ); + tree.set_child<0>( new binary_tree( "left subtree" ) ); + tree.set_child<1>( new binary_tree( "right subtree" ) ); + binary_tree& left = tree.child<0>(); + left.set_child<0>( new binary_tree( "left left subtree" ) ); + left.set_child<1>( new binary_tree( "left right subtree" ) ); + binary_tree& right = tree.child<1>(); + right.set_child<0>( new binary_tree( "right left subtree" ) ); + right.set_child<1>( new binary_tree( "right right subtree" ) ); + + tree.print( std::cout ); + + test_array_interface<ptr_array<Base,10>,Base,Derived_class>(); + test_array_interface<ptr_array<nullable<Base>,10>,Base,Derived_class>(); + test_array_interface<ptr_array<Value,10>,Value,Value>(); + test_array_interface<ptr_array<nullable<Value>,10>,Value,Value>(); + + ptr_array<int,10> vec; + BOOST_CHECK_THROW( vec.at(10), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation ); +#ifndef BOOST_NO_AUTO_PTR + BOOST_CHECK_THROW( (vec.replace(10u, std::auto_ptr<int>(new int(0)))), bad_ptr_container_operation ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_CHECK_THROW( (vec.replace(10u, std::unique_ptr<int>(new int(0)))), bad_ptr_container_operation ); +#endif + BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation ); + + ptr_array<Derived_class,2> derived; + derived.replace( 0, new Derived_class ); + derived.replace( 1, new Derived_class ); + ptr_array<Base,2> base( derived ); + + BOOST_TEST_MESSAGE( "finished derived to base test" ); + + base = derived; + ptr_array<Base,2> base2( base ); + base2 = base; + base = base; +} + +template< class C, class B, class T > +void test_array_interface() +{ + C c; + c.replace( 0, new T ); + c.replace( 1, new B ); + c.replace( 9, new T ); +#ifndef BOOST_NO_AUTO_PTR + c.replace( 0, std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.replace( 0, std::unique_ptr<T>( new T ) ); +#endif + const C c2( c.clone() ); + + BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); + hide_warning(i); + BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); + hide_warning(ci); + BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); + hide_warning(i2); + BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); + hide_warning(ci2); + BOOST_DEDUCED_TYPENAME C::reverse_iterator ri = c.rbegin(); + hide_warning(ri); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cri = c2.rbegin(); + hide_warning(cri); + BOOST_DEDUCED_TYPENAME C::reverse_iterator rv2 = c.rend(); + hide_warning(rv2); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cvr2 = c2.rend(); + hide_warning(cvr2); + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + BOOST_CHECK_EQUAL( c.empty(), false ); + BOOST_CHECK_EQUAL( c.size(), c.max_size() ); + + BOOST_TEST_MESSAGE( "finished capacity test" ); + + BOOST_CHECK_EQUAL( c.is_null(0), false ); + BOOST_CHECK_EQUAL( c.is_null(1), false ); + BOOST_CHECK_EQUAL( c.is_null(2), true ); + + c.front(); + c.back(); + c2.front(); + c2.back(); + C c3; + c.swap( c3 ); + C c4; + swap(c4,c3); + c3.swap(c4); + + BOOST_CHECK_EQUAL( c.is_null(0), true ); + BOOST_CHECK_EQUAL( c3.is_null(0), false ); + + c.replace( 5, new T ); + BOOST_CHECK_EQUAL( c.is_null(5), false ); + c = c3.release(); + for( size_t i = 0; i < c3.size(); ++i ) + BOOST_CHECK_EQUAL( c3.is_null(i), true ); + + BOOST_TEST_MESSAGE( "finished element access test" ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_array ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_circular_buffer.cpp b/src/boost/libs/ptr_container/test/ptr_circular_buffer.cpp new file mode 100644 index 00000000..95a532a9 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_circular_buffer.cpp @@ -0,0 +1,198 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "sequence_test_data.hpp" +#include <boost/ptr_container/ptr_circular_buffer.hpp> +#include <boost/ptr_container/ptr_list.hpp> +#include <boost/assign/list_inserter.hpp> + +template<class T> +struct set_capacity< ptr_circular_buffer<T> > +{ + void operator()( ptr_circular_buffer<T>& c ) const + { + c.set_capacity( 100u ); + } +}; + +void test_ptr_circular_buffer() +{ + reversible_container_test< ptr_circular_buffer<Base>, Base, Derived_class >(); + reversible_container_test< ptr_circular_buffer<Value>, Value, Value >(); + +#ifdef BOOST_NO_SFINAE +#else + reversible_container_test< ptr_circular_buffer< nullable<Base> >, Base, Derived_class >(); + reversible_container_test< ptr_circular_buffer< nullable<Value> >, Value, Value >(); +#endif + + container_assignment_test< ptr_circular_buffer<Base>, ptr_circular_buffer<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_circular_buffer< nullable<Base> >, + ptr_circular_buffer< nullable<Derived_class> >, + Derived_class>(); + container_assignment_test< ptr_circular_buffer< nullable<Base> >, + ptr_circular_buffer<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_circular_buffer<Base>, + ptr_circular_buffer< nullable<Derived_class> >, + Derived_class>(); + + test_transfer< ptr_circular_buffer<Derived_class>, ptr_circular_buffer<Base>, Derived_class>(); + test_transfer< ptr_circular_buffer<Derived_class>, ptr_list<Base>, Derived_class>(); + + random_access_algorithms_test< ptr_circular_buffer<int> >(); + + + BOOST_TEST_MESSAGE( "starting ptr_circular_buffer test" ); + ptr_circular_buffer<int> vec( 100u ); + BOOST_CHECK( vec.capacity() >= 100u ); + +#ifdef BOOST_PTR_CONTAINER_NO_EXCEPTIONS +#else + + BOOST_CHECK_THROW( vec.push_back(0), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.insert( vec.begin(), 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( vec.at( 42 ), bad_ptr_container_operation ); + vec.push_back( new int(0) ); + BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.replace(vec.begin(), 0 )), bad_ptr_container_operation ); + +#endif + + vec.clear(); + assign::push_back( vec )( new int(2) ) + ( new int(4) ) + ( new int(6) ) + ( new int(8) ); + ptr_circular_buffer<int> vec2( 100u ); + assign::push_back( vec2 ) + ( new int(1) ) + ( new int(3) ) + ( new int(5) ) + ( new int(7) ); + BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); + BOOST_CHECK( vec > vec2 ); + BOOST_CHECK( vec != vec2 ); + BOOST_CHECK( !(vec == vec2) ); + BOOST_CHECK( vec2 < vec ); + BOOST_CHECK( vec2 <= vec ); + BOOST_CHECK( vec >= vec2 ); + + BOOST_TEST_MESSAGE( "push_front test" ); + assign::push_front( vec2 ) + ( new int(2) ) + ( new int(4) ) + ( new int(6) ) + ( new int(8) ); + BOOST_CHECK_EQUAL( vec2.size(), 8u ); + BOOST_CHECK_EQUAL( vec2[0], 8 ); + BOOST_CHECK_EQUAL( vec2.front(), 8 ); + BOOST_CHECK_EQUAL( vec2.back(), 7 ); + + //vec2.linearize(); + vec2.rset_capacity( vec2.size() - 2u ); + vec2.rresize( 0 ); + //vec2.reverse(); + + BOOST_TEST_MESSAGE( "when full test" ); + + ptr_circular_buffer<int> vec3; + BOOST_CHECK_EQUAL( vec3.capacity(), 0u ); + vec3.set_capacity( 2u ); + BOOST_CHECK_EQUAL( vec3.capacity(), 2u ); + + vec3.push_back( new int(1) ); + vec3.push_back( new int(2) ); + BOOST_CHECK_EQUAL( vec3.size(), 2u ); + BOOST_CHECK( vec3.full() ); + + vec3.push_back( new int(3) ); + BOOST_CHECK_EQUAL( vec3.front(), 2 ); + BOOST_CHECK_EQUAL( vec3.back(), 3 ); + + vec3.push_front( new int(4) ); + BOOST_CHECK_EQUAL( vec3.size(), 2u ); + BOOST_CHECK_EQUAL( vec3.front(), 4 ); + BOOST_CHECK_EQUAL( vec3.back(), 2 ); + + vec3.insert( vec3.end(), new int(5) ); + BOOST_CHECK_EQUAL( vec3.front(), 2 ); + BOOST_CHECK_EQUAL( vec3.back(), 5 ); + + vec3.rinsert( vec3.begin(), new int(6) ); + BOOST_CHECK_EQUAL( vec3.front(), 6 ); + BOOST_CHECK_EQUAL( vec3.back(), 2 ); + + BOOST_TEST_MESSAGE( "transfer test" ); + ptr_circular_buffer<int> vec4(2u); + vec4.transfer( vec4.end(), vec3 ); + BOOST_CHECK_EQUAL( vec4.size(), 2u ); + BOOST_CHECK_EQUAL( vec3.size(), 0u ); + vec3.set_capacity(1u); + vec3.transfer( vec3.end(), vec4 ); + BOOST_CHECK_EQUAL( vec4.size(), 0u ); + BOOST_CHECK_EQUAL( vec3.size(), 1u ); + BOOST_CHECK_EQUAL( vec3.front(), 2 ); + + BOOST_TEST_MESSAGE( "rerase test" ); + vec.rerase( vec.begin() ); + vec.rerase( boost::make_iterator_range( vec ) ); + + BOOST_TEST_MESSAGE( "array test" ); + const int data_size = 10; + int** array = new int*[data_size]; + for( int i = 0; i != data_size; ++i ) + array[i] = new int(i); + + vec.transfer( vec.begin(), array, data_size ); + int** array2 = vec.c_array(); + BOOST_CHECK( array2 != array ); + + ptr_circular_buffer<int>::array_range array_range = vec.array_one(); + array_range = vec.array_two(); + ptr_circular_buffer<int>::const_array_range const_array_range = array_range; + const_array_range = const_cast< const ptr_circular_buffer<int>& >(vec).array_one(); + const_array_range = const_cast< const ptr_circular_buffer<int>& >(vec).array_two(); + + BOOST_TEST_MESSAGE( "finishing ptr_circular_buffer test" ); + +} + + + +void test_circular_buffer() +{ + boost::circular_buffer<void*> b(25u); + BOOST_CHECK_EQUAL( b.capacity(), 25u ); + b.push_back( 0 ); + BOOST_CHECK_EQUAL( b.size(), 1u ); + boost::circular_buffer<void*> b2( b.begin(), b.end() ); + BOOST_CHECK_EQUAL( b2.size(), b.size() ); +} + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_circular_buffer ) ); + test->add( BOOST_TEST_CASE( &test_ptr_circular_buffer ) ); + + return test; +} + + + + diff --git a/src/boost/libs/ptr_container/test/ptr_container_adapter.cpp b/src/boost/libs/ptr_container/test/ptr_container_adapter.cpp new file mode 100644 index 00000000..33664298 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_container_adapter.cpp @@ -0,0 +1,68 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "sequence_test_data.hpp" +#include <boost/ptr_container/ptr_container_adapter.hpp> +#include <list> + + +template< class T > +class my_list : public std::list<T> +{ + typedef BOOST_DEDUCED_TYPENAME std::list<T> base_class; + +public: +/* + my_list( const base_class::allocator_type& alloc = base_class::allocator_type() ) + : base_class( alloc ) {} + + my_list( size_type n, const T& x, const base_class::allocator_type& alloc = base_class::allocator_type() ) + : base_class( n, x, alloc ) {} + + template< class InputIterator > + my_list( InputIterator first, InputIterator last ) : base_class( first, last ) {} +*/ +}; + +void test_container_adapter() +{ + typedef ptr_container_adapter< my_list<Base*> > base_ptr_list; + typedef ptr_container_adapter< my_list<Value*> > value_ptr_list; + + typedef_test< base_ptr_list, Derived_class >(); + typedef_test< value_ptr_list, Value >(); + +// reversible_container_test< base_ptr_list, Base, Derived_class >(); +// reversible_container_test< value_ptr_list, Value, Value >(); + + base_ptr_list l; + l.push_back( new Derived_class ); + l.push_back( new Derived_class ); + +// algo_test< ptr_list<Value>, Value >(); +// algo_test_polymorphic< ptr_list<Base>, Derived_class >(); +} + +#include <boost/test/included/unit_test.hpp> + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_container_adapter ) ); + + return test; +} + + + diff --git a/src/boost/libs/ptr_container/test/ptr_deque.cpp b/src/boost/libs/ptr_container/test/ptr_deque.cpp new file mode 100644 index 00000000..5b366aee --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_deque.cpp @@ -0,0 +1,73 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "sequence_test_data.hpp" +#include <boost/ptr_container/ptr_deque.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_ptr_deque() +{ + reversible_container_test< ptr_deque<Base>, Base, Derived_class >(); + reversible_container_test< ptr_deque<Value>, Value, Value >(); + reversible_container_test< ptr_deque< nullable<Base> >, Base, Derived_class >(); + reversible_container_test< ptr_deque< nullable<Value> >, Value, Value >(); + + container_assignment_test< ptr_deque<Base>, ptr_deque<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_deque< nullable<Base> >, + ptr_deque< nullable<Derived_class> >, + Derived_class>(); + container_assignment_test< ptr_deque< nullable<Base> >, + ptr_deque<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_deque<Base>, + ptr_deque< nullable<Derived_class> >, + Derived_class>(); + + test_transfer< ptr_deque<Derived_class>, ptr_deque<Base>, Derived_class>(); + + random_access_algorithms_test< ptr_deque<int> >(); + ptr_deque<int> di; + di.push_front( new int(0) ); + std::size_t size = 1u; + BOOST_CHECK_EQUAL( di.size(), size ); +#ifndef BOOST_NO_AUTO_PTR + di.push_front( std::auto_ptr<int>( new int(1) ) ); + ++size; +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + di.push_front( std::unique_ptr<int>( new int(2) ) ); + ++size; +#endif + BOOST_CHECK_EQUAL( di.size(), size ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_ptr_deque ) ); + + return test; +} + diff --git a/src/boost/libs/ptr_container/test/ptr_inserter.cpp b/src/boost/libs/ptr_container/test/ptr_inserter.cpp new file mode 100644 index 00000000..464d83c3 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_inserter.cpp @@ -0,0 +1,93 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2008. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_inserter.hpp> +#include <boost/ptr_container/indirect_fun.hpp> +#include <boost/ptr_container/ptr_deque.hpp> +#include <boost/ptr_container/ptr_list.hpp> +#include <boost/assign/list_inserter.hpp> +#include <boost/iterator/transform_iterator.hpp> +#include <boost/test/test_tools.hpp> +#include <algorithm> +#include <functional> +#include <string> + +template< class T > +struct caster_to +{ + typedef T result_type; + + T operator()( void* obj ) const + { + return static_cast<T>( obj ); + } +}; + +template< class PtrSequence > +void test_ptr_inserter_helper() +{ + using namespace boost; + PtrSequence seq; + const int size = 1000; + for( int i = 0; i != size; ++i ) + seq.push_back( i % 3 == 0 ? 0 : new int(i) ); + + PtrSequence seq2; + // + // @remark: we call .base() to avoid null pointer indirection. + // The clone_inserter will handle the nulls correctly. + // + std::copy( boost::make_transform_iterator( seq.begin().base(), caster_to<int*>() ), + boost::make_transform_iterator( seq.end().base(), caster_to<int*>() ), + ptr_container::ptr_back_inserter( seq2 ) ); + + std::copy( boost::make_transform_iterator( seq.begin().base(), caster_to<int*>() ), + boost::make_transform_iterator( seq.end().base(), caster_to<int*>() ), + ptr_container::ptr_front_inserter( seq2 ) ); + BOOST_CHECK_EQUAL( seq.size()*2, seq2.size() ); + + PtrSequence seq3; + for( int i = 0; i != size; ++i ) + seq3.push_back( new int(i%3) ); + + // + // @remark: since there are no nulls in this container, it + // is easier to handle. + // + std::copy( seq3.begin(), seq3.end(), + ptr_container::ptr_inserter( seq, seq.end() ) ); + BOOST_CHECK_EQUAL( seq.size(), seq2.size() ); +} + + +void test_ptr_inserter() +{ + test_ptr_inserter_helper< boost::ptr_list< boost::nullable<int> > >(); + test_ptr_inserter_helper< boost::ptr_deque< boost::nullable<int> > >(); + + +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_ptr_inserter ) ); + + return test; +} + + diff --git a/src/boost/libs/ptr_container/test/ptr_list.cpp b/src/boost/libs/ptr_container/test/ptr_list.cpp new file mode 100644 index 00000000..46548bce --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_list.cpp @@ -0,0 +1,87 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#define PTR_LIST_TEST 1 +#define PTR_CONTAINER_DEBUG 0 + +#include <boost/test/unit_test.hpp> +#include "sequence_test_data.hpp" +#include <boost/ptr_container/ptr_list.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_list() +{ + + reversible_container_test< ptr_list<Base>, Base, Derived_class >(); + reversible_container_test< ptr_list<Value>, Value, Value >(); + reversible_container_test< ptr_list< nullable<Base> >, Base, Derived_class >(); + reversible_container_test< ptr_list< nullable<Value> >, Value, Value >(); + + container_assignment_test< ptr_list<Base>, ptr_list<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_list< nullable<Base> >, + ptr_list< nullable<Derived_class> >, + Derived_class>(); + container_assignment_test< ptr_list< nullable<Base> >, + ptr_list<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_list<Base>, + ptr_list< nullable<Derived_class> >, + Derived_class>(); + + test_transfer< ptr_list<Derived_class>, ptr_list<Base>, Derived_class>(); + + random_access_algorithms_test< ptr_list<int> >(); + ptr_list<int> list; + list.push_back( new int(0) ); + list.push_back( new int(2) ); + list.push_back( new int(1) ); + list.push_front( new int(3) ); +#ifndef BOOST_NO_AUTO_PTR + list.push_front( std::auto_ptr<int>( new int(42) ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + list.push_front( std::unique_ptr<int>( new int(43) ) ); +#endif + list.reverse(); + ptr_list<int>::const_iterator it = list.begin(); + BOOST_CHECK(1 == *it++); + BOOST_CHECK(2 == *it++); + BOOST_CHECK(0 == *it++); + BOOST_CHECK(3 == *it++); +#ifndef BOOST_NO_AUTO_PTR + BOOST_CHECK(42 == *it++); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_CHECK(43 == *it++); +#endif + BOOST_CHECK(list.end() == it); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_list ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_map.cpp b/src/boost/libs/ptr_container/test/ptr_map.cpp new file mode 100644 index 00000000..580015fb --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_map.cpp @@ -0,0 +1,454 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/test/unit_test.hpp> +#include <boost/ptr_container/exception.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/range/sub_range.hpp> +#include <boost/cast.hpp> +#include <cstdlib> +#include <iostream> +#include <memory> +#include <string> + +// +// abstract base class definition +// +struct abstract_base +{ + virtual ~abstract_base() {} + virtual void foo() = 0; + virtual abstract_base* clone() const = 0; +}; + +struct implementation : abstract_base +{ + implementation() + { } + + implementation( const implementation& ) + { } + + implementation( int, std::string, int, std::string ) + { } + + virtual void foo() {} + virtual abstract_base* clone() const + { + return new implementation( *this ); + } +}; + +inline std::ostream& operator<<( std::ostream& out, const abstract_base& r ) +{ + return out; +} + +inline abstract_base* new_clone( const abstract_base& r ) +{ + return r.clone(); +} + +// +// ptr_map test +// + +template< typename C, typename B, typename T > +void ptr_map_test(); + +template< class Key > +Key get_next_key( const Key& k ); + +template<> +int get_next_key<int>( const int& ) +{ + return rand(); +} + +template<> +std::string get_next_key<std::string>( const std::string& ) +{ + return boost::lexical_cast<std::string>( rand() ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +template< typename C, typename B, typename T > +void ptr_map_test() +{ + using namespace boost; + + BOOST_TEST_MESSAGE( "starting associative container test" ); + enum { max_cnt = 10, size = 100 }; + C c; + BOOST_CHECK( c.size() == 0 ); + + const C c2( c.begin(), c.end() ); + BOOST_CHECK( c.size() == c2.size() ); + + C c3; + + BOOST_TEST_MESSAGE( "finished construction test" ); + + BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); + BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); + BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); + BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); + hide_warning(i2); + BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); + hide_warning(ci2); + BOOST_DEDUCED_TYPENAME C::reverse_iterator ri = c.rbegin(); + hide_warning(ri); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cri = c2.rbegin(); + hide_warning(cri); + BOOST_DEDUCED_TYPENAME C::reverse_iterator rv2 = c.rend(); + hide_warning(rv2); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cvr2 = c2.rend(); + hide_warning(cvr2); + + BOOST_DEDUCED_TYPENAME C::key_type a_key; + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); + BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); + hide_warning(s2); + BOOST_CHECK_EQUAL( c.size(), s ); + bool b = c.empty(); + hide_warning(b); + BOOST_TEST_MESSAGE( "finished accessors test" ); + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + c3.insert( c.begin(), c.end() ); + c.insert( c3 ); + c.erase( c.begin() ); + BOOST_CHECK( c3.end() == c3.erase( boost::make_iterator_range(c3) ) ); + c3.erase( a_key ); + + BOOST_CHECK( c3.empty() ); + c.swap( c3 ); + swap(c,c3); + swap(c3,c); + BOOST_CHECK( !c3.empty() ); + c3.clear(); + BOOST_CHECK( c3.empty() ); + BOOST_TEST_MESSAGE( "finished modifiers test" ); + + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + a_key = get_next_key( a_key ); +#ifndef BOOST_NO_AUTO_PTR + c.insert( a_key, std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( a_key, std::unique_ptr<T>( new T ) ); +#endif + typename C::auto_type ptr2 = c.release( c.begin() ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<C> ap = c.release(); +#else + std::unique_ptr<C> up = c.release(); +#endif + c = c2.clone(); + BOOST_TEST_MESSAGE( "finished release/clone test" ); + + + a_key = get_next_key( a_key ); + c3.insert( a_key, new T ); + a_key = get_next_key( a_key ); + c3.insert( a_key, new T ); + + c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); + c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 ); + BOOST_CHECK( c3.empty() ); + BOOST_CHECK( !c.empty() ); + c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); + BOOST_CHECK( !c3.empty() ); + BOOST_CHECK( c.empty() ); +#ifdef BOOST_NO_SFINAE +#else + c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range(c3), c3 ); + BOOST_CHECK( !c.empty() ); + BOOST_CHECK( c3.empty() ); + c3. BOOST_NESTED_TEMPLATE transfer<C>(c); +#endif + BOOST_TEST_MESSAGE( "finished transfer test" ); + + BOOST_CHECK( !c3.empty() ); + c3.replace( c3.begin(), new T ); +#ifndef BOOST_NO_AUTO_PTR + c3.replace( c3.begin(), std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c3.replace( c3.begin(), std::unique_ptr<T>( new T ) ); +#endif + BOOST_TEST_MESSAGE( "finished set/map interface test" ); + + // @todo: make macro with algorithms so that the right erase() is called. + // c.unique(); + // c.unique( std::not_equal_to<T>() ); + // c.remove( T() ); + // c.remove_if( std::binder1st< std::equal_to<T> >( T() ) ); + + sub_range<C> sub; + sub_range<const C> csub; + + i = c.find( get_next_key( a_key ) ); + ci = c2.find( get_next_key( a_key ) ); + BOOST_CHECK_EQUAL(0, c2.count( get_next_key( a_key ) )); + i = c.lower_bound( get_next_key( a_key ) ); + ci = c2.lower_bound( get_next_key( a_key ) ); + i = c.upper_bound( get_next_key( a_key ) ); + ci = c2.upper_bound( get_next_key( a_key ) ); + sub = c.equal_range( get_next_key( a_key ) ); + csub = c2.equal_range( get_next_key( a_key ) ); + + try + { + c.at( get_next_key( a_key ) ); + } + catch( const bad_ptr_container_operation& ) + { } + + try + { + c2.at( get_next_key( a_key ) ); + } + catch( const bad_ptr_container_operation& ) + { } + + BOOST_TEST_MESSAGE( "finished algorithms interface test" ); + + typename C::iterator it = c.begin(), e = c.end(); + for( ; it != e; ++it ) + { + std::cout << "\n mapped value = " << *it->second << " key = " << it->first; + //std::cout << "\n mapped value = " << it.value() << " key = " << it.key(); + } + + typename C::reverse_iterator rit = c.rbegin(), re = c.rend(); + for( ; rit != re; ++rit ) + { + std::cout << "\n mapped value = " << *rit->second << " key = " << rit->first; + //std::cout << "\n mapped value = " << rit.value() << " key = " << rit.key(); + //std::cout << "\n mapped value (base) = " + // << rit.base().value() << " key = " << rit.base().key(); + } + + typename C::const_reverse_iterator crit = c2.rbegin(), cre = c2.rend(); + for( ; crit != cre; ++crit ) + { + std::cout << "\n mapped value = " << *(*crit).second << " key = " << (*crit).first; + //std::cout << "\n mapped value = " << crit.value() << " key = " << crit.key(); + //std::cout << "\n mapped value (base) = " + // << crit.base().value() << " key = " << crit.base().key(); + } + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + c.erase( a_key ); + c.erase( a_key ); + +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + + + +template< class CDerived, class CBase, class T > +void test_transfer() +{ + CDerived from; + CBase to; + + int key = get_next_key( key ); + from.insert( key, new T ); + key = get_next_key( key ); + from.insert( key, new T ); + transfer_test( from, to ); +} + + + +template< class BaseContainer, class DerivedContainer, class Derived > +void map_container_assignment_test() +{ + DerivedContainer derived; + std::string foo( "foo" ); + std::string bar( "foo" ); + derived.insert( foo, new Derived ); + derived.insert( bar, new Derived ); + + BaseContainer base_container( derived ); + BOOST_CHECK_EQUAL( derived.size(), base_container.size() ); + base_container.clear(); + base_container = derived; + BOOST_CHECK_EQUAL( derived.size(), base_container.size() ); + + BaseContainer base2( base_container ); + BOOST_CHECK_EQUAL( base2.size(), base_container.size() ); + base2 = base_container; + BOOST_CHECK_EQUAL( base2.size(), base_container.size() ); + base_container = base_container; +} + + + +#include <boost/ptr_container/ptr_map.hpp> + +using namespace std; + +void test_map() +{ + ptr_map_test< ptr_map<int, Base>, Base, Derived_class >(); + ptr_map_test< ptr_map<int, Value>, Value, Value >(); + ptr_map_test< ptr_map<int, nullable<Base> >, Base, Derived_class >(); + ptr_map_test< ptr_map<int, nullable<Value> >, Value, Value >(); + ptr_map_test< ptr_map<int, abstract_base>, abstract_base, implementation >(); + + ptr_map_test< ptr_multimap<int,Base>, Base, Derived_class >(); + ptr_map_test< ptr_multimap<int,Value>, Value, Value >(); + ptr_map_test< ptr_multimap<int, nullable<Base> >, Base, Derived_class >(); + ptr_map_test< ptr_multimap<int, nullable<Value> >, Value, Value >(); + + map_container_assignment_test< ptr_map<std::string,Base>, + ptr_map<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_map<std::string, nullable<Base> >, + ptr_map<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_map<std::string, nullable<Base> >, + ptr_map<std::string, nullable<Derived_class> >, + Derived_class>(); + map_container_assignment_test< ptr_multimap<std::string,Base>, + ptr_multimap<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_multimap<std::string, nullable<Base> >, + ptr_multimap<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_multimap<std::string, nullable<Base> >, + ptr_multimap<std::string, nullable<Derived_class> >, + Derived_class>(); + + + test_transfer< ptr_map<int,Derived_class>, ptr_map<int,Base>, Derived_class >(); + test_transfer< ptr_multimap<int,Derived_class>, ptr_multimap<int,Base>, Derived_class >(); + + string joe = "joe"; + string brian = "brian"; + string kenny = "kenny"; + + ptr_map<string,int> m; + m.insert( joe, new int( 4 ) ); + m.insert( brian, new int( 6 ) ); + BOOST_CHECK( m[ "foo" ] == 0 ); + m[ "bar" ] += 5; + BOOST_CHECK( m[ "bar" ] == 5 ); + m[ joe ] += 56; + m[ brian ] += 10; + + BOOST_CHECK_THROW( (m.insert(kenny, 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (m.replace(m.begin(), 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (m.at("not there")), bad_ptr_container_operation ); + + for( ptr_map<string,int>::iterator i = m.begin(); + i != m.end(); ++i ) + { + if( is_null(i) ) + BOOST_CHECK( false ); + const string& ref = i->first; + hide_warning(ref); + int& ref2 = *(*i).second; + ref2++; + } + + typedef ptr_map<string,Derived_class> map_type; + map_type m2; + m2.insert( joe, new Derived_class ); + // + // This works fine since 'm2' is not const + // + m2.begin()->second->foo(); + + // + // These all return an implementation-defined proxy + // with two public members: 'first' and 'second' + // + map_type::value_type a_value = *m2.begin(); + a_value.second->foo(); + map_type::reference a_reference = *m2.begin(); + a_reference.second->foo(); + map_type::const_reference a_creference = *const_begin(m2); + hide_warning(a_creference); + + // + // + // These will fail as iterators propagate constness + // + //a_creference.second->foo(); + //a_cpointer->second->foo(); + //const_begin(m2)->second->foo(); + +} + +#include <boost/tuple/tuple.hpp> +#include <boost/iterator/zip_iterator.hpp> +#include <map> +#include <boost/ptr_container/ptr_map.hpp> + +void test_map_iterators() +{ + using boost::zip_iterator; + using boost::tuple; + using boost::make_tuple; + using boost::ptr_map; + using std::map; + + //typedef map<int, int> theMapType; + /* + @remark: the following will not compile + because of the proxy (non-reference) returned by operator*() + of the ptr_map's iterator type. + + typedef boost::ptr_map<int, int> theMapType; + typedef zip_iterator + <tuple<theMapType::iterator, theMapType::iterator> > zipIter; + theMapType map1; + theMapType map2; + zipIter zip(make_tuple(map1.begin(), map2.begin())); + */ +} + + + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_map ) ); + test->add( BOOST_TEST_CASE( &test_map_iterators ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_map_adapter.cpp b/src/boost/libs/ptr_container/test/ptr_map_adapter.cpp new file mode 100644 index 00000000..18822474 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_map_adapter.cpp @@ -0,0 +1,88 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/ptr_map.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/test/unit_test.hpp> +#include <string> + +using namespace std; + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_ptr_map_adapter() +{ + //typedef_test< ptr_map<int, Base>, Derived >(); + //typedef_test< ptr_map<int, Value>, Value >(); + + //associative_container_test< ptr_map<int, Base>, Base, Derived >(); + //associative_container_test< ptr_map<int, Value>, Value, Value >(); + + //typedef_test< ptr_multimap<int, Base>, Derived >(); + //typedef_test< ptr_multimap<int, Value>, Value >(); + + //associative_container_test< ptr_multimap<int, Base>, Base, Derived >(); + //associative_container_test< ptr_multimap<int, Value>, Value, Value >(); + + string joe = "joe"; + string brian = "brian"; + + ptr_map<string,int> m; + m.insert( joe, new int( 4 ) ); +#ifndef BOOST_NO_AUTO_PTR + m.insert( brian, std::auto_ptr<int>( new int( 6 ) ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + m.insert( brian, std::unique_ptr<int>( new int( 6 ) ) ); +#endif + m[ joe ] += 56; + m[ brian ] += 10; + + try + { + m[ "hans" ] = 4; + } + catch( const bad_ptr_container_operation& ) + { } + + ptr_map<string,int> m2; + m2.insert( m2.begin(), *m.begin() ); + BOOST_CHECK( m != m2 ); + BOOST_CHECK( m2 < m ); + m2.insert( m2.begin(), joe, new int(5) ); + BOOST_CHECK( m != m2 ); + BOOST_CHECK( m2 > m ); + + ptr_multimap<string,int> m3; + m3.insert( m3.begin(), *m.begin() ); + BOOST_CHECK( m3.size() == 1u ); + m3.insert( m3.begin(), brian, new int(11 ) ); + BOOST_CHECK( m3.size() == 2u ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_ptr_map_adapter ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_set.cpp b/src/boost/libs/ptr_container/test/ptr_set.cpp new file mode 100644 index 00000000..aaea7972 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_set.cpp @@ -0,0 +1,124 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "associative_test_data.hpp" +#include <boost/ptr_container/ptr_set.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> + +template< class SetDerived, class SetBase, class T > +void test_transfer() +{ + SetBase to; + SetDerived from; + from.insert( new T ); + from.insert( new T ); + transfer_test( from, to ); +} + +template< class BaseContainer, class DerivedContainer, class Derived > +void test_copy() +{ + DerivedContainer derived; + derived.insert( new Derived ); + derived.insert( new Derived ); + + BaseContainer base( derived ); + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + base.clear(); + base = derived; + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + base = base; +} + + + +template< class PtrSet > +void test_erase() +{ + PtrSet s; + typedef typename PtrSet::key_type T; + + T t; + T* t2 = t.clone(); + s.insert ( new T ); + s.insert ( t2 ); + s.insert ( new T ); + BOOST_CHECK_EQUAL( s.size(), 3u ); + BOOST_CHECK_EQUAL( t, *t2 ); + BOOST_CHECK( ! (t < *t2) ); + BOOST_CHECK( ! (*t2 < t) ); + BOOST_CHECK_EQUAL( t, *t2 ); + + unsigned n = s.erase( t ); + BOOST_CHECK( n > 0 ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_set() +{ + srand( 0 ); + ptr_set_test< ptr_set<Base>, Base, Derived_class, true >(); + ptr_set_test< ptr_set<Value>, Value, Value, true >(); + + ptr_set_test< ptr_multiset<Base>, Base, Derived_class, true >(); + ptr_set_test< ptr_multiset<Value>, Value, Value, true >(); + + test_copy< ptr_set<Base>, ptr_set<Derived_class>, + Derived_class>(); + test_copy< ptr_multiset<Base>, ptr_multiset<Derived_class>, + Derived_class>(); + + test_transfer< ptr_set<Derived_class>, ptr_set<Base>, Derived_class>(); + test_transfer< ptr_multiset<Derived_class>, ptr_multiset<Base>, Derived_class>(); + + ptr_set<int> set; + + BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); + set.insert( new int(0) ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<int> ap( new int(1) ); + set.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr<int> up( new int(2) ); + set.insert( std::move( up ) ); +#endif + BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); +#ifndef BOOST_NO_AUTO_PTR + BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr<int>(0) )), bad_ptr_container_operation ); +#endif +#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_NULLPTR) + BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr<int>(nullptr) )), bad_ptr_container_operation ); +#endif + + test_erase< ptr_set<Base> >(); + test_erase< ptr_multiset<Base> >(); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_set ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_unordered_map.cpp b/src/boost/libs/ptr_container/test/ptr_unordered_map.cpp new file mode 100644 index 00000000..924bfa5a --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_unordered_map.cpp @@ -0,0 +1,425 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2008. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/test/unit_test.hpp> +#include <boost/ptr_container/exception.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/range/sub_range.hpp> +#include <boost/cast.hpp> +#include <cstdlib> +#include <iostream> +#include <memory> +#include <string> + +// +// abstract base class definition +// +struct abstract_base +{ + virtual ~abstract_base() {} + virtual void foo() = 0; + virtual abstract_base* clone() const = 0; +}; + +struct implementation : abstract_base +{ + implementation() + { } + + implementation( const implementation& ) + { } + + implementation( int, std::string, int, std::string ) + { } + + virtual void foo() {} + virtual abstract_base* clone() const + { + return new implementation( *this ); + } +}; + +inline std::ostream& operator<<( std::ostream& out, const abstract_base& r ) +{ + return out; +} + +inline abstract_base* new_clone( const abstract_base& r ) +{ + return r.clone(); +} + +inline std::size_t hash_value( const abstract_base& b ) +{ + return boost::hash_value( &b ); +} + +// +// ptr_map test +// + +template< typename C, typename B, typename T > +void ptr_map_test(); + +template< class Key > +Key get_next_key( const Key& k ); + +template<> +int get_next_key<int>( const int& ) +{ + return rand(); +} + +template<> +std::string get_next_key<std::string>( const std::string& ) +{ + return boost::lexical_cast<std::string>( rand() ); +} + + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +template< typename C, typename B, typename T > +void ptr_map_test() +{ + using namespace boost; + + BOOST_TEST_MESSAGE( "starting associative container test" ); + enum { max_cnt = 10, size = 100 }; + C c; + BOOST_CHECK( c.size() == 0 ); + + const C c2( c.begin(), c.end() ); + BOOST_CHECK( c.size() == c2.size() ); + + C c3; + + BOOST_TEST_MESSAGE( "finished construction test" ); + + BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); + BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); + BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); + BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); + hide_warning(i2); + BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); + hide_warning(ci2); + ci = c.cbegin(); + ci = c.cend(); + + BOOST_DEDUCED_TYPENAME C::key_type a_key; + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); + BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); + hide_warning(s2); + BOOST_CHECK_EQUAL( c.size(), s ); + bool b = c.empty(); + hide_warning(b); + BOOST_TEST_MESSAGE( "finished accessors test" ); + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + c3.insert( c.begin(), c.end() ); + c.insert( c3 ); + c.erase( c.begin() ); + BOOST_CHECK( c3.end() == c3.erase( boost::make_iterator_range(c3) ) ); + c3.erase( a_key ); + + BOOST_CHECK( c3.empty() ); + c.swap( c3 ); + swap(c,c3); + swap(c3,c); + BOOST_CHECK( !c3.empty() ); + c3.clear(); + BOOST_CHECK( c3.empty() ); + BOOST_TEST_MESSAGE( "finished modifiers test" ); + + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + a_key = get_next_key( a_key ); +#ifndef BOOST_NO_AUTO_PTR + c.insert( a_key, std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( a_key, std::unique_ptr<T>( new T ) ); +#endif + typename C::auto_type ptr2 = c.release( c.begin() ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<C> ap = c.release(); +#else + std::unique_ptr<C> up = c.release(); +#endif + c = c2.clone(); + BOOST_TEST_MESSAGE( "finished release/clone test" ); + + + a_key = get_next_key( a_key ); + c3.insert( a_key, new T ); + a_key = get_next_key( a_key ); + c3.insert( a_key, new T ); + + c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); + c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 ); + BOOST_CHECK( c3.empty() ); + BOOST_CHECK( !c.empty() ); + c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); + BOOST_CHECK( !c3.empty() ); + BOOST_CHECK( c.empty() ); +#ifdef BOOST_NO_SFINAE +#else + c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range(c3), c3 ); + BOOST_CHECK( !c.empty() ); + BOOST_CHECK( c3.empty() ); + c3. BOOST_NESTED_TEMPLATE transfer<C>(c); +#endif + BOOST_TEST_MESSAGE( "finished transfer test" ); + + BOOST_CHECK( !c3.empty() ); + c3.replace( c3.begin(), new T ); +#ifndef BOOST_NO_AUTO_PTR + c3.replace( c3.begin(), std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c3.replace( c3.begin(), std::unique_ptr<T>( new T ) ); +#endif + BOOST_TEST_MESSAGE( "finished set/map interface test" ); + + // @todo: make macro with algorithms so that the right erase() is called. + // c.unique(); + // c.unique( std::not_equal_to<T>() ); + // c.remove( T() ); + // c.remove_if( std::binder1st< std::equal_to<T> >( T() ) ); + + sub_range<C> sub; + sub_range<const C> csub; + + i = c.find( get_next_key( a_key ) ); + ci = c2.find( get_next_key( a_key ) ); + c2.count( get_next_key( a_key ) ); + sub = c.equal_range( get_next_key( a_key ) ); + csub = c2.equal_range( get_next_key( a_key ) ); + + try + { + c.at( get_next_key( a_key ) ); + } + catch( const bad_ptr_container_operation& ) + { } + + try + { + c2.at( get_next_key( a_key ) ); + } + catch( const bad_ptr_container_operation& ) + { } + + BOOST_TEST_MESSAGE( "finished algorithms interface test" ); + + typename C::iterator it = c.begin(), e = c.end(); + for( ; it != e; ++it ) + { + std::cout << "\n mapped value = " << *it->second << " key = " << it->first; + //std::cout << "\n mapped value = " << it.value() << " key = " << it.key(); + } + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + a_key = get_next_key( a_key ); + c.insert( a_key, new T ); + c.erase( a_key ); + c.erase( a_key ); + +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + + +template< class CDerived, class CBase, class T > +void test_transfer() +{ + CDerived from; + CBase to; + + int key = get_next_key( key ); + from.insert( key, new T ); + key = get_next_key( key ); + from.insert( key, new T ); + transfer_test( from, to ); +} + + + +template< class BaseContainer, class DerivedContainer, class Derived > +void map_container_assignment_test() +{ + DerivedContainer derived; + std::string foo( "foo" ); + std::string bar( "foo" ); + derived.insert( foo, new Derived ); + derived.insert( bar, new Derived ); + + BaseContainer base_container( derived ); + BOOST_CHECK_EQUAL( derived.size(), base_container.size() ); + base_container.clear(); + base_container = derived; + BOOST_CHECK_EQUAL( derived.size(), base_container.size() ); + + BaseContainer base2( base_container ); + BOOST_CHECK_EQUAL( base2.size(), base_container.size() ); + base2 = base_container; + BOOST_CHECK_EQUAL( base2.size(), base_container.size() ); + base_container = base_container; +} + + + +template< class Cont, class Key, class T > +void test_unordered_interface() +{ + Cont c; + T* t = new T; + Key key = get_next_key( key ); + c.insert( key, t ); + typename Cont::local_iterator i = c.begin( 0 ); + typename Cont::const_local_iterator ci = i; + ci = c.cbegin( 0 ); + i = c.end( 0 ); + ci = c.cend( 0 ); + typename Cont::size_type s = c.bucket_count(); + hide_warning(s); + s = c.max_bucket_count(); + s = c.bucket_size( 0 ); + s = c.bucket( key ); + float f = c.load_factor(); + f = c.max_load_factor(); + c.max_load_factor(f); + c.rehash(1000); +} + +#include <boost/ptr_container/ptr_unordered_map.hpp> + +using namespace std; + +void test_map() +{ + ptr_map_test< ptr_unordered_map<int, Base>, Base, Derived_class >(); + ptr_map_test< ptr_unordered_map<int, Value>, Value, Value >(); + ptr_map_test< ptr_unordered_map<int, nullable<Base> >, Base, Derived_class >(); + ptr_map_test< ptr_unordered_map<int, nullable<Value> >, Value, Value >(); + ptr_map_test< ptr_unordered_map<int, abstract_base>, abstract_base, implementation >(); + + ptr_map_test< ptr_unordered_multimap<int,Base>, Base, Derived_class >(); + ptr_map_test< ptr_unordered_multimap<int,Value>, Value, Value >(); + ptr_map_test< ptr_unordered_multimap<int, nullable<Base> >, Base, Derived_class >(); + ptr_map_test< ptr_unordered_multimap<int, nullable<Value> >, Value, Value >(); + + map_container_assignment_test< ptr_unordered_map<std::string,Base>, + ptr_unordered_map<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_unordered_map<std::string, nullable<Base> >, + ptr_unordered_map<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_unordered_map<std::string, nullable<Base> >, + ptr_unordered_map<std::string, nullable<Derived_class> >, + Derived_class>(); + map_container_assignment_test< ptr_unordered_multimap<std::string,Base>, + ptr_unordered_multimap<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_unordered_multimap<std::string, nullable<Base> >, + ptr_unordered_multimap<std::string,Derived_class>, + Derived_class>(); + map_container_assignment_test< ptr_unordered_multimap<std::string, nullable<Base> >, + ptr_unordered_multimap<std::string, nullable<Derived_class> >, + Derived_class>(); + + + test_transfer< ptr_unordered_map<int,Derived_class>, ptr_unordered_map<int,Base>, Derived_class >(); + test_transfer< ptr_unordered_multimap<int,Derived_class>, ptr_unordered_multimap<int,Base>, Derived_class >(); + + string joe = "joe"; + string brian = "brian"; + string kenny = "kenny"; + + ptr_unordered_map<string,int> m; + m.insert( joe, new int( 4 ) ); + m.insert( brian, new int( 6 ) ); + BOOST_CHECK( m[ "foo" ] == 0 ); + m[ "bar" ] += 5; + BOOST_CHECK( m[ "bar" ] == 5 ); + m[ joe ] += 56; + m[ brian ] += 10; + + BOOST_CHECK_THROW( (m.insert(kenny, 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (m.replace(m.begin(), 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (m.at("not there")), bad_ptr_container_operation ); + + for( ptr_unordered_map<string,int>::iterator i = m.begin(); + i != m.end(); ++i ) + { + if( is_null(i) ) + BOOST_CHECK( false ); + const string& ref = i->first; + hide_warning(ref); + int& ref2 = *(*i).second; + ref2++; + } + + typedef ptr_unordered_map<string,Derived_class> map_type; + map_type m2; + m2.insert( joe, new Derived_class ); + // + // This works fine since 'm2' is not const + // + m2.begin()->second->foo(); + + // + // These all return an implementation-defined proxy + // with two public members: 'first' and 'second' + // + map_type::value_type a_value = *m2.begin(); + a_value.second->foo(); + map_type::reference a_reference = *m2.begin(); + a_reference.second->foo(); + map_type::const_reference a_creference = *const_begin(m2); + hide_warning(a_creference); + + // + // + // These will fail as iterators propagate constness + // + //a_creference.second->foo(); + //a_cpointer->second->foo(); + //const_begin(m2)->second->foo(); + + test_unordered_interface< ptr_unordered_map<string,Base>, string, Derived_class >(); + test_unordered_interface< ptr_unordered_map<string,Base>, string, Derived_class >(); +} + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_map ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_unordered_set.cpp b/src/boost/libs/ptr_container/test/ptr_unordered_set.cpp new file mode 100644 index 00000000..9c21005b --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_unordered_set.cpp @@ -0,0 +1,151 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "associative_test_data.hpp" +#include <boost/ptr_container/ptr_unordered_set.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> + +template< class SetDerived, class SetBase, class T > +void test_transfer() +{ + SetBase to; + SetDerived from; + from.insert( new T ); + from.insert( new T ); + transfer_test( from, to ); +} + +template< class BaseContainer, class DerivedContainer, class Derived > +void test_copy() +{ + DerivedContainer derived; + derived.insert( new Derived ); + derived.insert( new Derived ); + + BaseContainer base( derived ); + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + base.clear(); + base = derived; + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + base = base; +} + +template< class Cont, class T > +void test_unordered_interface() +{ + Cont c; + T* t = new T; + c.insert( t ); + typename Cont::local_iterator i = c.begin( 0 ); + typename Cont::const_local_iterator ci = i; + ci = c.cbegin( 0 ); + i = c.end( 0 ); + ci = c.cend( 0 ); + typename Cont::size_type s = c.bucket_count(); + hide_warning(s); + s = c.max_bucket_count(); + s = c.bucket_size( 0 ); + s = c.bucket( *t ); + float f = c.load_factor(); + f = c.max_load_factor(); + c.max_load_factor(f); + c.rehash(1000); +} + + + +template< class PtrSet > +void test_erase() +{ + PtrSet s; + typedef typename PtrSet::key_type T; + + T t; + s.insert ( new T ); + T* t2 = t.clone(); + s.insert ( t2 ); + s.insert ( new T ); + BOOST_CHECK_EQUAL( s.size(), 3u ); + BOOST_CHECK_EQUAL( hash_value(t), hash_value(*t2) ); + BOOST_CHECK_EQUAL( t, *t2 ); + + typename PtrSet::iterator i = s.find( t ); + + BOOST_CHECK( i != s.end() ); + unsigned n = s.erase( t ); + BOOST_CHECK( n > 0 ); +} + + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_set() +{ + srand( 0 ); + ptr_set_test< ptr_unordered_set<Base>, Base, Derived_class, false >(); + ptr_set_test< ptr_unordered_set<Value>, Value, Value, false >(); + + ptr_set_test< ptr_unordered_multiset<Base>, Base, Derived_class, false >(); + ptr_set_test< ptr_unordered_multiset<Value>, Value, Value, false >(); + + test_copy< ptr_unordered_set<Base>, ptr_unordered_set<Derived_class>, + Derived_class>(); + test_copy< ptr_unordered_multiset<Base>, ptr_unordered_multiset<Derived_class>, + Derived_class>(); + + test_transfer< ptr_unordered_set<Derived_class>, ptr_unordered_set<Base>, Derived_class>(); + test_transfer< ptr_unordered_multiset<Derived_class>, ptr_unordered_multiset<Base>, Derived_class>(); + + ptr_unordered_set<int> set; + + BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); + set.insert( new int(0) ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<int> ap( new int(1) ); + set.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr<int> up( new int(2) ); + set.insert( std::move( up ) ); +#endif + BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); +#ifndef BOOST_NO_AUTO_PTR + BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr<int>(0) )), bad_ptr_container_operation ); +#endif +#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_NULLPTR) + BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr<int>(nullptr) )), bad_ptr_container_operation ); +#endif + + test_unordered_interface< ptr_unordered_set<Base>, Derived_class >(); + test_unordered_interface< ptr_unordered_multiset<Base>, Derived_class >(); + + test_erase< ptr_unordered_set<Base> >(); + test_erase< ptr_unordered_multiset<Base> >(); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_set ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_vector.cpp b/src/boost/libs/ptr_container/test/ptr_vector.cpp new file mode 100644 index 00000000..58df0c5b --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_vector.cpp @@ -0,0 +1,112 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/test/unit_test.hpp> +#include "sequence_test_data.hpp" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/ptr_container/ptr_list.hpp> +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/assign/list_inserter.hpp> + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +void test_ptr_vector() +{ + reversible_container_test< ptr_vector<Base>, Base, Derived_class >(); + reversible_container_test< ptr_vector<Value>, Value, Value >(); + +#ifdef BOOST_NO_SFINAE +#else + reversible_container_test< ptr_vector< nullable<Base> >, Base, Derived_class >(); + reversible_container_test< ptr_vector< nullable<Value> >, Value, Value >(); +#endif + + container_assignment_test< ptr_vector<Base>, ptr_vector<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_vector< nullable<Base> >, + ptr_vector< nullable<Derived_class> >, + Derived_class>(); + container_assignment_test< ptr_vector< nullable<Base> >, + ptr_vector<Derived_class>, + Derived_class>(); + container_assignment_test< ptr_vector<Base>, + ptr_vector< nullable<Derived_class> >, + Derived_class>(); + + test_transfer< ptr_vector<Derived_class>, ptr_vector<Base>, Derived_class>(); + test_transfer< ptr_vector<Derived_class>, ptr_list<Base>, Derived_class>(); + + random_access_algorithms_test< ptr_vector<int> >(); + + + ptr_vector<int> vec( 100u ); + BOOST_CHECK( vec.capacity() >= 100u ); + +#ifdef BOOST_PTR_CONTAINER_NO_EXCEPTIONS +#else + + BOOST_CHECK_THROW( vec.push_back(0), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.insert( vec.begin(), 0 )), bad_ptr_container_operation ); + BOOST_CHECK_THROW( vec.at( 42 ), bad_ptr_container_operation ); + vec.push_back( new int(0) ); + BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation ); + BOOST_CHECK_THROW( (vec.replace(vec.begin(), 0 )), bad_ptr_container_operation ); + +#endif + + vec.clear(); + assign::push_back( vec )( new int(2) ) + ( new int(4) ) + ( new int(6) ) + ( new int(8) ); + ptr_vector<int> vec2; + assign::push_back( vec2 ) + ( new int(1) ) + ( new int(3) ) + ( new int(5) ) + ( new int(7) ); + BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); + BOOST_CHECK( vec > vec2 ); + BOOST_CHECK( vec != vec2 ); + BOOST_CHECK( !(vec == vec2) ); + BOOST_CHECK( vec2 < vec ); + BOOST_CHECK( vec2 <= vec ); + BOOST_CHECK( vec >= vec2 ); + + const int data_size = 10; + int** array = new int*[data_size]; + for( int i = 0; i != data_size; ++i ) + array[i] = new int(i); + + vec.transfer( vec.begin(), array, data_size ); + int** array2 = vec.c_array(); + BOOST_CHECK( array2 != array ); + +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_ptr_vector ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/ptr_vector_size.cpp b/src/boost/libs/ptr_container/test/ptr_vector_size.cpp new file mode 100644 index 00000000..7d48fcf3 --- /dev/null +++ b/src/boost/libs/ptr_container/test/ptr_vector_size.cpp @@ -0,0 +1,26 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_vector.hpp> + +template class +boost::ptr_vector<int>; + +template class +boost::ptr_vector<short>; + +template class +boost::ptr_vector<char>; + +template class +boost::ptr_vector<char*>; + + diff --git a/src/boost/libs/ptr_container/test/sequence_test_data.hpp b/src/boost/libs/ptr_container/test/sequence_test_data.hpp new file mode 100644 index 00000000..6d3c43a2 --- /dev/null +++ b/src/boost/libs/ptr_container/test/sequence_test_data.hpp @@ -0,0 +1,342 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> +#include <boost/range/iterator_range.hpp> +#include <boost/bind.hpp> + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +template< typename C, typename B, typename T > +void reversible_container_test(); + +template< class IntContainer > +void algorithms_test(); + +template< typename C, typename B, typename T > +void reversible_container_test() +{ + using namespace boost; + + BOOST_TEST_MESSAGE( "starting reversible container test" ); + enum { max_cnt = 10 }; + C c; + set_capacity<C>()( c ); + BOOST_CHECK( c.size() == 0 ); + c.push_back( new T ); + BOOST_CHECK( c.size() == 1 ); + + const C c2_dummy( c.begin(), c.end() ); + BOOST_CHECK_EQUAL( c2_dummy.size(), c.size() ); + const C c2( c.clone() ); + BOOST_CHECK_EQUAL( c2.size(), c.size() ); + + C c3( c.begin(), c.end() ); + set_capacity<C>()( c3 ); + BOOST_CHECK_EQUAL( c.size(), c3.size() ); + + c.assign( c3.begin(), c3.end() ); + BOOST_CHECK_EQUAL( c.size(), c3.size() ); + + c.assign( c3 ); + set_capacity<C>()( c ); + BOOST_TEST_MESSAGE( "finished construction test" ); + + C a_copy( c ); + BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); + a_copy = a_copy; + BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); + a_copy.clear(); + a_copy = a_copy; + BOOST_CHECK( a_copy.empty() ); + BOOST_CHECK( !c.empty() ); + BOOST_TEST_MESSAGE( "finished copying test" ); + + BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); + hide_warning(alloc); + BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); + BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); + BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); + hide_warning(i2); + BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); + hide_warning(ci2); + BOOST_DEDUCED_TYPENAME C::reverse_iterator ri = c.rbegin(); + hide_warning(ri); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cri = c2.rbegin(); + hide_warning(cri); + BOOST_DEDUCED_TYPENAME C::reverse_iterator rv2 = c.rend(); + hide_warning(rv2); + BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cvr2 = c2.rend(); + hide_warning(cvr2); + i = c.rbegin().base(); + ci = c2.rbegin().base(); + i = c.rend().base(); + ci = c2.rend().base(); + BOOST_CHECK_EQUAL( std::distance( c.rbegin(), c.rend() ), + std::distance( c.begin(), c.end() ) ); + + BOOST_TEST_MESSAGE( "finished iterator test" ); + + BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); + hide_warning(s); + BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); + hide_warning(s2); + c.push_back( new T ); + std::size_t size = 2u; +#ifndef BOOST_NO_AUTO_PTR + c.push_back( std::auto_ptr<T>( new T ) ); + ++size; +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.push_back( std::unique_ptr<T>( new T ) ); + ++size; +#endif + bool b = c.empty(); + BOOST_CHECK( !c.empty() ); + b = is_null( c.begin() ); + BOOST_CHECK( b == false ); + BOOST_DEDUCED_TYPENAME C::reference r = c.front(); + hide_warning(r); + BOOST_DEDUCED_TYPENAME C::const_reference cr = c2.front(); + hide_warning(cr); + BOOST_DEDUCED_TYPENAME C::reference r2 = c.back(); + hide_warning(r2); + BOOST_DEDUCED_TYPENAME C::const_reference cr2 = c2.back(); + hide_warning(cr2); + BOOST_TEST_MESSAGE( "finished accessors test" ); + + c.push_back( new T ); + ++size; + BOOST_CHECK_EQUAL( c.size(), size ); + + c.pop_back(); + BOOST_CHECK( !c.empty() ); + c.insert( c.end(), new T ); +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<T> ap(new T); + c.insert( c.end(), ap ); + ++size; +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr<T> up( new T ); + c.insert( c.end(), std::move( up ) ); + ++size; +#endif + BOOST_CHECK_EQUAL( c.size(), size ); + +#if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) +#else + c.insert( c.end(), c3 ); +#endif + c3.insert( c3.end(), c.begin(), c.end() ); + c.erase( c.begin() ); + c3.erase( c3.begin(), c3.end() ); + c3.erase( boost::make_iterator_range(c3) ); + BOOST_CHECK( c3.empty() ); + BOOST_CHECK( !c.empty() ); + c.swap( c3 ); + BOOST_CHECK( !c3.empty() ); + c3.clear(); + BOOST_CHECK( c3.empty() ); + C c4; + c4.swap(c3); +#ifdef BOOST_NO_SFINAE +#else + swap(c4,c3); +#endif + BOOST_TEST_MESSAGE( "finished modifiers test" ); + + c.push_back( new T ); c.push_back( new T ); c.push_back( new T ); + typedef BOOST_DEDUCED_TYPENAME C::auto_type auto_type; + +#ifdef BOOST_NO_SFINAE +#else + auto_type ptr = c.release( c.begin() ); +#endif +#ifndef BOOST_NO_AUTO_PTR + std::auto_ptr<C> ap2 = c.release(); +#else + std::unique_ptr<C> up2 = c.release(); +#endif + c = c2.clone(); + BOOST_CHECK( !c.empty() ); + auto_type ptr2 = c.replace( c.begin(), new T ); +#ifndef BOOST_NO_AUTO_PTR + ptr2 = c.replace( c.begin(), std::auto_ptr<T>( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + ptr2 = c.replace( c.begin(), std::unique_ptr<T>( new T ) ); +#endif + BOOST_TEST_MESSAGE( "finished release/clone/replace test" ); + + c3.push_back( new T ); + c3.push_back( new T ); + c3.push_back( new T ); + c. BOOST_NESTED_TEMPLATE transfer<C>( c.begin(), c3.begin(), c3 ); + c. BOOST_NESTED_TEMPLATE transfer<C>( c.end(), c3.begin(), c3.end(), c3 ); +#ifdef BOOST_NO_SFINAE +#else + c. BOOST_NESTED_TEMPLATE transfer<C>( c.end(), boost::make_iterator_range( c3 ), c3 ); + BOOST_CHECK( c3.empty() ); + BOOST_CHECK( !c.empty() ); +#endif + c3. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c ); + BOOST_CHECK( !c3.empty() ); + BOOST_CHECK( c.empty() ); + BOOST_TEST_MESSAGE( "finished transfer test" ); + + c3.resize( 0u ); + BOOST_CHECK( c3.empty() ); + c3.resize( 10u ); + BOOST_CHECK_EQUAL( c3.size(), 10u ); + c3.resize( 12u, &*c3.begin() ); + BOOST_CHECK_EQUAL( c3.size(), 12u ); + BOOST_TEST_MESSAGE( "finished resize test" ); + +} + + + +template< class CDerived, class CBase, class T > +void test_transfer() +{ + BOOST_TEST_MESSAGE( "starting transfer test" ); + CDerived from; + CBase to; + + set_capacity<CDerived>()( from ); + set_capacity<CBase>()( to ); + + from.push_back( new T ); + from.push_back( new T ); + to. BOOST_NESTED_TEMPLATE transfer<CDerived>( to.end(), from ); + BOOST_TEST_MESSAGE( "finished transfer test" ); +} + + + +#include <boost/assign/list_inserter.hpp> +#include <iostream> + +template< class Compare, class C > +bool is_sorted( const C& c ) +{ + if( c.size() < 2 ) + return true; + + typename C::const_iterator prev = c.begin(), + e = c.end(), + next = prev; + Compare pred; + for( ; next != e ; ) + { + prev = next; + ++next; + + if( next == c.end() ) + return true; + + if( !pred(*prev,*next) ) + return false; + } + return true; +} + + + + +struct equal_to_int +{ + int i_; + + equal_to_int( int i ) : i_(i) + { } + + bool operator()( int i ) const + { + return i_ == i; + } +}; + + +template< class IntContainer > +void random_access_algorithms_test() +{ + BOOST_TEST_MESSAGE( "starting random accessors algorithms test" ); + + IntContainer c; + set_capacity<IntContainer>()( c ); + assign::push_back( c ) + ( new int(1) ) + ( new int(3) ) + ( new int(6) ) + ( new int(7) ) + ( new int(2) ) + ( new int(2) ) + ( new int(0) ) + ( new int(6) ) + ( new int(3) ); + c.sort(); + BOOST_CHECK( is_sorted< std::less_equal<int> >( c ) ); + BOOST_CHECK_EQUAL( c.size(), 9u ); + + c.unique(); + BOOST_CHECK_EQUAL( c.size(), 6u ); +#ifdef PTR_LIST_TEST + BOOST_CHECK( c.front() == 0 ); + BOOST_CHECK( c.back() == 7 ); +#else + BOOST_CHECK( c[0] == 0 ); + BOOST_CHECK( c[1] == 1 ); + BOOST_CHECK( c[2] == 2 ); + BOOST_CHECK( c[3] == 3 ); + BOOST_CHECK( c[4] == 6 ); + BOOST_CHECK( c[5] == 7 ); +#endif + + c.erase_if( equal_to_int(1) ); + BOOST_CHECK_EQUAL( c.size(), 5u ); +#ifdef PTR_LIST_TEST + BOOST_CHECK_EQUAL( c.front(), 0 ); +#else + BOOST_CHECK_EQUAL( c[0], 0 ); + BOOST_CHECK_EQUAL( c[1], 2 ); +#endif + + c.erase_if( equal_to_int(7) ); + BOOST_CHECK_EQUAL( c.size(), 4u ); + BOOST_CHECK_EQUAL( c.back(), 6 ); + + // C = [0,2,3,6] + + IntContainer c2; + set_capacity<IntContainer>()( c2 ); + assign::push_back( c2 ) + ( new int(-1) ) + ( new int(1) ) + ( new int(4) ) + ( new int(5) ) + ( new int(7) ); + BOOST_CHECK( c2.size() == 5u ); + c.merge( c2 ); + BOOST_CHECK( c2.empty() ); + BOOST_CHECK( c.size() == 9u ); + BOOST_CHECK( is_sorted< std::less_equal<int> >( c ) ); + BOOST_TEST_MESSAGE( "finished random accessors algorithms test" ); +} + +#if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) +#pragma GCC diagnostic pop +#endif diff --git a/src/boost/libs/ptr_container/test/serialization.cpp b/src/boost/libs/ptr_container/test/serialization.cpp new file mode 100644 index 00000000..f2ee0774 --- /dev/null +++ b/src/boost/libs/ptr_container/test/serialization.cpp @@ -0,0 +1,359 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/config.hpp> +#ifdef BOOST_MSVC +#pragma warning( disable: 4996 ) +#endif + +#include <boost/test/unit_test.hpp> +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> +#include <boost/archive/xml_iarchive.hpp> +#include <boost/archive/xml_oarchive.hpp> +#include <boost/functional/hash.hpp> +#include <boost/ptr_container/ptr_container.hpp> +#include <boost/ptr_container/serialize_ptr_container.hpp> +#include <boost/serialization/export.hpp> +#include <boost/serialization/base_object.hpp> +#include <boost/serialization/utility.hpp> +#include <boost/serialization/string.hpp> +#include <fstream> +#include <string> +#include <cstdio> + +// +// serialization helper: we can't save a non-const object +// +template< class T > +inline T const& as_const( T const& r ) +{ + return r; +} + +// +// used to customize tests for circular_buffer +// +template< class Cont > +struct set_capacity +{ + void operator()( Cont& ) const + { } +}; + +template<class T> +struct set_capacity< boost::ptr_circular_buffer<T> > +{ + void operator()( boost::ptr_circular_buffer<T>& c ) const + { + c.set_capacity( 100u ); + } +}; + +// +// class hierarchy +// +struct Base +{ + friend class boost::serialization::access; + + int i; + + + template< class Archive > + void serialize( Archive& ar, const unsigned int /*version*/ ) + { + ar & boost::serialization::make_nvp( "i", i ); + } + + Base() : i(42) + { } + + Base( int i ) : i(i) + { } + + virtual ~Base() + { } +}; + +inline bool operator<( const Base& l, const Base& r ) +{ + return l.i < r.i; +} + +inline bool operator==( const Base& l, const Base& r ) +{ + return l.i == r.i; +} + +inline std::size_t hash_value( const Base& b ) +{ + return boost::hash_value( b.i ); +} + +struct Derived : Base +{ + int i2; + + template< class Archive > + void serialize( Archive& ar, const unsigned int /*version*/ ) + { + ar & boost::serialization::make_nvp( "Base", + boost::serialization::base_object<Base>( *this ) ); + ar & boost::serialization::make_nvp( "i2", i2 ); + } + + Derived() : Base(42), i2(42) + { } + + explicit Derived( int i2 ) : Base(0), i2(i2) + { } +}; + +BOOST_CLASS_EXPORT_GUID( Derived, "Derived" ) + +// +// test of containers +// +// + +template< class C, class T > +void add( C& c, T* r, unsigned /*n*/ ) +{ + c.insert( c.end(), r ); +} + +template< class U, class T > +void add( boost::ptr_array<U,2>& c, T* r, unsigned n ) +{ + c.replace( n, r ); +} + +template< class Cont, class OArchive, class IArchive > +void test_serialization_helper() +{ + Cont vec; + set_capacity<Cont>()( vec ); + add( vec, new Base( -1 ), 0u ); + add( vec, new Derived( 1 ), 1u ); + BOOST_CHECK_EQUAL( vec.size(), 2u ); + + std::string fn = std::tmpnam( 0 ); + + { + std::ofstream ofs( fn.c_str() ); + OArchive oa(ofs); + oa << boost::serialization::make_nvp( "container", as_const(vec) ); + } + + Cont vec2; + + { + std::ifstream ifs( fn.c_str(), std::ios::binary ); + IArchive ia(ifs); + ia >> boost::serialization::make_nvp( "container", vec2 ); + } + + std::remove( fn.c_str() ); + + BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); + BOOST_CHECK_EQUAL( (*vec2.begin()).i, -1 ); + BOOST_CHECK_EQUAL( (*++vec2.begin()).i, 0 ); + + typename Cont::iterator i = vec2.begin(); + ++i; + Derived* d = dynamic_cast<Derived*>( &*i ); + BOOST_CHECK_EQUAL( d->i2, 1 ); + +} + +template< class Cont, class OArchive, class IArchive > +void test_serialization_unordered_set_helper() +{ + Cont vec; + set_capacity<Cont>()( vec ); + add( vec, new Base( -1 ), 0u ); + add( vec, new Derived( 1 ), 1u ); + BOOST_CHECK_EQUAL( vec.size(), 2u ); + + std::string fn = std::tmpnam( 0 ); + + { + std::ofstream ofs( fn.c_str() ); + OArchive oa(ofs); + oa << boost::serialization::make_nvp( "container", as_const(vec) ); + } + + Cont vec2; + + { + std::ifstream ifs( fn.c_str(), std::ios::binary ); + IArchive ia(ifs); + ia >> boost::serialization::make_nvp( "container", vec2 ); + } + + std::remove( fn.c_str() ); + + BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); + BOOST_CHECK_EQUAL( (*vec2.begin()).i, -1 ); + BOOST_CHECK_EQUAL( (*++vec2.begin()).i, 0 ); +} + +template< class Map, class OArchive, class IArchive > +void test_serialization_map_helper() +{ + Map m; + std::string key1("key1"), key2("key2"); + m.insert( key1, new Base( -1 ) ); + m.insert( key2, new Derived( 1 ) ); + BOOST_CHECK_EQUAL( m.size(), 2u ); + + std::string fn = std::tmpnam( 0 ); + + { + std::ofstream ofs( fn.c_str() ); + OArchive oa(ofs); + oa << boost::serialization::make_nvp( "container", as_const(m) ); + } + + Map m2; + + { + std::ifstream ifs( fn.c_str(), std::ios::binary ); + IArchive ia(ifs); + ia >> boost::serialization::make_nvp( "container", m2 ); + } + + std::remove( fn.c_str() ); + + BOOST_CHECK_EQUAL( m.size(), m2.size() ); + BOOST_CHECK_EQUAL( m2.find(key1)->second->i, -1 ); + BOOST_CHECK_EQUAL( m2.find(key2)->second->i, 0 ); + + typename Map::iterator i = m2.find(key2); + Derived* d = dynamic_cast<Derived*>( i->second ); + BOOST_CHECK_EQUAL( d->i2, 1 ); +} + +// +// basic test of hierarchy +// +void test_hierarchy() +{ + Base* p = new Derived(); + + std::string fn = std::tmpnam( 0 ); + + { + std::ofstream ofs( fn.c_str() ); + boost::archive::text_oarchive oa(ofs); + oa << as_const(p); + } + + Base* d = 0; + + { + std::ifstream ifs( fn.c_str(), std::ios::binary ); + boost::archive::text_iarchive ia(ifs); + ia >> d; + } + + std::remove( fn.c_str() ); + + BOOST_CHECK_EQUAL( p->i, d->i ); + BOOST_CHECK( p != d ); + BOOST_CHECK( dynamic_cast<Derived*>( d ) ); + delete p; + delete d; +} + +// +// test initializer +// +void test_serialization() +{ + test_hierarchy(); + test_serialization_helper< boost::ptr_deque<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive >(); + test_serialization_helper< boost::ptr_list<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_helper< boost::ptr_vector<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_helper< boost::ptr_vector<Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + test_serialization_helper< boost::ptr_circular_buffer<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_helper< boost::ptr_circular_buffer<Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + test_serialization_helper< boost::ptr_array<Base,2>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_helper< boost::ptr_set<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_helper< boost::ptr_multiset<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + + test_serialization_unordered_set_helper< boost::ptr_unordered_set<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_unordered_set_helper<boost::ptr_unordered_multiset<Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + + test_serialization_map_helper< boost::ptr_map<std::string,Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_map_helper< boost::ptr_multimap<std::string,Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + + test_serialization_map_helper< boost::ptr_map<std::string,Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + test_serialization_map_helper< boost::ptr_multimap<std::string,Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + + test_serialization_map_helper< boost::ptr_unordered_map<std::string,Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + test_serialization_map_helper< boost::ptr_unordered_multimap<std::string,Base>, + boost::archive::text_oarchive, + boost::archive::text_iarchive>(); + + test_serialization_map_helper< boost::ptr_unordered_map<std::string,Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + test_serialization_map_helper< boost::ptr_unordered_multimap<std::string,Base>, + boost::archive::xml_oarchive, + boost::archive::xml_iarchive>(); + +} + + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_serialization ) ); + + return test; +} diff --git a/src/boost/libs/ptr_container/test/simple_test.cpp b/src/boost/libs/ptr_container/test/simple_test.cpp new file mode 100644 index 00000000..bdd67111 --- /dev/null +++ b/src/boost/libs/ptr_container/test/simple_test.cpp @@ -0,0 +1,106 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/lambda/lambda.hpp> +#include <algorithm> + +using namespace std; + +// +// A simple polymorphic class +// +class Poly +{ + int i_; + static int cnt_; + +public: + Poly() : i_( cnt_++ ) { } + virtual ~Poly() { } + void foo() { doFoo(); } + +private: + virtual void doFoo() { ++i_; } + +public: + friend inline bool operator>( const Poly& l, const Poly r ) + { + return l.i_ > r.i_; + } +}; + +int Poly::cnt_ = 0; + +// +// Normally we need something like this to compare pointers to objects +// +template< typename T > +struct sptr_greater +{ + bool operator()( const boost::shared_ptr<T>& l, const boost::shared_ptr<T>& r ) const + { + return *l > *r; + } +}; + +// +// one doesn't need to introduce new names or live with long ones +// +typedef boost::shared_ptr<Poly> PolyPtr; + + +void simple_test() +{ + enum { size = 2000 }; + typedef vector<PolyPtr> vector_t; + typedef boost::ptr_vector<Poly> ptr_vector_t; + vector_t svec; + ptr_vector_t pvec; + + for( int i = 0; i < size; ++i ) + { + svec.push_back( PolyPtr( new Poly ) ); + pvec.push_back( new Poly ); // no extra syntax + } + + for( int i = 0; i < size; ++i ) + { + svec[i]->foo(); + pvec[i].foo(); // automatic indirection + svec[i] = PolyPtr( new Poly ); + pvec.replace( i, new Poly ); // direct pointer assignment not possible, original element is deleted + } + + for( vector_t::iterator i = svec.begin(); i != svec.end(); ++i ) + (*i)->foo(); + + for( ptr_vector_t::iterator i = pvec.begin(); i != pvec.end(); ++i ) + i->foo(); // automatic indirection +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &simple_test ) ); + + return test; +} + + + + + diff --git a/src/boost/libs/ptr_container/test/test_data.hpp b/src/boost/libs/ptr_container/test/test_data.hpp new file mode 100644 index 00000000..31683602 --- /dev/null +++ b/src/boost/libs/ptr_container/test/test_data.hpp @@ -0,0 +1,337 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/static_assert.hpp> +#include <boost/type_traits.hpp> +#include <boost/config.hpp> +#include <boost/test/unit_test.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/functional/hash.hpp> +#include <algorithm> +#include <iostream> +#include <string> +#include <utility> +#include <cstdlib> + +using namespace std; +using namespace boost; + +////////////////////////////////////////////////////////////////////////////// +// Test class 1: a class hierarchy +////////////////////////////////////////////////////////////////////////////// + +namespace test +{ + class Base + { + protected: + Base( const Base& r ) : data1(r.data1), data2(r.data2), + data3(r.data3), data(r.data) + { + #ifdef PTR_CONTAINER_DEBUG + objects++; + std::cout <<"+ " << objects << "\n"; + #endif + } + + Base& operator=( const Base& ); + + public: // for test reasons only + int data1, data2, data3; + string data; + + public: + + Base() : data1(1), data2(2), data3(rand()%256), + data(lexical_cast<string>(rand())) + { + #ifdef PTR_CONTAINER_DEBUG + objects++; + std::cout <<"+ " << objects << "\n"; + #endif + } + + virtual ~Base() + { + #ifdef PTR_CONTAINER_DEBUG + objects--; + std::cout <<"- " << objects << "\n"; + if( objects < 0 ) + terminate(); + #endif + } + + void print( ostream& out ) const { do_print( out); } + Base* clone() const { return do_clone(); } + void foo() { do_foo(); } + + virtual bool less_than( const Base& b ) const + { + return data3 < b.data3; + } + + virtual bool equal( const Base& b ) const + { + return data1 == b.data1 && + data2 == b.data2 && + data3 == b.data3 && + data == b.data; + } + + #ifdef PTR_CONTAINER_DEBUG + static int objects; + #endif + + private: + virtual void do_print( ostream& /*out*/ ) const { }; + virtual Base* do_clone() const { return new Base( *this ); }; + virtual void do_foo() { }; + }; + + #ifdef PTR_CONTAINER_DEBUG + int Base::objects = 0; + #endif + + + + ostream& operator<<( ostream& out, const Base& b ) + { + b.print( out ); + return out; + } + + + // + // We rely on argument dependent lookup + // for this to be found + // + inline Base* new_clone( const Base& b ) + { + return b.clone(); + } + + + + inline bool operator<( const Base& l, const Base& r ) + { + return l.less_than( r ); + } + + + + inline bool operator>( const Base& l, const Base& r ) + { + return r < l; + } + + + + inline bool operator==( const Base& l, const Base& r ) + { + return l.equal( r ); + } + + + + inline bool operator!=( const Base& l, const Base& r ) + { + return !l.equal( r ); + } + + + + inline std::size_t hash_value( const Base& b ) + { + std::size_t seed = 0; + boost::hash_combine( seed, b.data ); + boost::hash_combine( seed, b.data1 ); + boost::hash_combine( seed, b.data2 ); + boost::hash_combine( seed, b.data3 ); + return seed; + } + + + class Derived_class : public Base + { + protected: + Derived_class( const Derived_class& r ) : Base( r ), i_(r.i_) + { } + + public: // for test reasons only + int i_; + + private: + + virtual void do_print( ostream& out ) const + { + out << i_; + } + + + virtual Base* do_clone() const + { + return new Derived_class( *this ); + } + + virtual void do_foo() + { + ++i_; + } + + public: + Derived_class() : i_( rand() ) + { } + + virtual bool less_than( const Base& b ) const + { + const Derived_class& d = dynamic_cast<const Derived_class&>( b ); + return i_ < d.i_; + } + }; + + + + inline std::size_t hash_value( const Derived_class& b ) + { + std::size_t seed = hash_value( static_cast<const Base&>( b ) ); + boost::hash_combine( seed, b.i_ ); + return seed; + } +} + +using test::Base; +using test::Derived_class; + +////////////////////////////////////////////////////////////////////////////// +// Test class 2: a value class +////////////////////////////////////////////////////////////////////////////// + +class Value +{ +public: // for test reasons only + string s_; + +public: + + Value() : s_( boost::lexical_cast<string>( rand() ) ) + {} + + ~Value() { /** debug code here */ } + + string name() const + { + return s_; + } +}; + + + +inline bool operator<( const Value& l, const Value& r ) +{ + return l.name() < r.name(); +} + + + +inline bool operator>( const Value& l, const Value& r ) +{ + return l.name() > r.name(); +} + + + +inline bool operator==( const Value& l, const Value& r ) +{ + return l.name() == r.name(); +} + + + +inline bool operator!=( const Value& l, const Value& r ) +{ + return l.name() != r.name(); +} + + + +inline ostream& operator<<( ostream& out, const Value& v ) +{ + return out << v.name() << " "; +} + + + +inline std::size_t hash_value( const Value& v ) +{ + return boost::hash_value( v.s_ ); +} + +// +// used to hide "unused variable" warnings +// +template< class T > +inline void hide_warning( T& /*r*/ ) +{ } + +// +// used to customize tests for circular_buffer +// +template< class Cont > +struct set_capacity +{ + void operator()( Cont& ) const + { } +}; + +// +// transfer() test +// + +template< class Cont1, class Cont2 > +void transfer_test( Cont1& from, Cont2& to ) +{ + BOOST_TEST_MESSAGE( "starting container transfer test" ); + BOOST_CHECK( !from.empty() ); + to. BOOST_NESTED_TEMPLATE transfer<Cont1>( from ); + BOOST_CHECK( !to.empty() ); + BOOST_TEST_MESSAGE( "finishing container transfer test" ); +} + + +// +// test of copy operations +// + +template< class BaseContainer, class DerivedContainer, class Derived > +void container_assignment_test() +{ + BOOST_TEST_MESSAGE( "starting container assignment test" ); + + DerivedContainer derived; + set_capacity<DerivedContainer>()( derived ); + derived.insert( derived.begin(), new Derived ); + derived.insert( derived.begin(), new Derived ); + + BaseContainer base( derived ); + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + base.clear(); + base = derived; + BOOST_CHECK_EQUAL( derived.size(), base.size() ); + BaseContainer base2( base ); + BOOST_CHECK_EQUAL( base2.size(), base.size() ); + base2 = base; + BOOST_CHECK_EQUAL( base2.size(), base.size() ); + base = base; + + BOOST_TEST_MESSAGE( "finished container assignment test" ); +} + + diff --git a/src/boost/libs/ptr_container/test/tree_test.cpp b/src/boost/libs/ptr_container/test/tree_test.cpp new file mode 100644 index 00000000..26805271 --- /dev/null +++ b/src/boost/libs/ptr_container/test/tree_test.cpp @@ -0,0 +1,279 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include "test_data.hpp" +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/utility.hpp> +#include <boost/lexical_cast.hpp> +#include <algorithm> +#include <iostream> +#include <cstddef> +#include <string> + +using namespace std; +using namespace boost; + +class node; + +class tree +{ + typedef ptr_vector<node> nodes_t; + nodes_t nodes; + +protected: + void swap( tree& r ) + { nodes.swap( r.nodes ); } + +public: + typedef nodes_t::iterator iterator; + typedef nodes_t::const_iterator const_iterator; + +public: + void add_child( node* n ); + void remove( iterator n ); + void write_tree( ostream& os ) const; + size_t size() const; + node& child( size_t idx ); + const node& child( size_t idx ) const; + iterator child_begin(); + const_iterator child_begin() const; + iterator child_end(); + const_iterator child_end() const; + iterator find( const string& match ); +}; + + + +class node : noncopyable +{ + virtual size_t do_node_size() const = 0; + virtual string do_description() const = 0; + virtual void do_write_value( ostream& os ) const = 0; + +public: + virtual ~node() { } + size_t node_size() const { return do_node_size(); } + string description() const { return do_description(); } + void write_value( ostream& os ) const { do_write_value( os ); } +}; + + + +class inner_node : public node, public tree +{ + string name; + + virtual size_t do_node_size() const + { + return tree::size(); + } + + virtual string do_description() const + { + return lexical_cast<string>( name ); + } + + virtual void do_write_value( ostream& os ) const + { + os << " inner node: " << name; + } + + void swap( inner_node& r ) + { + name.swap( r.name ); + tree::swap( r ); + } + +public: + inner_node() : name("inner node") + { } + + inner_node( const string& r ) : name(r) + { } + + inner_node* release() + { + inner_node* ptr( new inner_node ); + ptr->swap( *this ); + return ptr; + } +}; + + + +template< class T > +class leaf : public node +{ + T data; + + virtual size_t do_node_size() const + { + return 1; + } + + virtual string do_description() const + { + return lexical_cast<string>( data ); + } + + virtual void do_write_value( ostream& os ) const + { + os << " leaf: " << data; + } + +public: + leaf() : data( T() ) + { } + + leaf( const T& r ) : data(r) + { } + + void set_data( const T& r ) + { data = r; } +}; + +///////////////////////////////////////////////////////////////////////// +// tree implementation +///////////////////////////////////////////////////////////////////////// + +inline void tree::add_child( node* n ) +{ + nodes.push_back( n ); +} + +inline void tree::remove( iterator n ) +{ + BOOST_ASSERT( n != nodes.end() ); + nodes.erase( n ); +} + +void tree::write_tree( ostream& os ) const +{ + for( const_iterator i = nodes.begin(), + e = nodes.end(); + i != e; ++i ) + { + i->write_value( os ); + if( const inner_node* p = dynamic_cast<const inner_node*>( &*i ) ) + p->write_tree( os ); + } +} + +size_t tree::size() const +{ + size_t res = 1; + + for( const_iterator i = nodes.begin(), + e = nodes.end(); + i != e; ++i ) + { + res += i->node_size(); + } + + return res; +} + +inline node& tree::child( size_t idx ) +{ + return nodes[idx]; +} + +inline const node& tree::child( size_t idx ) const +{ + return nodes[idx]; +} + +inline tree::iterator tree::child_begin() +{ + return nodes.begin(); +} + +inline tree::const_iterator tree::child_begin() const +{ + return nodes.begin(); +} + +inline tree::iterator tree::child_end() +{ + return nodes.end(); +} + +inline tree::const_iterator tree::child_end() const +{ + return nodes.end(); +} + +tree::iterator tree::find( const string& match ) +{ + for( iterator i = nodes.begin(), + e = nodes.end(); + i != e; ++i ) + { + if( i->description() == match ) + return i; + + if( inner_node* p = dynamic_cast<inner_node*>( &*i ) ) + { + iterator j = p->find( match ); + if( j != p->child_end() ) + return j; + } + + } + + return child_end(); +} + +///////////////////////////////////////////////////////////////////////// +// test case +///////////////////////////////////////////////////////////////////////// + +void test_tree() +{ + tree root; + BOOST_CHECK_EQUAL( root.size(), 1u ); + inner_node node1( "node 1" ); + node1.add_child( new leaf<string>( "leaf 1" ) ); + node1.add_child( new leaf<int>( 42 ) ); + inner_node node2( "node 2" ); + node2.add_child( new leaf<float>( 42.0f ) ); + node2.add_child( new leaf<string>( "leaf 4" ) ); + + root.add_child( node1.release() ); + BOOST_CHECK_EQUAL( root.size(), 4u ); + root.add_child( node2.release() ); + root.add_child( new inner_node( "node 3" ) ); + BOOST_CHECK_EQUAL( root.size(), 8u ); + root.add_child( new leaf<string>( "leaf 5" ) ); + BOOST_CHECK_EQUAL( root.size(), 9u ); + + root.write_tree( cout ); + tree::iterator a_leaf = root.find( "42" ); + BOOST_CHECK_EQUAL( a_leaf->description(), "42" ); + leaf<int>& the_leaf = dynamic_cast< leaf<int>& >( *a_leaf ); + the_leaf.set_data( 2*42 ); + BOOST_CHECK_EQUAL( a_leaf->description(), "84" ); + +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_tree ) ); + + return test; +} + + diff --git a/src/boost/libs/ptr_container/test/tut1.cpp b/src/boost/libs/ptr_container/test/tut1.cpp new file mode 100644 index 00000000..ebd149db --- /dev/null +++ b/src/boost/libs/ptr_container/test/tut1.cpp @@ -0,0 +1,359 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +// +// This example is intended to get you started. +// Notice how the smart container +// +// 1. takes ownership of objects +// 2. transfers ownership +// 3. applies indirection to iterators +// 4. clones objects from other smart containers +// + +// +// First we select which container to use. +// +#include <boost/ptr_container/ptr_deque.hpp> + +// +// we need these later in the example +// +#include <boost/assert.hpp> +#include <string> +#include <exception> + + +// +// Then we define a small polymorphic class +// hierarchy. +// + +class animal : boost::noncopyable +{ + virtual std::string do_speak() const = 0; + std::string name_; + +protected: + // + // Animals cannot be copied... + // + animal( const animal& r ) : name_( r.name_ ) { } + void operator=( const animal& ); + +private: + // + // ...but due to advances in genetics, we can clone them! + // + + virtual animal* do_clone() const = 0; + +public: + animal( const std::string& name ) : name_(name) { } + virtual ~animal() throw() { } + + std::string speak() const + { + return do_speak(); + } + + std::string name() const + { + return name_; + } + + animal* clone() const + { + return do_clone(); + } +}; + +// +// An animal is still not Clonable. We need this last hook. +// +// Notice that we pass the animal by const reference +// and return by pointer. +// + +animal* new_clone( const animal& a ) +{ + return a.clone(); +} + +// +// We do not need to define 'delete_clone()' since +// since the default is to call the default 'operator delete()'. +// + +const std::string muuuh = "Muuuh!"; +const std::string oiink = "Oiiink"; + +class cow : public animal +{ + virtual std::string do_speak() const + { + return muuuh; + } + + virtual animal* do_clone() const + { + return new cow( *this ); + } + +public: + cow( const std::string& name ) : animal(name) { } +}; + +class pig : public animal +{ + virtual std::string do_speak() const + { + return oiink; + } + + virtual animal* do_clone() const + { + return new pig( *this ); + } + +public: + pig( const std::string& name ) : animal(name) { } +}; + +// +// Then we, of course, need a place to put all +// those animals. +// + +class farm +{ + // + // This is where the smart containers are handy + // + typedef boost::ptr_deque<animal> barn_type; + barn_type barn; + +#if !defined(BOOST_NO_CXX11_SMART_PTR) && !(defined(BOOST_MSVC) && BOOST_MSVC == 1600) && !BOOST_WORKAROUND(BOOST_GCC, < 40600) + typedef std::unique_ptr<barn_type> raii_ptr; +#else + typedef std::auto_ptr<barn_type> raii_ptr; +#endif + + // + // An error type + // + struct farm_trouble : public std::exception { }; + +public: + // + // We would like to make it possible to + // iterate over the animals in the farm + // + typedef barn_type::iterator animal_iterator; + + // + // We also need to count the farm's size... + // + typedef barn_type::size_type size_type; + + // + // And we also want to transfer an animal + // safely around. The easiest way to think + // about '::auto_type' is to imagine a simplified + // 'std::auto_ptr<T>' ... this means you can expect + // + // T* operator->() + // T* release() + // deleting destructor + // + // but not more. + // + typedef barn_type::auto_type animal_transport; + + // + // Create an empty farm. + // + farm() { } + + // + // We need a constructor that can make a new + // farm by cloning a range of animals. + // + farm( animal_iterator begin, animal_iterator end ) + : + // + // Objects are always cloned before insertion + // unless we explicitly add a pointer or + // use 'release()'. Therefore we actually + // clone all animals in the range + // + barn( begin, end ) { } + + // + // ... so we need some other function too + // + + animal_iterator begin() + { + return barn.begin(); + } + + animal_iterator end() + { + return barn.end(); + } + + // + // Here it is quite ok to have an 'animal*' argument. + // The smart container will handle all ownership + // issues. + // + void buy_animal( animal* a ) + { + barn.push_back( a ); + } + + // + // The farm can also be in economical trouble and + // therefore be in the need to sell animals. + // + animal_transport sell_animal( animal_iterator to_sell ) + { + if( to_sell == end() ) + throw farm_trouble(); + + // + // Here we remove the animal from the barn, + // but the animal is not deleted yet...it's + // up to the buyer to decide what + // to do with it. + // + return barn.release( to_sell ); + } + + // + // How big a farm do we have? + // + size_type size() const + { + return barn.size(); + } + + // + // If things are bad, we might choose to sell all animals :-( + // + raii_ptr sell_farm() + { + return barn.release(); + } + + // + // However, if things are good, we might buy somebody + // else's farm :-) + // + + void buy_farm( raii_ptr other ) + { + // + // This line inserts all the animals from 'other' + // and is guaranteed either to succeed or to have no + // effect + // + barn.transfer( barn.end(), // insert new animals at the end + *other ); // we want to transfer all animals, + // so we use the whole container as argument + // + // You might think you would have to do + // + // other.release(); + // + // but '*other' is empty and can go out of scope as it wants + // + BOOST_ASSERT( other->empty() ); + } + +}; // class 'farm'. + +int main() +{ + // + // First we make a farm + // + farm animal_farm; + BOOST_ASSERT( animal_farm.size() == 0u ); + + animal_farm.buy_animal( new pig("Betty") ); + animal_farm.buy_animal( new pig("Benny") ); + animal_farm.buy_animal( new pig("Jeltzin") ); + animal_farm.buy_animal( new cow("Hanz") ); + animal_farm.buy_animal( new cow("Mary") ); + animal_farm.buy_animal( new cow("Frederik") ); + BOOST_ASSERT( animal_farm.size() == 6u ); + + // + // Then we make another farm...it will actually contain + // a clone of the other farm. + // + farm new_farm( animal_farm.begin(), animal_farm.end() ); + BOOST_ASSERT( new_farm.size() == 6u ); + + // + // Is it really clones in the new farm? + // + BOOST_ASSERT( new_farm.begin()->name() == "Betty" ); + + // + // Then we search for an animal, Mary (the Crown Princess of Denmark), + // because we would like to buy her ... + // + typedef farm::animal_iterator iterator; + iterator to_sell; + for( iterator i = animal_farm.begin(), + end = animal_farm.end(); + i != end; ++i ) + { + if( i->name() == "Mary" ) + { + to_sell = i; + break; + } + } + + farm::animal_transport mary = animal_farm.sell_animal( to_sell ); + + + if( mary->speak() == muuuh ) + // + // Great, Mary is a cow, and she may live longer + // + new_farm.buy_animal( mary.release() ); + else + // + // Then the animal would be destroyed (!) + // when we go out of scope. + // + ; + + // + // Now we can observe some changes to the two farms... + // + BOOST_ASSERT( animal_farm.size() == 5u ); + BOOST_ASSERT( new_farm.size() == 7u ); + + // + // The new farm has however underestimated how much + // it cost to feed Mary and its owner is forced to sell the farm... + // + animal_farm.buy_farm( new_farm.sell_farm() ); + + BOOST_ASSERT( new_farm.size() == 0u ); + BOOST_ASSERT( animal_farm.size() == 12u ); +} diff --git a/src/boost/libs/ptr_container/test/tut34.cpp b/src/boost/libs/ptr_container/test/tut34.cpp new file mode 100644 index 00000000..0716bde3 --- /dev/null +++ b/src/boost/libs/ptr_container/test/tut34.cpp @@ -0,0 +1,61 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +#include <boost/ptr_container/ptr_sequence_adapter.hpp> +#include <vector> +#include <boost/ptr_container/ptr_map_adapter.hpp> +#include <map> + +template< class T > +struct my_ptr_vector : + public boost::ptr_sequence_adapter< std::vector<T*> > +{ + +}; + + +template< class Key, class T, class Pred = std::less<Key>, + class Allocator = std::allocator< std::pair<const Key, T> > > +struct my_map : public std::map<Key,T,Pred,Allocator> +{ + explicit my_map( const Pred& pred = Pred(), + const Allocator& alloc = Allocator() ) + { } +}; + +#include <string> +struct Foo {}; + +typedef boost::ptr_map_adapter< my_map<std::string,Foo*> > foo_map; + +template< class Key, class T, class Pred = std::less<Key> > +struct my_ptr_map : public boost::ptr_map_adapter< std::map<Key,T*,Pred> > +{ + +}; + +typedef my_ptr_map<std::string,Foo> foo_map2; + + +int main() +{ + + my_ptr_vector<Foo> vec; + vec.push_back( new Foo ); + foo_map m1; + foo_map2 m2; + std::string s(""); + m1.insert( s, new Foo ); + m2.insert( s, new Foo ); + + +} + diff --git a/src/boost/libs/ptr_container/test/view_example.cpp b/src/boost/libs/ptr_container/test/view_example.cpp new file mode 100644 index 00000000..e8ad5dfe --- /dev/null +++ b/src/boost/libs/ptr_container/test/view_example.cpp @@ -0,0 +1,180 @@ +// +// Boost.Pointer Container +// +// Copyright Thorsten Ottosen 2003-2005. Use, modification and +// distribution is 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) +// +// For more information, see http://www.boost.org/libs/ptr_container/ +// + +// +// This example is intended to show you how to +// use the 'view_clone_manager'. The idea +// is that we have a container of non-polymorphic +// objects and want to keep then sorted by different +// criteria at the same time. +// + +// +// We'll go for 'ptr_vector' here. Using a node-based +// container would be a waste of space here. +// All container headers will also include +// the Clone Managers. +// +#include <boost/ptr_container/ptr_vector.hpp> +#include <boost/ptr_container/indirect_fun.hpp> + +#include <functional> // For 'binary_fnuction' +#include <cstdlib> // For 'rand()' +#include <algorithm> // For 'std::sort()' +#include <iostream> // For 'std::cout' + +using namespace std; + +// +// This is our simple example data-structure. It can +// be ordered in three ways. +// +struct photon +{ + photon() : color( rand() ), + direction( rand() ), + power( rand() ) + { } + + int color; + int direction; + int power; +}; + +// +// Our big container is a standard vector +// +typedef std::vector<photon> vector_type; + +// +// Now we define our view type by adding a second template argument. +// The 'view_clone_manager' will implements Cloning by taking address +// of objects. +// +// Notice the first template argument is 'photon' and not +// 'const photon' to allow the view container write access. +// +typedef boost::ptr_vector<photon,boost::view_clone_allocator> view_type; + +// +// Our first sort criterium +// +struct sort_by_color +{ + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + + bool operator()( const photon& l, const photon& r ) const + { + return l.color < r.color; + } +}; + +// +// Our second sort criterium +// +struct sort_by_direction +{ + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + + bool operator()( const photon& l, const photon& r ) const + { + return l.direction < r.direction; + } +}; + + +// +// Our third sort criterium +// +struct sort_by_power +{ + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + + bool operator()( const photon& l, const photon& r ) const + { + return l.power < r.power; + } +}; + +// +// This function inserts "Clones" into the +// the view. +// +// We need to pass the first argument +// as a non-const reference to be able to store +// 'T*' instead of 'const T*' objects. Alternatively, +// we might change the declaration of the 'view_type' +// to +// typedef boost::ptr_vector<const photon,boost::view_clone_manager> +// view_type; ^^^^^^ +// +void insert( vector_type& from, view_type& to ) +{ + to.insert( to.end(), + from.begin(), + from.end() ); +} + +int main() +{ + enum { sz = 10, count = 500 }; + + // + // First we create the main container and two views + // + std::vector<vector_type> photons; + view_type color_view; + view_type direction_view; + + // + // Then we fill the main container with some random data + // + for( int i = 0; i != sz; ++i ) + { + photons.push_back( vector_type() ); + + for( int j = 0; j != count; ++j ) + photons[i].push_back( photon() ); + } + + // + // Then we create the two views. + // + for( int i = 0; i != sz; ++i ) + { + insert( photons[i], color_view ); + insert( photons[i], direction_view ); + } + + // + // First we sort the original photons, using one of + // the view classes. This may sound trivial, but consider that + // the objects are scatered all around 'sz' different vectors; + // the view makes them act as one big vector. + // + std::sort( color_view.begin(), color_view.end(), sort_by_power() ); + + // + // And now we can sort the views themselves. Notice how + // we switch to different iterators and different predicates: + // + color_view.sort( sort_by_color() ); + + direction_view.sort( sort_by_direction() ); + + return 0; +} |