├── .appveyor.yml ├── .codecov.yml ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .ubsan-ignorelist ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build.jam ├── doc ├── associative_ptr_container.html ├── associative_ptr_container.rst ├── boost.png ├── comp.sh ├── comp_all.sh ├── comp_assoc_ptr_container.sh ├── comp_compatible_smart_ptr.sh ├── comp_conventions.sh ├── comp_examples.sh ├── comp_faq.sh ├── comp_guidelines.sh ├── comp_headers.sh ├── comp_indirect_fun.sh ├── comp_ptr_array.sh ├── comp_ptr_container.sh ├── comp_ptr_deque.sh ├── comp_ptr_inserter.sh ├── comp_ptr_list.sh ├── comp_ptr_map.sh ├── comp_ptr_map_adapter.sh ├── comp_ptr_multimap.sh ├── comp_ptr_multimap_adapter.sh ├── comp_ptr_multiset.sh ├── comp_ptr_multiset_adapter.sh ├── comp_ptr_sequence_adapter.sh ├── comp_ptr_set.sh ├── comp_ptr_set_adapter.sh ├── comp_ptr_vector.sh ├── comp_reference.sh ├── comp_rever_ptr_container.sh ├── comp_tutorial.sh ├── compatible_smart_ptr.html ├── compatible_smart_ptr.rst ├── conventions.html ├── conventions.rst ├── default.css ├── examples.html ├── examples.rst ├── faq.html ├── faq.rst ├── guidelines.html ├── guidelines.rst ├── headers.html ├── headers.rst ├── indirect_fun.html ├── indirect_fun.rst ├── intro.xml ├── ptr_array.html ├── ptr_array.rst ├── ptr_container.html ├── ptr_container.rst ├── ptr_container.xml ├── ptr_deque.html ├── ptr_deque.rst ├── ptr_inserter.html ├── ptr_inserter.rst ├── ptr_list.html ├── ptr_list.rst ├── ptr_map.html ├── ptr_map.rst ├── ptr_map_adapter.html ├── ptr_map_adapter.rst ├── ptr_multimap.html ├── ptr_multimap.rst ├── ptr_multimap_adapter.html ├── ptr_multimap_adapter.rst ├── ptr_multiset.html ├── ptr_multiset.rst ├── ptr_multiset_adapter.html ├── ptr_multiset_adapter.rst ├── ptr_sequence_adapter.html ├── ptr_sequence_adapter.rst ├── ptr_set.html ├── ptr_set.rst ├── ptr_set_adapter.html ├── ptr_set_adapter.rst ├── ptr_vector.html ├── ptr_vector.rst ├── reference.html ├── reference.rst ├── reversible_ptr_container.html ├── reversible_ptr_container.rst ├── todo.txt ├── tutorial.html ├── tutorial.rst └── tutorial_example.html ├── include └── boost │ └── ptr_container │ ├── clone_allocator.hpp │ ├── detail │ ├── associative_ptr_container.hpp │ ├── default_deleter.hpp │ ├── is_convertible.hpp │ ├── map_iterator.hpp │ ├── meta_functions.hpp │ ├── move.hpp │ ├── ptr_container_disable_deprecated.hpp │ ├── reversible_ptr_container.hpp │ ├── scoped_deleter.hpp │ ├── serialize_ptr_map_adapter.hpp │ ├── serialize_reversible_cont.hpp │ ├── serialize_xml_names.hpp │ ├── static_move_ptr.hpp │ ├── throw_exception.hpp │ └── void_ptr_iterator.hpp │ ├── exception.hpp │ ├── indirect_fun.hpp │ ├── nullable.hpp │ ├── ptr_array.hpp │ ├── ptr_circular_buffer.hpp │ ├── ptr_container.hpp │ ├── ptr_deque.hpp │ ├── ptr_inserter.hpp │ ├── ptr_list.hpp │ ├── ptr_map.hpp │ ├── ptr_map_adapter.hpp │ ├── ptr_sequence_adapter.hpp │ ├── ptr_set.hpp │ ├── ptr_set_adapter.hpp │ ├── ptr_unordered_map.hpp │ ├── ptr_unordered_set.hpp │ ├── ptr_vector.hpp │ ├── serialize_ptr_array.hpp │ ├── serialize_ptr_circular_buffer.hpp │ ├── serialize_ptr_container.hpp │ ├── serialize_ptr_deque.hpp │ ├── serialize_ptr_list.hpp │ ├── serialize_ptr_map.hpp │ ├── serialize_ptr_set.hpp │ ├── serialize_ptr_unordered_map.hpp │ ├── serialize_ptr_unordered_set.hpp │ └── serialize_ptr_vector.hpp ├── index.html ├── meta └── libraries.json └── test ├── Jamfile.v2 ├── associative_test_data.hpp ├── cmake_test ├── CMakeLists.txt └── main.cpp ├── const_element_containers.cpp ├── incomplete_type_test.cpp ├── indirect_fun.cpp ├── issue_23.cpp ├── iterator_test.cpp ├── no_exceptions.cpp ├── pointainer_speed.cpp ├── ptr_array.cpp ├── ptr_circular_buffer.cpp ├── ptr_container_adapter.cpp ├── ptr_deque.cpp ├── ptr_inserter.cpp ├── ptr_list.cpp ├── ptr_map.cpp ├── ptr_map_adapter.cpp ├── ptr_set.cpp ├── ptr_unordered_map.cpp ├── ptr_unordered_set.cpp ├── ptr_vector.cpp ├── ptr_vector_size.cpp ├── sequence_test_data.hpp ├── serialization.cpp ├── simple_test.cpp ├── test_data.hpp ├── tree_test.cpp ├── tut1.cpp ├── tut34.cpp └── view_example.cpp /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2017 Peter Dimov 2 | # Copyright 2017 - 2019 James E. King III 3 | # Copyright 2019 - 2021 Alexander Grund 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 6 | 7 | # 8 | # Generic Appveyor build script for boostorg repositories 9 | # See: https://github.com/boostorg/boost-ci/ 10 | # 11 | # Instructions for customizing this script for your library: 12 | # 13 | # 1. Customize the compilers and language levels you want. 14 | # 2. If you have more than include/, src/, test/, example/, examples/, 15 | # benchmark/ or tools/ directories, set the environment variable DEPINST. 16 | # For example if your build uses code in "bench/" and "fog/" directories: 17 | # - DEPINST: --include bench --include fog 18 | # 3. Enable pull request builds in your boostorg/ account. 19 | # 20 | # That's it - the script will do everything else for you. 21 | # 22 | 23 | version: 1.0.{build}-{branch} 24 | 25 | shallow_clone: true 26 | 27 | branches: 28 | only: 29 | - master 30 | - develop 31 | - /bugfix\/.*/ 32 | - /feature\/.*/ 33 | - /fix\/.*/ 34 | - /pr\/.*/ 35 | 36 | skip_commits: 37 | files: 38 | - LICENSE 39 | - meta/* 40 | - README.md 41 | 42 | matrix: 43 | fast_finish: false 44 | # Adding MAYFAIL to any matrix job allows it to fail but the build stays green: 45 | allow_failures: 46 | - MAYFAIL: true 47 | 48 | environment: 49 | global: 50 | B2_CI_VERSION: 1 51 | GIT_FETCH_JOBS: 4 52 | # see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties 53 | # to use the default for a given environment, comment it out; recommend you build debug and release however: 54 | # on Windows it is important to exercise all the possibilities, especially shared vs static, however most 55 | # libraries that care about this exercise it in their Jamfiles... 56 | B2_ADDRESS_MODEL: 32,64 57 | B2_LINK: shared,static 58 | # B2_THREADING: threading=multi,single 59 | B2_VARIANT: release 60 | 61 | matrix: 62 | - FLAVOR: Visual Studio 2017 C++2a Strict 63 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 64 | B2_CXXFLAGS: -permissive- 65 | B2_CXXSTD: 2a 66 | B2_TOOLSET: msvc-14.1 67 | 68 | - FLAVOR: Visual Studio 2017 C++14/17 69 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 70 | B2_CXXSTD: 14,17 71 | B2_TOOLSET: msvc-14.1 72 | 73 | - FLAVOR: cygwin (32-bit) 74 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 75 | ADDPATH: C:\cygwin\bin; 76 | B2_ADDRESS_MODEL: 32 77 | B2_CXXSTD: 11,14,1z 78 | B2_TOOLSET: gcc 79 | 80 | - FLAVOR: cygwin (64-bit) 81 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 82 | ADDPATH: C:\cygwin64\bin; 83 | B2_ADDRESS_MODEL: 64 84 | B2_CXXSTD: 11,14,1z 85 | B2_TOOLSET: gcc 86 | 87 | install: 88 | - git clone --depth 1 https://github.com/boostorg/boost-ci.git C:\boost-ci-cloned 89 | # Copy ci folder if not testing Boost.CI 90 | - if NOT "%APPVEYOR_PROJECT_NAME%" == "boost-ci" xcopy /s /e /q /i /y C:\boost-ci-cloned\ci .\ci 91 | - rmdir /s /q C:\boost-ci-cloned 92 | - ci\appveyor\install.bat 93 | 94 | build: off 95 | 96 | test_script: ci\build.bat 97 | 98 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 - 2021 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | # 5 | # Sample codecov configuration file. Edit as required 6 | 7 | codecov: 8 | max_report_age: off 9 | require_ci_to_pass: yes 10 | notify: 11 | # Increase this if you have multiple coverage collection jobs 12 | after_n_builds: 2 13 | wait_for_ci: yes 14 | 15 | parsers: 16 | gcov: 17 | branch_detection: 18 | conditional: yes 19 | loop: yes 20 | method: no 21 | macro: no 22 | 23 | # Change how pull request comments look 24 | comment: 25 | layout: "reach,diff,flags,files,footer" 26 | 27 | # Ignore specific files or folders. Glob patterns are supported. 28 | # See https://docs.codecov.com/docs/ignoring-paths 29 | ignore: 30 | - libs/ptr_container/test/ 31 | - test/ 32 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.ubsan-ignorelist: -------------------------------------------------------------------------------- 1 | vptr:libboost_serialization.so 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake ptr_container` 2 | # Copyright 2020, 2021 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.20) 7 | 8 | project(boost_ptr_container VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_ptr_container INTERFACE) 11 | add_library(Boost::ptr_container ALIAS boost_ptr_container) 12 | 13 | target_include_directories(boost_ptr_container INTERFACE include) 14 | 15 | target_link_libraries(boost_ptr_container 16 | INTERFACE 17 | Boost::array 18 | Boost::assert 19 | Boost::circular_buffer 20 | Boost::config 21 | Boost::core 22 | Boost::iterator 23 | Boost::mpl 24 | Boost::range 25 | Boost::smart_ptr 26 | Boost::static_assert 27 | Boost::type_traits 28 | Boost::unordered 29 | Boost::utility 30 | ) 31 | 32 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 33 | 34 | add_subdirectory(test) 35 | 36 | endif() 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PtrContainer, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), provides containers for holding heap-allocated objects in an exception-safe manner and with minimal overhead. 2 | 3 | ### License 4 | 5 | Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). 6 | 7 | ### Properties 8 | 9 | * C++11 10 | * Header Only 11 | 12 | ### Build Status 13 | 14 | 15 | | Branch | GHA CI | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | 16 | | :-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | 17 | | [`master`](https://github.com/boostorg/ptr_container/tree/master) | [![Build Status](https://github.com/boostorg/ptr_container/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/ptr_container/actions?query=branch:master) | [![Build status](https://ci.appveyor.com/api/projects/status//branch/master?svg=true)](https://ci.appveyor.com/project/cppalliance/ptr-container/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects//badge.svg)](https://scan.coverity.com/projects/boostorg-ptr_container) | [![codecov](https://codecov.io/gh/boostorg/ptr_container/branch/master/graph/badge.svg?token=)](https://codecov.io/gh/boostorg/ptr_container/tree/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)](https://www.boost.org/doc/libs/master/libs/ptr_container) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](https://www.boost.org/development/tests/master/developer/ptr_container.html) 18 | | [`develop`](https://github.com/boostorg/ptr_container/tree/develop) | [![Build Status](https://github.com/boostorg/ptr_container/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/ptr_container/actions?query=branch:develop) | [![Build status](https://ci.appveyor.com/api/projects/status//branch/develop?svg=true)](https://ci.appveyor.com/project/cppalliance/ptr-container/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects//badge.svg)](https://scan.coverity.com/projects/boostorg-ptr_container) | [![codecov](https://codecov.io/gh/boostorg/ptr_container/branch/develop/graph/badge.svg?token=)](https://codecov.io/gh/boostorg/ptr_container/tree/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)](https://www.boost.org/doc/libs/develop/libs/ptr_container) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](https://www.boost.org/development/tests/develop/developer/ptr_container.html) 19 | 20 | ### Directories 21 | 22 | | Name | Purpose | 23 | | ----------- | ------------------------------ | 24 | | `doc` | documentation | 25 | | `include` | headers | 26 | | `test` | unit tests | 27 | 28 | ### More information 29 | 30 | * [Ask questions](https://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-ptr_container) 31 | * [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. 32 | * 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](https://www.boost.org/LICENSE_1_0.txt). 33 | * Discussions about the library are held on the [Boost developers mailing list](https://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](https://www.boost.org/community/policy.html) before posting and add the `[ptr_container]` tag at the beginning of the subject line. 34 | 35 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright René Ferdinand Rivera Morell 2023-2024 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/array//boost_array 10 | /boost/assert//boost_assert 11 | /boost/circular_buffer//boost_circular_buffer 12 | /boost/config//boost_config 13 | /boost/core//boost_core 14 | /boost/iterator//boost_iterator 15 | /boost/mpl//boost_mpl 16 | /boost/range//boost_range 17 | /boost/smart_ptr//boost_smart_ptr 18 | /boost/static_assert//boost_static_assert 19 | /boost/type_traits//boost_type_traits 20 | /boost/unordered//boost_unordered 21 | /boost/utility//boost_utility ; 22 | 23 | project /boost/ptr_container 24 | : common-requirements 25 | include 26 | ; 27 | 28 | explicit 29 | [ alias boost_ptr_container : : : : $(boost_dependencies) ] 30 | [ alias all : boost_ptr_container test ] 31 | ; 32 | 33 | call-if : boost-library ptr_container 34 | ; 35 | 36 | -------------------------------------------------------------------------------- /doc/boost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/ptr_container/fa5071af867bfd2480e3b004a4bee27127b951b6/doc/boost.png -------------------------------------------------------------------------------- /doc/comp.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | sh comp_ptr_container.sh 13 | sh comp_reversible_ptr_container.sh 14 | sh comp_ptr_sequence_adapter.sh 15 | sh comp_associative_ptr_container.sh 16 | sh comp_ptr_set_adapter.sh 17 | 18 | -------------------------------------------------------------------------------- /doc/comp_all.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | sh comp_ptr_container.sh 13 | sh comp_reference.sh 14 | sh comp_faq.sh 15 | sh comp_tutorial.sh 16 | sh comp_guidelines.sh 17 | sh comp_headers.sh 18 | sh comp_examples.sh 19 | sh comp_conventions.sh 20 | sh comp_rever_ptr_container.sh 21 | sh comp_ptr_sequence_adapter.sh 22 | sh comp_assoc_ptr_container.sh 23 | sh comp_ptr_set_adapter.sh 24 | sh comp_ptr_multiset_adapter.sh 25 | sh comp_ptr_map_adapter.sh 26 | sh comp_ptr_multimap_adapter.sh 27 | sh comp_ptr_array.sh 28 | sh comp_ptr_vector.sh 29 | sh comp_ptr_deque.sh 30 | sh comp_ptr_list.sh 31 | sh comp_ptr_map.sh 32 | sh comp_ptr_multimap.sh 33 | sh comp_ptr_set.sh 34 | sh comp_ptr_multiset.sh 35 | sh comp_indirect_fun.sh 36 | sh comp_compatible_smart_ptr.sh 37 | 38 | 39 | -------------------------------------------------------------------------------- /doc/comp_assoc_ptr_container.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py associative_ptr_container.rst > associative_ptr_container.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_compatible_smart_ptr.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py compatible_smart_ptr.rst > compatible_smart_ptr.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_conventions.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py conventions.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > conventions.html 14 | -------------------------------------------------------------------------------- /doc/comp_examples.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py examples.rst > examples.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_faq.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py faq.rst > faq.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_guidelines.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py guidelines.rst > guidelines.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_headers.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py headers.rst > headers.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_indirect_fun.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py indirect_fun.rst > indirect_fun.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_array.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_array.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_array.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_container.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_container.rst > ptr_container.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_deque.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_deque.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_deque.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_inserter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_inserter.rst > ptr_inserter.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_list.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_list.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_list.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_map.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_map.rst > ptr_map.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_map_adapter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_map_adapter.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_map_adapter.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_multimap.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_multimap.rst > ptr_multimap.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_multimap_adapter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_multimap_adapter.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_multimap_adapter.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_multiset.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_multiset.rst > ptr_multiset.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_multiset_adapter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_multiset_adapter.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_multiset_adapter.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_sequence_adapter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_sequence_adapter.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_sequence_adapter.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_set.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_set.rst > ptr_set.html 13 | 14 | -------------------------------------------------------------------------------- /doc/comp_ptr_set_adapter.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_set_adapter.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_set_adapter.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_ptr_vector.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py ptr_vector.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > ptr_vector.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_reference.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py reference.rst > reference.html 13 | -------------------------------------------------------------------------------- /doc/comp_rever_ptr_container.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py reversible_ptr_container.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > reversible_ptr_container.html 14 | 15 | -------------------------------------------------------------------------------- /doc/comp_tutorial.sh: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | rst2html.py tutorial.rst | 13 | sed 's@compatible-smart-ptr@compatible-smart-ptr@g' > tutorial.html 14 | 15 | -------------------------------------------------------------------------------- /doc/conventions.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Conventions 8 | +++++++++++ 9 | 10 | There are a few design decisions that will affect how the classes are 11 | used. Besides these the classes are much like normal standard containers 12 | and provides almost the same interface. The new conventions are: 13 | 14 | .. contents:: :local: 15 | 16 | Null pointers are not allowed by default 17 | ---------------------------------------- 18 | 19 | If the user tries to insert the null pointer, the operation will throw a 20 | ``bad_pointer`` exception (see `Example 1 `_). 21 | 22 | Use `nullable `_ to allow null pointers. 23 | 24 | Please notice that all preconditions of the form :: 25 | 26 | x != 0; 27 | 28 | are not active when the you have instantiated a container 29 | with ``nullable`` as in :: 30 | 31 | boost::ptr_vector< boost::nullable > vec; 32 | vec.push_back( 0 ); // ok 33 | 34 | All default iterators apply an extra layer of indirection 35 | --------------------------------------------------------- 36 | 37 | This is done to 38 | make the containers easier and safer to use. It promotes a kind of 39 | pointer-less programming and the user of a class needs not worry about 40 | pointers except when allocating them (see `Example 2 `_). Iterators that 41 | provide access to the naked pointers are also provided since they might be 42 | useful in rare cases. For example, whenever ``begin()`` returns an iterator, 43 | ``ptr_begin()`` will return an iterator that allows one to iterate over the 44 | stored pointers. 45 | 46 | All comparison operations are done on the pointed to objects and not at the pointer level 47 | ----------------------------------------------------------------------------------------- 48 | 49 | For example, in ``ptr_set`` the ordering is by default done by 50 | ``boost::ptr_less`` which compares the indirected pointers. 51 | Similarly, ``operator==()`` for ``container`` compares all objects 52 | with ``operator==(const Foo&, const Foo&)``. 53 | 54 | 55 | Stored elements are required to be `Cloneable `_ for a subset of the operations 56 | --------------------------------------------------------------------------------------------------------------------- 57 | 58 | This is because most polymorphic objects cannot be copied directly, but 59 | they can often be so by a use of a member function (see `Example 4 `_). Often 60 | it does not even make sense to clone an object in which case a large 61 | subset of the operations are still workable. 62 | 63 | Whenever objects are inserted into a container, they are cloned before insertion 64 | -------------------------------------------------------------------------------- 65 | 66 | This is necessary because all pointer containers take ownerships of stored objects 67 | (see `Example 5 `_). 68 | 69 | Whenever pointers are inserted into a container, ownership is transferred to the container 70 | ------------------------------------------------------------------------------------------ 71 | 72 | All containers take ownership of the stored pointers and therefore a 73 | container needs to have its own copies (see `Example 5 `_). 74 | 75 | Ownership can be transferred from a container on a per pointer basis 76 | -------------------------------------------------------------------- 77 | 78 | This can of course also be convenient. Whenever it happens, an 79 | ``SmartContainer::auto_type`` object is used to provide an exception-safe transfer 80 | (see `Example 6 `_). 81 | 82 | Ownership can be transferred from a container to another container on a per iterator range basis 83 | ------------------------------------------------------------------------------------------------ 84 | 85 | This makes it possible to exchange data safely between different pointer 86 | containers without cloning the objects again (see `Example 7 `_). 87 | 88 | A container can be cheaply returned from functions either by making a clone or by giving up ownership of the container 89 | ---------------------------------------------------------------------------------------------------------------------- 90 | 91 | Two special member functions, ``clone()`` and ``release()``, both return a 92 | ``compatible-smart-ptr`` which can be assigned to another pointer container. This 93 | effectively reduces the cost of returning a container to one 94 | heap-allocation plus a call to ``swap()`` (see `Example 3 `_). 95 | 96 | Iterators are invalidated as in the corresponding standard container 97 | -------------------------------------------------------------------- 98 | 99 | Because the containers in this library wrap standard containers, the 100 | rules for invalidation of iterators are the same as the rules 101 | of the corresponding standard container. 102 | 103 | For example, for both ``boost::ptr_vector`` and ``std::vector`` 104 | insertion and deletion only invalidates the deleted 105 | element and elements following it; all elements before the inserted/deleted 106 | element remain valid. 107 | 108 | .. raw:: html 109 | 110 |
111 | 112 | **Navigate:** 113 | 114 | - `home `_ 115 | - `reference `_ 116 | 117 | .. raw:: html 118 | 119 |
120 | 121 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 122 | 123 | __ http://www.boost.org/LICENSE_1_0.txt 124 | 125 | 126 | -------------------------------------------------------------------------------- /doc/default.css: -------------------------------------------------------------------------------- 1 | /* 2 | boostinspect:nolicense 3 | 4 | :Author: David Goodger 5 | :Contact: goodger@users.sourceforge.net 6 | :date: $Date$ 7 | :version: $Revision$ 8 | :copyright: This stylesheet has been placed in the public domain. 9 | 10 | Default cascading style sheet for the HTML output of Docutils. 11 | */ 12 | 13 | .first { 14 | margin-top: 0 } 15 | 16 | .last { 17 | margin-bottom: 0 } 18 | 19 | a.toc-backref { 20 | text-decoration: none ; 21 | color: black } 22 | 23 | dd { 24 | margin-bottom: 0.5em } 25 | 26 | div.abstract { 27 | margin: 2em 5em } 28 | 29 | div.abstract p.topic-title { 30 | font-weight: bold ; 31 | text-align: center } 32 | 33 | div.attention, div.caution, div.danger, div.error, div.hint, 34 | div.important, div.note, div.tip, div.warning, div.admonition { 35 | margin: 2em ; 36 | border: medium outset ; 37 | padding: 1em } 38 | 39 | div.attention p.admonition-title, div.caution p.admonition-title, 40 | div.danger p.admonition-title, div.error p.admonition-title, 41 | div.warning p.admonition-title { 42 | color: red ; 43 | font-weight: bold ; 44 | font-family: sans-serif } 45 | 46 | div.hint p.admonition-title, div.important p.admonition-title, 47 | div.note p.admonition-title, div.tip p.admonition-title, 48 | div.admonition p.admonition-title { 49 | font-weight: bold ; 50 | font-family: sans-serif } 51 | 52 | div.dedication { 53 | margin: 2em 5em ; 54 | text-align: center ; 55 | font-style: italic } 56 | 57 | div.dedication p.topic-title { 58 | font-weight: bold ; 59 | font-style: normal } 60 | 61 | div.figure { 62 | margin-left: 2em } 63 | 64 | div.footer, div.header { 65 | font-size: smaller } 66 | 67 | div.sidebar { 68 | margin-left: 1em ; 69 | border: medium outset ; 70 | padding: 0em 1em ; 71 | background-color: #ffffee ; 72 | width: 40% ; 73 | float: right ; 74 | clear: right } 75 | 76 | div.sidebar p.rubric { 77 | font-family: sans-serif ; 78 | font-size: medium } 79 | 80 | div.system-messages { 81 | margin: 5em } 82 | 83 | div.system-messages h1 { 84 | color: red } 85 | 86 | div.system-message { 87 | border: medium outset ; 88 | padding: 1em } 89 | 90 | div.system-message p.system-message-title { 91 | color: red ; 92 | font-weight: bold } 93 | 94 | div.topic { 95 | margin: 2em } 96 | 97 | h1.title { 98 | text-align: center } 99 | 100 | h2.subtitle { 101 | text-align: center } 102 | 103 | hr { 104 | width: 75% } 105 | 106 | ol.simple, ul.simple { 107 | margin-bottom: 1em } 108 | 109 | ol.arabic { 110 | list-style: decimal } 111 | 112 | ol.loweralpha { 113 | list-style: lower-alpha } 114 | 115 | ol.upperalpha { 116 | list-style: upper-alpha } 117 | 118 | ol.lowerroman { 119 | list-style: lower-roman } 120 | 121 | ol.upperroman { 122 | list-style: upper-roman } 123 | 124 | p.attribution { 125 | text-align: right ; 126 | margin-left: 50% } 127 | 128 | p.caption { 129 | font-style: italic } 130 | 131 | p.credits { 132 | font-style: italic ; 133 | font-size: smaller } 134 | 135 | p.label { 136 | white-space: nowrap } 137 | 138 | p.rubric { 139 | font-weight: bold ; 140 | font-size: larger ; 141 | color: maroon ; 142 | text-align: center } 143 | 144 | p.sidebar-title { 145 | font-family: sans-serif ; 146 | font-weight: bold ; 147 | font-size: larger } 148 | 149 | p.sidebar-subtitle { 150 | font-family: sans-serif ; 151 | font-weight: bold } 152 | 153 | p.topic-title { 154 | font-weight: bold } 155 | 156 | pre.address { 157 | margin-bottom: 0 ; 158 | margin-top: 0 ; 159 | font-family: serif ; 160 | font-size: 100% } 161 | 162 | pre.line-block { 163 | font-family: serif ; 164 | font-size: 100% } 165 | 166 | pre.literal-block, pre.doctest-block { 167 | margin-left: 2em ; 168 | margin-right: 2em ; 169 | background-color: #eeeeee } 170 | 171 | span.classifier { 172 | font-family: sans-serif ; 173 | font-style: oblique } 174 | 175 | span.classifier-delimiter { 176 | font-family: sans-serif ; 177 | font-weight: bold } 178 | 179 | span.interpreted { 180 | font-family: sans-serif } 181 | 182 | span.option { 183 | white-space: nowrap } 184 | 185 | span.option-argument { 186 | font-style: italic } 187 | 188 | span.pre { 189 | white-space: pre } 190 | 191 | span.problematic { 192 | color: red } 193 | 194 | table { 195 | margin-top: 0.5em ; 196 | margin-bottom: 0.5em } 197 | 198 | table.citation { 199 | border-left: solid thin gray ; 200 | padding-left: 0.5ex } 201 | 202 | table.docinfo { 203 | margin: 2em 4em } 204 | 205 | table.footnote { 206 | border-left: solid thin black ; 207 | padding-left: 0.5ex } 208 | 209 | td, th { 210 | padding-left: 0.5em ; 211 | padding-right: 0.5em ; 212 | vertical-align: top } 213 | 214 | th.docinfo-name, th.field-name { 215 | font-weight: bold ; 216 | text-align: left ; 217 | white-space: nowrap } 218 | 219 | h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { 220 | font-size: 100% } 221 | 222 | tt { 223 | background-color: #eeeeee } 224 | 225 | ul.auto-toc { 226 | list-style-type: none } 227 | 228 | pre{ 229 | BORDER-RIGHT: gray 1pt solid; 230 | PADDING-RIGHT: 2pt; 231 | BORDER-TOP: gray 1pt solid; 232 | DISPLAY: block; 233 | PADDING-LEFT: 2pt; 234 | PADDING-BOTTOM: 2pt; 235 | BORDER-LEFT: gray 1pt solid; 236 | MARGIN-RIGHT: 32pt; 237 | PADDING-TOP: 2pt; 238 | BORDER-BOTTOM: gray 1pt solid; 239 | FONT-FAMILY: "Courier New", Courier, mono; 240 | background-color: #EEEEEE; 241 | } 242 | 243 | 244 | .keyword{color: #0000FF;} 245 | .identifier{} 246 | .comment{font-style: italic; color: #008000;} 247 | .special{color: #800040;} 248 | .preprocessor{color: #3F007F;} 249 | .string{font-style: italic; color: #666666;} 250 | .literal{/*font-style: italic;*/ color: #000000;} 251 | -------------------------------------------------------------------------------- /doc/faq.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | 8 | FAQ 9 | === 10 | 11 | .. contents:: :local: 12 | 13 | Calling ``assign()`` is very costly and I do not really need to store cloned objects; I merely need to overwrite the existing ones; what do I do? 14 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 15 | 16 | Call ``std::copy( first, last, c.begin() );``. 17 | 18 | Which mutating algorithms are safe to use with pointers? 19 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20 | 21 | Any mutating algorithm that moves elements around by swapping them. An 22 | important example is ``std::sort()``; examples of unsafe algorithms are 23 | ``std::unique()`` and ``std::remove()``. 24 | 25 | .. That is why these algorithms are 26 | provided as member functions. 27 | 28 | Why does ``ptr_map::insert()/replace()`` take two arguments (the key and the pointer) instead of one ``std::pair``? And why is the key passed by non-const reference? 29 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 30 | 31 | This is the only way the function can be implemented in an exception-safe 32 | manner; since the copy-constructor of the key might throw, and since 33 | function arguments are not guaranteed to be evaluated from left to right, 34 | we need to ensure that evaluating the first argument does not throw. 35 | Passing the key as a reference achieves just that. 36 | 37 | When instantiating a pointer container with a type ``T``, is ``T`` then allowed to be incomplete at that point? 38 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 39 | 40 | No. This is a distinct property of ``shared_ptr`` which implies some overhead. 41 | 42 | However, one can leave ``T`` incomplete in the header file:: 43 | 44 | // foo.hpp 45 | class Foo { ... }; 46 | new_clone( const Foo& ) { ... } 47 | delete_clone( const Foo* ) { ... } 48 | 49 | // x.hpp 50 | class Foo; // Foo is incomplete here 51 | class X { ptr_deque container; ... } 52 | 53 | // x.cpp 54 | #include 55 | #include // now Foo is not incomplete anymore 56 | ... 57 | 58 | 59 | 60 | Why do iterator-range inserts give the strong exception-safety guarantee? 61 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 62 | 63 | Is this not very inefficient? It is because it is actually affordable to 64 | do so; the overhead is one heap-allocation which is relatively small 65 | compared to cloning N objects. 66 | 67 | What is the _`polymorphic class problem`? 68 | +++++++++++++++++++++++++++++++++++++++++ 69 | 70 | The problem refers to the relatively troublesome way C++ supports Object 71 | Oriented programming in connection with containers of pointers to 72 | polymorphic objects. In a language without garbage collection, you end up 73 | using either a container of smart pointers or a container that takes 74 | ownership of the pointers. The hard part is to find a safe, fast and 75 | elegant solution. 76 | 77 | Are the pointer containers faster and do they have a better memory footprint than a container of smart pointers? 78 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 79 | 80 | The short answer is yes: they are faster and they do use less memory; in 81 | fact, they are the only way to obtain the zero-overhead hallmark of C++. 82 | Smart pointers usually have one word or more of memory overhead per 83 | pointer because a reference count must be maintained. And since the 84 | reference count must be maintained, there is also a runtime-overhead. If 85 | your objects are big, then the memory overhead is often negligible, but if 86 | you have many small objects, it is not. Further reading can be found in 87 | these references: `[11] `_ and `[12] `_. 88 | 89 | When the stored pointers cannot be ``0``, how do I allow this "empty" behavior anyway? 90 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 91 | 92 | Storing a null-pointer among a list of pointers does not fit well into the Object Oriented paradigm. 93 | The most elegant design is to use the Null-Object Pattern where one basically makes a concrete 94 | class with dummy implementations of the virtual functions. See `[13] `_ for details. 95 | 96 | .. raw:: html 97 | 98 |
99 | 100 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 101 | 102 | __ http://www.boost.org/LICENSE_1_0.txt 103 | 104 | 105 | -------------------------------------------------------------------------------- /doc/headers.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | =============== 8 | Library headers 9 | =============== 10 | 11 | ======================================================= ============================================================= 12 | **Header** **Includes** 13 | 14 | ```` classes heap_clone_allocator_ and view_clone_allocator_ 15 | and functions ``new_clone()`` and ``delete_clone()`` 16 | 17 | ```` class `ptr_deque `_ (and ``std::deque``) 18 | 19 | ```` class `ptr_list `_ (and ``std::list``) 20 | 21 | ```` class `ptr_vector `_ (and ``std::vector``) 22 | 23 | ```` class `ptr_array `_ (and ``boost::array``) 24 | 25 | ```` classes `ptr_set `_ and `ptr_multiset `_ 26 | (and ``std::set`` and ``std::multiset``) 27 | 28 | ```` classes `ptr_map `_ and `ptr_multimap `_ 29 | (and ``std::map`` and ``std::multimap``) 30 | 31 | ```` functions `ptr_back_inserter `_, `ptr_front_inserter `_ and `ptr_inserter `_ 32 | 33 | ```` all classes 34 | 35 | ```` class `ptr_sequence_adapter `_ 36 | 37 | ```` classes `ptr_set_adapter `_ and `ptr_multiset_adapter `_ 38 | 39 | ```` classes `ptr_map_adapter `_ and `ptr_multimap_adapter `_ 40 | 41 | ```` classes `bad_ptr_container_operation`_, `bad_index`_ and `bad_pointer`_ 42 | ```` class `indirect_fun`_ 43 | 44 | ```` class `nullable`_ 45 | 46 | ```` class `ptr_deque `_ with serialization support 47 | 48 | ```` class `ptr_list `_ with serialization support 49 | 50 | ```` class `ptr_vector `_ with serialization support 51 | 52 | ```` class `ptr_array `_ with serialization support 53 | 54 | ```` classes `ptr_set `_ and `ptr_multiset `_ with serialization support 55 | 56 | ```` classes `ptr_map `_ and `ptr_multimap `_ with serialization support 57 | 58 | ```` all classes with serialization support 59 | 60 | ======================================================= ============================================================= 61 | 62 | .. _`heap_clone_allocator`: reference.html#the-clone-allocator-concept 63 | .. _`view_clone_allocator`: reference.html#the-clone-allocator-concept 64 | .. _`bad_ptr_container_operation`: reference.html#exception-classes 65 | .. _`bad_index`: reference.html#exception-classes 66 | .. _`bad_pointer`: reference.html#exception-classes 67 | .. _`nullable`: reference.html#class-nullable 68 | .. _`indirect_fun`: indirect_fun.html 69 | 70 | 71 | **Navigate:** 72 | 73 | - `home `_ 74 | - `reference `_ 75 | 76 | .. raw:: html 77 | 78 |
79 | 80 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 81 | 82 | __ http://www.boost.org/LICENSE_1_0.txt 83 | 84 | 85 | -------------------------------------------------------------------------------- /doc/indirect_fun.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Indirected functions 8 | -------------------- 9 | 10 | It is quite common that we have two pointers and what to compare the 11 | pointed to objects. Also, we have usually already defined how 12 | to compare the objects. So to avoid some tedious boiler-plate code 13 | this library defines predicates that apply an indirection before comparing. 14 | 15 | When the container uses ``void*`` internally, we can use the 16 | class ``void_ptr_indirect_fun``; otherwise we use the class 17 | ``indirect_fun``. 18 | 19 | **Example:** :: 20 | 21 | std::string* bar = new std::string("bar"); 22 | std::string* foo = new std::string("foo"); 23 | BOOST_ASSERT( indirect_fun< std::less >()( bar, foo ) == true ); 24 | BOOST_ASSERT( make_indirect_fun( std::less() )( foo, bar ) == false ); 25 | 26 | void* vptr1 = ptr1; 27 | void* vptr2 = ptr2; 28 | void_ptr_indirect_fun< std::less, std::string> cast_fun; 29 | BOOST_CHECK( cast_fun( vptr1, vptr2 ) == true ); 30 | 31 | **See also:** 32 | 33 | - `result_of `_ 34 | - `pointee `_ 35 | - `ptr_set `_ 36 | - `ptr_multiset `_ 37 | 38 | **Navigate** 39 | 40 | - `home `_ 41 | - `reference `_ 42 | 43 | **Remarks:** 44 | 45 | The class ``indirect_fun`` will work with smart pointers such as `boost::shared_ptr `_ 46 | because of the type traits ``pointee::type`` from the header ````. 47 | 48 | **Synopsis:** 49 | 50 | Since the definition of the predicates is somewhat trivial, only the 51 | first operation is expanded inline. 52 | 53 | :: 54 | 55 | namespace boost 56 | { 57 | 58 | template< class Fun > 59 | struct indirect_fun 60 | { 61 | indirect_fun() : fun(Fun()) 62 | { } 63 | 64 | indirect_fun( Fun f ) : fun(f) 65 | { } 66 | 67 | template< class T > 68 | typename result_of< Fun( typename pointee::type ) >::type 69 | operator()( const T& r ) const 70 | { 71 | return fun( *r ); 72 | } 73 | 74 | template< class T, class U > 75 | typename result_of< Fun( typename pointee::type, 76 | typename pointee::type ) >::type 77 | operator()( const T& r, const U& r2 ) const 78 | { 79 | return fun( *r, *r2 ); 80 | } 81 | 82 | private: 83 | Fun fun; 84 | }; 85 | 86 | template< class Fun > 87 | inline indirect_fun make_indirect_fun( Fun f ) 88 | { 89 | return indirect_fun( f ); 90 | } 91 | 92 | 93 | 94 | template< class Fun, class Arg1, class Arg2 = Arg1 > 95 | struct void_ptr_indirect_fun 96 | { 97 | void_ptr_indirect_fun() : fun(Fun()) 98 | { } 99 | 100 | void_ptr_indirect_fun( Fun f ) : fun(f) 101 | { } 102 | 103 | typename result_of< Fun( Arg1 ) >::type 104 | operator()( const void* r ) const 105 | { 106 | return fun( * static_cast( r ) ); 107 | } 108 | 109 | typename result_of< Fun( Arg1, Arg2 ) >::type 110 | operator()( const void* l, const void* r ) const 111 | { 112 | return fun( * static_cast( l ), * static_cast( r ) ); 113 | } 114 | 115 | private: 116 | Fun fun; 117 | }; 118 | 119 | template< class Fun, class Arg > 120 | inline void_ptr_indirect_fun 121 | make_void_ptr_indirect_fun( Fun f ) 122 | { 123 | return void_ptr_indirect_fun( f ); 124 | } 125 | 126 | } // namespace 'boost' 127 | 128 | .. raw:: html 129 | 130 |
131 | 132 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 133 | 134 | __ http://www.boost.org/LICENSE_1_0.txt 135 | 136 | 137 | -------------------------------------------------------------------------------- /doc/intro.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 16 |
17 | Introduction 18 | 19 | 20 | This library provides standard-like containers that are suitable 21 | for storing pointers to both polymorphic and non-polymorphic objects. 22 | For each of the standard containers there is a pointer container 23 | equivalent that takes ownership of the stored pointers in an exception 24 | safe manner. In this respect it is intended to solve 25 | the so-called polymorphic class problem. 26 | 27 | 28 | The main advantages are 29 | 30 | Exception-safe and fool proof pointer storage and manipulation.. 31 | Exception-guarantees are generally much better than with standard containers (at least the strong guarantee 32 | Notational convinience compared to the use of containers of smart pointers. 33 | Iterators are automatically indirected so the comparison operations can be kept 34 | on object basis instead of making/adding pointer based variants. 35 | No memory-overhead as containers of smart_pointers can have. 36 | Faster than using containers of smart pointers. 37 | Provides an elegant solution to vector< vector > performance 38 | problems; simply use ptr_vector< vector > 39 | 40 | 41 | Below is given some example that show how the usage compares to a container of smart pointers: 42 | 43 | using namespace boost; 44 | using namespace std; 45 | 46 | class Poly 47 | { 48 | public: 49 | virtual ~Poly() {} 50 | void foo() { doFoo(); } 51 | private: 52 | virtual void doFoo() 53 | { 54 | int i; 55 | ++i; 56 | } 57 | }; 58 | 59 | // 60 | // one doesn't need to introduce new names or live with long ones 61 | // 62 | typedef shared_ptr PolyPtr; 63 | 64 | // 65 | // one doesn't need to write this anymore 66 | // 67 | struct PolyPtrOps 68 | { 69 | void operator()( const PolyPtr & a ) 70 | { a->foo(); } 71 | }; 72 | 73 | int main() 74 | { 75 | enum { size = 2000000 }; 76 | vector svec 77 | ptr_vector pvec; 78 | 79 | for( int i = 0; i < size; ++i ) 80 | { 81 | svec.push_back( PolyPtr( new Poly ) ); 82 | pvec.push_back( new Poly ); // no extra syntax 83 | } 84 | 85 | for_each( svec.begin(), svec.end(), PolyPtrOps() ); 86 | 87 | for_each( pvec.begin(), pvec.end(), mem_fun_ref( &Poly::foo ) ); 88 | } 89 | 90 | 91 |
92 | -------------------------------------------------------------------------------- /doc/ptr_container.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/ptr_container/fa5071af867bfd2480e3b004a4bee27127b951b6/doc/ptr_container.rst -------------------------------------------------------------------------------- /doc/ptr_container.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 16 | 18 | 20 | 21 | 22 | Thorsten 23 | Ottosen 24 | 25 | 26 | 27 | 2003 28 | Thorsten Ottosen 29 | 30 | 31 | 32 | Permission to copy, use, sell and distribute this software 33 | is granted provided this copyright notice appears in all copies. 34 | Permission to modify the code and to distribute modified code is 35 | granted provided this copyright notice appears in all copies, and 36 | a notice that the code was modified is included with the copyright 37 | notice. 38 | 39 | This software is provided "as is" without express or 40 | implied warranty, and with no claim as to its suitability for any 41 | purpose. 42 | 43 | 44 | 45 | This library provides standard-like containers that are suitable 46 | for storing pointers to both polymorphic and non-polymorphic objects. 47 | 48 | 49 | 50 | 51 | Boost Pointer Container Library 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /doc/ptr_deque.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_deque`` 8 | -------------------- 9 | 10 | A ``ptr_deque`` is a pointer container that uses an underlying ``std:deque`` 11 | to store the pointers. 12 | 13 | **Hierarchy:** 14 | 15 | - `reversible_ptr_container `_ 16 | 17 | - `ptr_sequence_adapter `_ 18 | 19 | - `ptr_vector `_ 20 | - `ptr_list `_ 21 | - ``ptr_deque`` 22 | - `ptr_array `_ 23 | 24 | **Navigate:** 25 | 26 | - `home `_ 27 | - `reference `_ 28 | 29 | 30 | **Synopsis:** 31 | 32 | .. parsed-literal:: 33 | 34 | namespace boost 35 | { 36 | 37 | template 38 | < 39 | class T, 40 | class CloneAllocator = heap_clone_allocator 41 | class Allocator = std::allocator 42 | > 43 | class ptr_deque : public ptr_sequence_adapter 44 | < 45 | T, 46 | std::deque, 47 | CloneAllocator 48 | > 49 | { 50 | 51 | public: // `element access`_ 52 | T& operator[]( size_type n ); 53 | const T& operator[]( size_type n ) const; 54 | T& at( size_type n ); 55 | const T& at( size_type n ) const; 56 | 57 | public: // modifiers_ 58 | void push_front( T* x ); 59 | template< class U > 60 | void push_front( compatible-smart-ptr x ); 61 | auto_type pop_front(); 62 | 63 | public: // `pointer container requirements`_ 64 | auto_type replace( size_type idx, T* x ); 65 | template< class U > 66 | auto_type replace( size_type idx, compatible-smart-ptr x ); 67 | bool is_null( size_type idx ) const; 68 | 69 | }; 70 | 71 | } // namespace 'boost' 72 | 73 | 74 | .. _`reversible_ptr_container`: reversible_ptr_container.html 75 | 76 | .. _`ptr_sequence_adapter`: ptr_sequence_adapter.html 77 | 78 | Semantics 79 | --------- 80 | 81 | .. _modifiers: 82 | 83 | Semantics: modifiers 84 | ^^^^^^^^^^^^^^^^^^^^ 85 | 86 | - ``void push_front( T* x );`` 87 | 88 | - Requirements: ``x != 0`` 89 | 90 | - Effects: Inserts the pointer into container and takes ownership of it 91 | 92 | - Throws: ``bad_pointer`` if ``x == 0`` 93 | 94 | - Exception safety: Strong guarantee 95 | 96 | - ``template< class U > void push_front( compatible-smart-ptr x );`` 97 | 98 | - Effects: ``push_front( x.release() );`` 99 | 100 | .. 101 | - ``void push_front( const T& x );`` 102 | 103 | - Effects: push_front( allocate_clone( x ) ); 104 | 105 | - Exception safety: Strong guarantee 106 | 107 | - ``auto_type pop_front():`` 108 | 109 | - Requirements:``not empty()`` 110 | 111 | - Effects: Removes the first element in the container 112 | 113 | - Postconditions: ``size()`` is one less 114 | 115 | - Throws: ``bad_ptr_container_operation`` if ``empty() == true`` 116 | 117 | - Exception safety: Strong guarantee 118 | 119 | 120 | .. _`element access`: 121 | 122 | Semantics: element access 123 | ^^^^^^^^^^^^^^^^^^^^^^^^^ 124 | 125 | - ``T& operator[]( size_type n );`` 126 | - ``const T& operator[]( size_type n ) const;`` 127 | 128 | - Requirements: ``n < size()`` 129 | 130 | - Effects: Returns a reference to the ``n``'th element 131 | 132 | - Throws: Nothing 133 | 134 | - ``T& at( size_type n );`` 135 | - ``const T& at( size_type n ) const;`` 136 | 137 | - Requirements: ``n < size()`` 138 | 139 | - Effects: Returns a reference to the ``n``'th element 140 | 141 | - Throws: ``bad_index`` if ``n >=size()`` 142 | 143 | 144 | .. _`pointer container requirements`: 145 | 146 | Semantics: pointer container requirements 147 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 148 | 149 | - ``auto_type replace( size_type idx, T* x );`` 150 | 151 | - Requirements: `` x != 0 and idx < size()`` 152 | 153 | - Effects: returns the object indexed by ``idx`` and replaces it with ``x``. 154 | 155 | - Throws: ``bad_index`` if ``idx >= size()`` and ``bad_pointer`` if ``x == 0``. 156 | 157 | - Exception safety: Strong guarantee 158 | 159 | - ``template< class U > auto_type replace( size_type idx, compatible-smart-ptr x );`` 160 | 161 | - Effects: ``return replace( idx, x.release() );`` 162 | 163 | - ``bool is_null( size_type idx ) const;`` 164 | 165 | - Requirements: ``idx < size()`` 166 | 167 | - Effects: returns whether the pointer at index ``idx`` is null 168 | 169 | - Exception safety: Nothrow guarantee 170 | 171 | .. raw:: html 172 | 173 |
174 | 175 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 176 | 177 | __ http://www.boost.org/LICENSE_1_0.txt 178 | 179 | 180 | -------------------------------------------------------------------------------- /doc/ptr_inserter.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Insert Iterators 8 | ---------------- 9 | 10 | When you work with normal value-based containers and algorithms, you often 11 | use insert iterators :: 12 | 13 | std::list coll1; 14 | // ... 15 | std::vector coll2; 16 | std::copy( coll1.begin(), coll1.end(), 17 | back_inserter(coll2) ); 18 | 19 | With the special insert iterators for pointer containers, 20 | you can do exactly the same :: 21 | 22 | boost::ptr_list coll1; 23 | // ... 24 | boost::ptr_vector coll2; 25 | std::copy( coll1.begin(), coll1.end(), 26 | boost::ptr_container::ptr_back_inserter(coll2) ); 27 | 28 | Each element is cloned and inserted into the container. Furthermore, 29 | if the source range iterates over pointers 30 | instead of references, ``NULL`` pointers 31 | can be transfered as well. 32 | 33 | **Navigate** 34 | 35 | - `home `_ 36 | - `reference `_ 37 | 38 | **Synopsis:** 39 | 40 | :: 41 | 42 | namespace boost 43 | { 44 | namespace ptr_container 45 | { 46 | 47 | template< class PtrContainer > 48 | class ptr_back_insert_iterator; 49 | 50 | template< class PtrContainer > 51 | class ptr_front_insert_iterator; 52 | 53 | template< class PtrContainer > 54 | class ptr_insert_iterator; 55 | 56 | template< class PtrContainer > 57 | ptr_back_insert_iterator 58 | ptr_back_inserter( PtrContainer& cont ); 59 | 60 | template< class PtrContainer > 61 | ptr_front_insert_iterator 62 | ptr_front_inserter( PtrContainer& cont ); 63 | 64 | template< class PtrContainer > 65 | ptr_insert_iterator 66 | ptr_inserter( PtrContainer& cont, typename PtrContainer::iterator before ); 67 | 68 | } // namespace 'ptr_container' 69 | } // namespace 'boost' 70 | 71 | .. raw:: html 72 | 73 |
74 | 75 | :Copyright: Thorsten Ottosen 2008. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 76 | 77 | __ http://www.boost.org/LICENSE_1_0.txt 78 | 79 | 80 | -------------------------------------------------------------------------------- /doc/ptr_list.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_list`` 8 | ------------------ 9 | 10 | A ``ptr_list`` is a pointer container that uses an underlying ``std:list`` 11 | to store the pointers. 12 | 13 | **Hierarchy:** 14 | 15 | - `reversible_ptr_container `_ 16 | 17 | - `ptr_sequence_adapter `_ 18 | 19 | - `ptr_vector `_ 20 | - ``ptr_list`` 21 | - `ptr_deque `_ 22 | - `ptr_array `_ 23 | 24 | **Navigate:** 25 | 26 | - `home `_ 27 | - `reference `_ 28 | 29 | 30 | **Synopsis:** 31 | 32 | .. parsed-literal:: 33 | 34 | namespace boost 35 | { 36 | 37 | template 38 | < 39 | class T, 40 | class CloneAllocator = heap_clone_allocator, 41 | class Allocator = std::allocator 42 | > 43 | class ptr_list : public ptr_sequence_adapter 44 | < 45 | T, 46 | std::list, 47 | CloneAllocator 48 | > 49 | { 50 | 51 | public: // modifiers_ 52 | void push_front( T* x ); 53 | template< class U > 54 | void push_front( compatible-smart-ptr x ); 55 | auto_type pop_front(); 56 | 57 | public: // `list operations`_ 58 | void reverse(); 59 | 60 | }; // class 'ptr_list' 61 | 62 | } // namespace 'boost' 63 | 64 | 65 | Semantics 66 | --------- 67 | 68 | .. _modifiers: 69 | 70 | Semantics: modifiers 71 | ^^^^^^^^^^^^^^^^^^^^ 72 | 73 | - ``void push_front( T* x );`` 74 | 75 | - Requirements: ``x != 0`` 76 | 77 | - Effects: Inserts the pointer into container and takes ownership of it 78 | 79 | - Throws: ``bad_pointer`` if ``x == 0`` 80 | 81 | - Exception safety: Strong guarantee 82 | 83 | - ``template< class U > void push_front( compatible-smart-ptr x );`` 84 | 85 | - Effects: ``push_front( x.release() );`` 86 | 87 | .. 88 | - ``void push_front( const T& x );`` 89 | 90 | - Effects: push_front( allocate_clone( x ) ); 91 | 92 | - Exception safety: Strong guarantee 93 | 94 | - ``auto_type pop_front():`` 95 | 96 | - Requirements:``not empty()`` 97 | 98 | - Effects: Removes the first element in the container 99 | 100 | - Postconditions: ``size()`` is one less 101 | 102 | - Throws: ``bad_ptr_container_operation`` if ``empty() == true`` 103 | 104 | - Exception safety: Strong guarantee 105 | 106 | .. _`list operations`: 107 | 108 | Semantics: list operations 109 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 110 | 111 | .. 112 | - ``void splice( iterator before, ptr_list& x );`` 113 | 114 | - Requirements:``&x != this`` 115 | 116 | - Effects: inserts the all of ``x``'s elements before ``before`` 117 | 118 | - Postconditions: ``x.empty()`` 119 | 120 | - Throws: nothing 121 | 122 | - Remark: prefer this to ``transfer( before, x );`` 123 | 124 | - ``void splice( iterator before, ptr_list& x, iterator i );`` 125 | 126 | - Not ready yet 127 | 128 | - ``void splice( iterator before, ptr_list& x, iterator first, iterator last );`` 129 | 130 | - Not ready yet 131 | 132 | - ``void merge( ptr_list& x );`` 133 | 134 | - Not ready yet 135 | 136 | - ``template< typename Compare > 137 | void merge( ptr_list& x, Compare comp );`` 138 | 139 | - Not ready yet 140 | 141 | - ``void reverse();`` 142 | 143 | - Effects: reverses the underlying sequence 144 | 145 | - Throws: nothing 146 | 147 | .. raw:: html 148 | 149 |
150 | 151 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 152 | 153 | __ http://www.boost.org/LICENSE_1_0.txt 154 | 155 | 156 | -------------------------------------------------------------------------------- /doc/ptr_map.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_map`` 8 | ----------------- 9 | 10 | A ``ptr_map`` is a pointer container that uses an underlying ``std::map`` 11 | to store the pointers. 12 | 13 | **Hierarchy:** 14 | 15 | - `reversible_ptr_container `_ 16 | 17 | - `associative_ptr_container `_ 18 | 19 | - `ptr_set_adapter `_ 20 | - `ptr_multiset_adapter `_ 21 | - `ptr_map_adapter `_ 22 | - `ptr_multi_map_adapter `_ 23 | 24 | - `ptr_set `_ 25 | - `ptr_multi_set `_ 26 | - ``ptr_map`` 27 | - `ptr_multimap `_ 28 | 29 | **Navigate:** 30 | 31 | - `home `_ 32 | - `reference `_ 33 | 34 | 35 | **Synopsis:** 36 | 37 | .. parsed-literal:: 38 | 39 | 40 | namespace boost 41 | { 42 | 43 | template 44 | < 45 | class Key, 46 | class T, 47 | class Compare = std::less, 48 | class CloneAllocator = heap_clone_allocator, 49 | class Allocator = std::allocator< std::pair > 50 | > 51 | class ptr_map : public ptr_map_adapter 52 | < 53 | T, 54 | std::map, 55 | CloneAllocator 56 | > 57 | { 58 | // see references 59 | 60 | }; // class 'ptr_map' 61 | 62 | } // namespace 'boost' 63 | 64 | .. raw:: html 65 | 66 |
67 | 68 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 69 | 70 | __ http://www.boost.org/LICENSE_1_0.txt 71 | 72 | 73 | -------------------------------------------------------------------------------- /doc/ptr_multimap.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_multimap`` 8 | ---------------------- 9 | 10 | A ``ptr_multimap`` is a pointer container that uses an underlying ``std::multimap`` 11 | to store the pointers. 12 | 13 | 14 | **Hierarchy:** 15 | 16 | - `reversible_ptr_container `_ 17 | 18 | - `associative_ptr_container `_ 19 | 20 | - `ptr_set_adapter `_ 21 | - `ptr_multiset_adapter `_ 22 | - `ptr_map_adapter `_ 23 | - `ptr_multi_map_adapter `_ 24 | 25 | - `ptr_set `_ 26 | - `ptr_multi_set `_ 27 | - `ptr_map `_ 28 | - ``ptr_multimap`` 29 | 30 | **Navigate:** 31 | 32 | - `home `_ 33 | - `reference `_ 34 | 35 | .. _reversible_ptr_container: reversible_ptr_container.html 36 | .. _associative_ptr_container: associative_ptr_container.html 37 | .. _ptr_multimap_adapter: ptr_multimap_adapter.html 38 | 39 | 40 | 41 | **Synopsis:** 42 | 43 | .. parsed-literal:: 44 | 45 | 46 | namespace boost 47 | { 48 | template 49 | < 50 | class Key, 51 | class T, 52 | class Compare = std::less, 53 | class CloneAllocator = heap_clone_allocator, 54 | class Allocator = std::allocator< std::pair > 55 | > 56 | class ptr_multimap : public ptr_multimap_adapter 57 | < 58 | T, 59 | std::multimap, 60 | CloneAllocator 61 | > 62 | { 63 | // see references 64 | 65 | }; // class 'ptr_multimap' 66 | 67 | } // namespace 'boost' 68 | 69 | 70 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 71 | 72 | __ http://www.boost.org/LICENSE_1_0.txt 73 | 74 | 75 | -------------------------------------------------------------------------------- /doc/ptr_multiset.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_multiset`` 8 | ---------------------- 9 | 10 | A ``ptr_multiset`` is a pointer container that uses an underlying ``std::multiset`` 11 | to store the pointers. 12 | 13 | **Hierarchy:** 14 | 15 | - `reversible_ptr_container `_ 16 | 17 | - `associative_ptr_container `_ 18 | 19 | - `ptr_set_adapter `_ 20 | - `ptr_multiset_adapter `_ 21 | - `ptr_map_adapter `_ 22 | - `ptr_multi_map_adapter `_ 23 | 24 | - `ptr_set `_ 25 | - ``ptr_multi_set`` 26 | - `ptr_map `_ 27 | - `ptr_multimap `_ 28 | 29 | **See also:** 30 | 31 | - `void_ptr_indirect_fun `_ 32 | 33 | **Navigate:** 34 | 35 | - `home `_ 36 | - `reference `_ 37 | 38 | 39 | **Synopsis:** 40 | 41 | .. parsed-literal:: 42 | 43 | 44 | namespace boost 45 | { 46 | 47 | template 48 | < 49 | class Key, 50 | class Compare = std::less, 51 | class CloneAllocator = heap_clone_allocator, 52 | class Allocator = std::allocator 53 | > 54 | class ptr_multiset : public ptr_multiset_adapter 55 | < 56 | Key, 57 | std::multiset,Allocator>, 58 | CloneAllocator 59 | > 60 | { 61 | // see references 62 | 63 | }; // class 'ptr_multiset' 64 | 65 | } // namespace 'boost' 66 | 67 | **Remarks:** 68 | 69 | - Using ``nullable`` as ``Key`` is meaningless and is not allowed 70 | 71 | .. raw:: html 72 | 73 |
74 | 75 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 76 | 77 | __ http://www.boost.org/LICENSE_1_0.txt 78 | 79 | 80 | -------------------------------------------------------------------------------- /doc/ptr_multiset_adapter.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_multiset_adapter`` 8 | ------------------------------ 9 | 10 | This class is used to build custom pointer containers with 11 | an underlying multiset-like container. The interface of the class is an extension 12 | of the interface from ``associative_ptr_container``. 13 | 14 | **Hierarchy:** 15 | 16 | - `reversible_ptr_container `_ 17 | 18 | - `associative_ptr_container `_ 19 | 20 | - `ptr_set_adapter `_ 21 | - ``ptr_multiset_adapter`` 22 | - `ptr_map_adapter `_ 23 | - `ptr_multi_map_adapter `_ 24 | 25 | - `ptr_set `_ 26 | - `ptr_multi_set `_ 27 | - `ptr_map `_ 28 | - `ptr_multimap `_ 29 | 30 | **Navigate:** 31 | 32 | - `home `_ 33 | - `reference `_ 34 | 35 | **Synopsis:** 36 | 37 | .. parsed-literal:: 38 | 39 | 40 | namespace boost 41 | { 42 | template 43 | < 44 | class Key, 45 | class VoidPtrMultiSet, 46 | class CloneAllocator = heap_clone_allocator 47 | > 48 | class ptr_multiset_adapter 49 | { 50 | 51 | public: // `modifiers`_ 52 | iterator insert( Key* x ); 53 | template< class Key2 > 54 | iterator insert( compatible-smart-ptr x ); 55 | 56 | public: // `pointer container requirements`_ 57 | void transfer( iterator object, ptr_multiset_adapter& from ); 58 | size_type transfer( iterator first, iterator last, ptr_multiset_adapter& from ); 59 | template< class Range > 60 | size_type transfer( const Range& r, ptr_multiset_adapter& from ); 61 | void transfer( ptr_multiset_adapter& from ); 62 | 63 | }; // class 'ptr_multiset_adapter' 64 | 65 | } // namespace 'boost' 66 | 67 | 68 | Semantics 69 | --------- 70 | 71 | .. _`modifiers`: 72 | 73 | Semantics: modifiers 74 | ^^^^^^^^^^^^^^^^^^^^ 75 | 76 | - ``iterator insert( key_type* x );`` 77 | 78 | - Requirements: ``x != 0`` 79 | 80 | - Effects: Takes ownership of ``x``. The returned iterator points to the element with key ``x``. 81 | 82 | - Throws: bad_pointer if ``x == 0`` 83 | 84 | - Exception safety: Strong guarantee 85 | 86 | 87 | - ``template< class Key2 > iterator insert( compatible-smart-ptr x );`` 88 | 89 | - Effects: ``return insert( x.release() );`` 90 | 91 | .. 92 | - ``iterator insert( const key_type& x );`` 93 | 94 | - Effects: ``return insert( allocate_clone( x ) );`` 95 | 96 | - Exception safety: Strong guarantee 97 | 98 | .. _`pointer container requirements`: 99 | 100 | Semantics: pointer container requirements 101 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 102 | 103 | - ``void transfer( iterator object, ptr_multiset_adapter& from );`` 104 | 105 | - Requirements: ``not from.empty()`` 106 | 107 | - Effects: Inserts the object defined by ``object`` into the container and remove it from ``from``. 108 | 109 | - Postconditions: ``size()`` is one more, ``from.size()`` is one less. 110 | 111 | - Exception safety: Strong guarantee 112 | 113 | - ``void transfer( iterator first, iterator last, ptr_multiset_adapter& from );`` 114 | 115 | - Requirements: ``not from.empty()`` 116 | 117 | - Effects: Inserts the objects defined by the range ``[first,last)`` into the container and remove it from ``from``. 118 | 119 | - Postconditions: Let ``N == std::distance(first,last);`` then ``size()`` is ``N`` more, ``from.size()`` is ``N`` less. 120 | 121 | - Exception safety: Basic guarantee 122 | 123 | - ``template< class Range > void transfer( const Range& r, ptr_multiset_adapter& from );`` 124 | 125 | - Effects: ``transfer( boost::begin(r), boost::end(r), from );`` 126 | 127 | - ``void transfer( ptr_multiset_adapter& from );`` 128 | 129 | - Effects: ``transfer( from.begin(), from.end(), from );``. 130 | 131 | - Postconditions: ``from.empty();`` 132 | 133 | - Exception safety: Basic guarantee 134 | 135 | .. raw:: html 136 | 137 |
138 | 139 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 140 | 141 | __ http://www.boost.org/LICENSE_1_0.txt 142 | 143 | 144 | -------------------------------------------------------------------------------- /doc/ptr_set.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_set`` 8 | ----------------- 9 | 10 | A ``ptr_set`` is a pointer container that uses an underlying ``std::set`` 11 | to store the pointers. 12 | 13 | **Hierarchy:** 14 | 15 | - `reversible_ptr_container `_ 16 | 17 | - `associative_ptr_container `_ 18 | 19 | - `ptr_set_adapter `_ 20 | - `ptr_multiset_adapter `_ 21 | - `ptr_map_adapter `_ 22 | - `ptr_multi_map_adapter `_ 23 | 24 | - ``ptr_set`` 25 | - `ptr_multi_set `_ 26 | - `ptr_map `_ 27 | - `ptr_multimap `_ 28 | 29 | 30 | **See also:** 31 | 32 | - `void_ptr_indirect_fun `_ 33 | 34 | **Navigate:** 35 | 36 | - `home `_ 37 | - `reference `_ 38 | 39 | 40 | **Synopsis:** 41 | 42 | .. parsed-literal:: 43 | 44 | 45 | namespace boost 46 | { 47 | 48 | template 49 | < 50 | class Key, 51 | class Compare = std::less, 52 | class CloneAllocator = heap_clone_allocator, 53 | class Allocator = std::allocator 54 | > 55 | class ptr_set : public ptr_set_adapter 56 | < 57 | Key, 58 | std::set,Allocator>, 60 | CloneAllocator 61 | > 62 | { 63 | // see references 64 | 65 | }; // class 'ptr_set' 66 | 67 | } // namespace 'boost' 68 | 69 | **Remarks:** 70 | 71 | - Using ``nullable`` as ``Key`` is meaningless and is not allowed 72 | 73 | .. raw:: html 74 | 75 |
76 | 77 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 78 | 79 | __ http://www.boost.org/LICENSE_1_0.txt 80 | 81 | 82 | -------------------------------------------------------------------------------- /doc/ptr_set_adapter.rst: -------------------------------------------------------------------------------- 1 | ++++++++++++++++++++++++++++++++++ 2 | |Boost| Pointer Container Library 3 | ++++++++++++++++++++++++++++++++++ 4 | 5 | .. |Boost| image:: boost.png 6 | 7 | Class ``ptr_set_adapter`` 8 | ------------------------- 9 | 10 | This class is used to build custom pointer containers with 11 | an underlying set-like container. The interface of the class is an extension 12 | of the interface from ``associative_ptr_container``. 13 | 14 | **Hierarchy:** 15 | 16 | - `reversible_ptr_container `_ 17 | 18 | - `associative_ptr_container `_ 19 | 20 | - ``ptr_set_adapter`` 21 | - `ptr_multiset_adapter `_ 22 | - `ptr_map_adapter `_ 23 | - `ptr_multi_map_adapter `_ 24 | 25 | - `ptr_set `_ 26 | - `ptr_multi_set `_ 27 | - `ptr_map `_ 28 | - `ptr_multimap `_ 29 | 30 | **Navigate:** 31 | 32 | - `home `_ 33 | - `reference `_ 34 | 35 | .. _reversible_ptr_container: reversible_ptr_container.html 36 | .. _associative_ptr_container: associative_ptr_container.html 37 | .. _ptr_set: ptr_set.html 38 | 39 | **Synopsis:** 40 | 41 | .. parsed-literal:: 42 | 43 | 44 | namespace boost 45 | { 46 | template 47 | < 48 | class Key, 49 | class VoidPtrSet, 50 | class CloneAllocator = heap_clone_allocator 51 | > 52 | class ptr_set_adapter 53 | { 54 | 55 | public: // `modifiers`_ 56 | std::pair insert( Key* x ); 57 | template< class Key2 > 58 | std::pair insert( compatible-smart-ptr x ); 59 | 60 | public: // `pointer container requirements`_ 61 | bool transfer( iterator object, ptr_set_adapter& from ); 62 | size_type transfer( iterator first, iterator last, ptr_set_adapter& from ); 63 | template< class Range > 64 | size_type transfer( const Range& r, ptr_set_adapter& from ); 65 | size_type transfer( ptr_set_adapter& from ); 66 | 67 | }; // class 'ptr_set_adapter' 68 | 69 | } // namespace 'boost' 70 | 71 | 72 | Semantics 73 | --------- 74 | 75 | .. _`modifiers`: 76 | 77 | Semantics: modifiers 78 | ^^^^^^^^^^^^^^^^^^^^ 79 | 80 | - ``std::pair insert( key_type* x );`` 81 | 82 | - Requirements: ``x != 0`` 83 | 84 | - Effects: Takes ownership of ``x`` and insert it if there is no equivalent of it already. The ``bool`` part of the return value indicates insertion and the iterator points to the element with key ``x``. 85 | 86 | - Throws: bad_pointer if ``x == 0`` 87 | 88 | - Exception safety: Strong guarantee 89 | 90 | - ``template< class Key2 > std::pair insert( compatible-smart-ptr x );`` 91 | 92 | - Effects: ``return insert( x.release() );`` 93 | 94 | 95 | .. 96 | - ``std::pair insert( const key_type& x );`` 97 | 98 | - Effects: ``return insert( allocate_clone( x ) );`` 99 | 100 | - Exception safety: Strong guarantee 101 | 102 | .. _`pointer container requirements`: 103 | 104 | Semantics: pointer container requirements 105 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 106 | 107 | - ``bool transfer( iterator object, ptr_set_adapter& from );`` 108 | 109 | - Requirements: ``not from.empty()`` 110 | 111 | - Effects: Inserts the object defined by ``object`` into the container and remove it from ``from`` 112 | iff no equivalent object exists. 113 | 114 | - Returns: whether the object was transfered 115 | 116 | - Exception safety: Strong guarantee 117 | 118 | - ``void transfer( iterator first, iterator last, ptr__set_adapter& from );`` 119 | 120 | - Requirements: ``not from.empty()`` 121 | 122 | - Effects: Inserts the objects defined by the range ``[first,last)`` into the container and remove it from ``from``. 123 | An object is only transferred if no equivalent object exists. 124 | 125 | - Returns: the number of transfered objects 126 | 127 | - Exception safety: Basic guarantee 128 | 129 | - ``template< class Range > void transfer( const Range& r, ptr_set_adapter& from );`` 130 | 131 | - Effects: ``return transfer( boost::begin(r), boost::end(r), from );`` 132 | 133 | - ``size_type transfer( ptr_set_adapter& from );`` 134 | 135 | - Effects: ``return transfer( from.begin(), from.end(), from );``. 136 | 137 | .. raw:: html 138 | 139 |
140 | 141 | :Copyright: Thorsten Ottosen 2004-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__). 142 | 143 | __ http://www.boost.org/LICENSE_1_0.txt 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/reversible_ptr_container.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/ptr_container/fa5071af867bfd2480e3b004a4bee27127b951b6/doc/reversible_ptr_container.rst -------------------------------------------------------------------------------- /doc/todo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/ptr_container/fa5071af867bfd2480e3b004a4bee27127b951b6/doc/todo.txt -------------------------------------------------------------------------------- /include/boost/ptr_container/clone_allocator.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP 13 | #define BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | ///////////////////////////////////////////////////////////////////////// 22 | // Clonable concept 23 | ///////////////////////////////////////////////////////////////////////// 24 | 25 | template< class T > 26 | inline T* new_clone( const T& r ) 27 | { 28 | // 29 | // @remark: if you get a compile-error here, 30 | // it is most likely because you did not 31 | // define new_clone( const T& ) in the namespace 32 | // of T. 33 | // 34 | T* res = new T( r ); 35 | BOOST_ASSERT( typeid(r) == typeid(*res) && 36 | "Default new_clone() sliced object!" ); 37 | return res; 38 | } 39 | 40 | 41 | 42 | template< class T > 43 | inline void delete_clone( const T* r ) 44 | { 45 | checked_delete( r ); 46 | } 47 | 48 | ///////////////////////////////////////////////////////////////////////// 49 | // CloneAllocator concept 50 | ///////////////////////////////////////////////////////////////////////// 51 | 52 | struct heap_clone_allocator 53 | { 54 | template< class U > 55 | static U* allocate_clone( const U& r ) 56 | { 57 | return new_clone( r ); 58 | } 59 | 60 | template< class U > 61 | static void deallocate_clone( const U* r ) 62 | { 63 | delete_clone( r ); 64 | } 65 | 66 | }; 67 | 68 | 69 | 70 | struct view_clone_allocator 71 | { 72 | template< class U > 73 | static U* allocate_clone( const U& r ) 74 | { 75 | return const_cast(&r); 76 | } 77 | 78 | template< class U > 79 | static void deallocate_clone( const U* /*r*/ ) 80 | { 81 | // do nothing 82 | } 83 | }; 84 | 85 | } // namespace 'boost' 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/default_deleter.hpp: -------------------------------------------------------------------------------- 1 | // (C) Copyright Jonathan Turkanis 2004-2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) 4 | 5 | // Contains the definition of move_ptrs::default_deleter, the default 6 | // Deleter template argument to move_ptr. Uses a technique of Daniel 7 | // Wallin to capture the type of a pointer at the time the deleter 8 | // is constructed, so that move_ptrs can delete objects of incomplete 9 | // type by default. 10 | 11 | #ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED 12 | #define BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { namespace ptr_container_detail { namespace move_ptrs { 20 | 21 | namespace ptr_container_detail { 22 | 23 | template 24 | struct deleter_base { 25 | typedef void (*deleter)(T*); 26 | deleter_base(deleter d) { delete_ = d; } 27 | void operator() (T* t) const { delete_(t); } 28 | static deleter delete_; 29 | }; 30 | 31 | template 32 | typename deleter_base::deleter 33 | deleter_base::delete_; 34 | 35 | template 36 | struct scalar_deleter : deleter_base { 37 | typedef deleter_base base; 38 | scalar_deleter() : base(do_delete) { } 39 | static void do_delete(T* t) { checked_delete(t); } 40 | }; 41 | 42 | template 43 | struct array_deleter 44 | : deleter_base::type> 45 | { 46 | typedef typename remove_bounds::type element_type; 47 | typedef deleter_base base; 48 | array_deleter() : base(do_delete) { } 49 | static void do_delete(element_type* t) { checked_array_delete(t); } 50 | }; 51 | 52 | } // End namespace ptr_container_detail. 53 | 54 | template 55 | struct default_deleter 56 | : mpl::if_< 57 | is_array, 58 | ptr_container_detail::array_deleter, 59 | ptr_container_detail::scalar_deleter 60 | >::type 61 | { 62 | default_deleter() { } 63 | template 64 | default_deleter(default_deleter) { } 65 | }; 66 | 67 | } } } // End namespaces ptr_container_detail, move_ptrs, boost. 68 | 69 | #endif // #ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED 70 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/is_convertible.hpp: -------------------------------------------------------------------------------- 1 | // (C) Copyright Thorsten Ottosen 2005 2 | // (C) Copyright Howard Hinnant 2004 3 | // (C) Copyright Jonathan Turkanis 2004 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) 6 | 7 | // 8 | // Contains type traits machinery for incomplete arrays. MPL compatibility 9 | // is included for completeness, but is not necessary for the current 10 | // application. 11 | // 12 | 13 | #ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED 14 | #define BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED 15 | 16 | #include // BOOST_STATIC_CONSTANT. 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace boost { namespace ptr_container_detail { namespace move_ptrs { 30 | 31 | // From Howard Hinnant. 32 | template 33 | struct is_array_convertible { 34 | typedef typename remove_bounds::type t_element; 35 | typedef typename remove_bounds::type u_element; 36 | typedef typename remove_cv::type t_base; 37 | typedef typename remove_cv::type u_base; 38 | typedef typename 39 | mpl::and_< 40 | is_array, 41 | is_array, 42 | is_same, 43 | is_convertible 44 | >::type type; 45 | BOOST_STATIC_CONSTANT(bool, value = type::value); 46 | BOOST_MPL_AUX_LAMBDA_SUPPORT(2, is_array_convertible, (T, U)) 47 | }; 48 | 49 | template 50 | struct is_smart_ptr_convertible 51 | : mpl::if_< 52 | is_array, 53 | is_array_convertible, 54 | is_convertible 55 | >::type 56 | { }; 57 | 58 | #ifndef BOOST_NO_SFINAE 59 | template 60 | struct enable_if_convertible 61 | : enable_if< 62 | is_smart_ptr_convertible, 63 | T 64 | > 65 | { }; 66 | #else 67 | template 68 | struct enable_if_convertible : mpl::identity { }; 69 | #endif 70 | 71 | } } } // End namespaces ptr_container_detail, move_ptrs, boost. 72 | 73 | #endif // #ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED 74 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/map_iterator.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP 13 | #define BOOST_PTR_CONTAINER_MAP_ITERATOR_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined(BOOST_MSVC) 25 | # pragma warning(push) 26 | # pragma warning(disable:4512) // Assignment operator could not be generated. 27 | #endif 28 | 29 | namespace boost 30 | { 31 | namespace ptr_container_detail 32 | { 33 | template< class F, class S > 34 | struct ref_pair 35 | { 36 | typedef F first_type; 37 | typedef S second_type; 38 | 39 | const F& first; 40 | S second; 41 | 42 | template< class F2, class S2 > 43 | ref_pair( const std::pair& p ) 44 | : first(p.first), second(static_cast(p.second)) 45 | { } 46 | 47 | template< class RP > 48 | ref_pair( const RP* rp ) 49 | : first(rp->first), second(rp->second) 50 | { } 51 | 52 | const ref_pair* operator->() const 53 | { 54 | return this; 55 | } 56 | 57 | friend inline bool operator==( ref_pair l, ref_pair r ) 58 | { 59 | return l.first == r.first && 60 | boost::equal_pointees( l.second, r.second ); 61 | } 62 | 63 | friend inline bool operator!=( ref_pair l, ref_pair r ) 64 | { 65 | return !( l == r ); 66 | } 67 | 68 | friend inline bool operator<( ref_pair l, ref_pair r ) 69 | { 70 | if( l.first == r.first ) 71 | return boost::less_pointees( l.second, r.second ); 72 | else 73 | return l.first < r.first; 74 | } 75 | 76 | friend inline bool operator>( ref_pair l, ref_pair r ) 77 | { 78 | return r < l; 79 | } 80 | 81 | friend inline bool operator<=( ref_pair l, ref_pair r ) 82 | { 83 | return !(r < l); 84 | } 85 | 86 | friend inline bool operator>=( ref_pair l, ref_pair r ) 87 | { 88 | return !(l < r); 89 | } 90 | 91 | }; 92 | } 93 | 94 | template< 95 | class I, // base iterator 96 | class F, // first type, key type 97 | class S // second type, mapped type 98 | > 99 | class ptr_map_iterator : 100 | public boost::iterator_adaptor< ptr_map_iterator, I, 101 | ptr_container_detail::ref_pair, 102 | use_default, 103 | ptr_container_detail::ref_pair > 104 | { 105 | typedef boost::iterator_adaptor< ptr_map_iterator, I, 106 | ptr_container_detail::ref_pair, 107 | use_default, 108 | ptr_container_detail::ref_pair > 109 | base_type; 110 | 111 | 112 | public: 113 | ptr_map_iterator() : base_type() 114 | { } 115 | 116 | explicit ptr_map_iterator( const I& i ) : base_type(i) 117 | { } 118 | 119 | template< class I2, class F2, class S2 > 120 | ptr_map_iterator( const ptr_map_iterator& r ) 121 | : base_type(r.base()) 122 | { } 123 | 124 | }; // class 'ptr_map_iterator' 125 | 126 | } 127 | 128 | #if defined(BOOST_MSVC) 129 | # pragma warning(pop) 130 | #endif 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/meta_functions.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_DETAIL_META_FUNCTIONS 13 | #define BOOST_PTR_CONTAINER_DETAIL_META_FUNCTIONS 14 | 15 | #include 16 | #include 17 | 18 | namespace boost 19 | { 20 | namespace ptr_container_detail 21 | { 22 | template< class T > 23 | struct select_value_compare 24 | { 25 | typedef typename T::value_compare type; 26 | }; 27 | 28 | template< class T > 29 | struct select_key_compare 30 | { 31 | typedef typename T::key_compare type; 32 | }; 33 | 34 | template< class T > 35 | struct select_hasher 36 | { 37 | typedef typename T::hasher type; 38 | }; 39 | 40 | template< class T > 41 | struct select_key_equal 42 | { 43 | typedef typename T::key_equal type; 44 | }; 45 | 46 | template< class T > 47 | struct select_iterator 48 | { 49 | typedef typename T::iterator type; 50 | }; 51 | 52 | template< class T > 53 | struct select_local_iterator 54 | { 55 | typedef typename T::local_iterator type; 56 | }; 57 | 58 | template< class T > 59 | struct select_const_local_iterator 60 | { 61 | typedef typename T::const_local_iterator type; 62 | }; 63 | } 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/move.hpp: -------------------------------------------------------------------------------- 1 | // (C) Copyright Daniel Wallin 2004. 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) 4 | 5 | // Contains the definitions of the class template move_source and the function 6 | // template move, which together make move pointers moveable. 7 | 8 | #ifndef BOOST_MOVE_HPP_INCLUDED 9 | #define BOOST_MOVE_HPP_INCLUDED 10 | 11 | namespace boost { namespace ptr_container_detail { 12 | 13 | namespace move_ptrs { 14 | 15 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 16 | #pragma warning(push) 17 | #pragma warning(disable:4512) 18 | #endif 19 | 20 | template 21 | class move_source { 22 | public: 23 | move_source(Ptr& ptr) : ptr_(ptr) {} 24 | Ptr& ptr() const { return ptr_; } 25 | private: 26 | Ptr& ptr_; 27 | move_source(const Ptr&); 28 | }; 29 | 30 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 31 | #pragma warning(pop) 32 | #endif 33 | 34 | } // End namespace move_ptrs. 35 | 36 | 37 | template 38 | move_ptrs::move_source move(T& x) 39 | { return move_ptrs::move_source(x); } 40 | 41 | } // namespace 'ptr_container_detail' 42 | } // End namespace boost. 43 | 44 | #endif // #ifndef BOOST_MOVE_HPP_INCLUDED 45 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/ptr_container_disable_deprecated.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_PTR_CONTAINER_DETAIL_PTR_CONTAINER_DISABLE_DEPRECATED_HPP_INCLUDED 2 | #define BOOST_PTR_CONTAINER_DETAIL_PTR_CONTAINER_DISABLE_DEPRECATED_HPP_INCLUDED 3 | 4 | // MS compatible compilers support #pragma once 5 | 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 7 | # pragma once 8 | #endif 9 | 10 | // 11 | // boost/ptr_container/detail/ptr_container_disable_deprecated.hpp 12 | // 13 | // Copyright 2015 Peter Dimov 14 | // 15 | // Distributed under the Boost Software License, Version 1.0. 16 | // See accompanying file LICENSE_1_0.txt or copy at 17 | // http://www.boost.org/LICENSE_1_0.txt) 18 | // 19 | 20 | #include 21 | 22 | #if defined( __GNUC__ ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || ( __cplusplus >= 201103L ) ) && !defined(BOOST_NO_AUTO_PTR) 23 | 24 | # if defined( BOOST_GCC ) 25 | 26 | # if BOOST_GCC >= 40600 27 | # define BOOST_PTR_CONTAINER_DISABLE_DEPRECATED 28 | # endif 29 | 30 | # elif defined( __clang__ ) && defined( __has_warning ) 31 | 32 | # if __has_warning( "-Wdeprecated-declarations" ) 33 | # define BOOST_PTR_CONTAINER_DISABLE_DEPRECATED 34 | # endif 35 | 36 | # endif 37 | 38 | #endif 39 | 40 | #endif // #ifndef BOOST_PTR_CONTAINER_DETAIL_PTR_CONTAINER_DISABLE_DEPRECATED_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/scoped_deleter.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP 13 | #define BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost 24 | { 25 | 26 | namespace ptr_container_detail 27 | { 28 | template< class Container > 29 | class scoped_deleter 30 | { 31 | typedef BOOST_DEDUCED_TYPENAME Container::size_type size_type; 32 | typedef BOOST_DEDUCED_TYPENAME Container::object_type T; 33 | 34 | Container& cont_; 35 | scoped_array ptrs_; 36 | size_type stored_; 37 | bool released_; 38 | 39 | public: 40 | scoped_deleter( Container& cont, T** a, size_type size ) 41 | : cont_(cont), 42 | ptrs_( a ), 43 | stored_( size ), 44 | released_( false ) 45 | { 46 | BOOST_ASSERT( a ); 47 | } 48 | 49 | scoped_deleter( Container& cont, size_type size ) 50 | : cont_(cont), 51 | ptrs_( new T*[size] ), 52 | stored_( 0 ), 53 | released_( false ) 54 | { 55 | BOOST_ASSERT( size > 0 ); 56 | } 57 | 58 | 59 | 60 | scoped_deleter( Container& cont, size_type n, const T& x ) // strong 61 | : cont_(cont), 62 | ptrs_( new T*[n] ), 63 | stored_(0), 64 | released_( false ) 65 | { 66 | for( size_type i = 0; i != n; i++ ) 67 | add( cont_.null_policy_allocate_clone( &x ) ); 68 | BOOST_ASSERT( stored_ > 0 ); 69 | } 70 | 71 | 72 | 73 | template< class InputIterator > 74 | scoped_deleter ( Container& cont, InputIterator first, InputIterator last ) // strong 75 | : cont_(cont), 76 | ptrs_( new T*[ std::distance(first,last) ] ), 77 | stored_(0), 78 | released_( false ) 79 | { 80 | for( ; first != last; ++first ) 81 | add( cont_.null_policy_allocate_clone_from_iterator( first ) ); 82 | BOOST_ASSERT( stored_ > 0 ); 83 | } 84 | 85 | 86 | 87 | ~scoped_deleter() 88 | { 89 | if ( !released_ ) 90 | { 91 | for( size_type i = 0u; i != stored_; ++i ) 92 | cont_.null_policy_deallocate_clone( ptrs_[i] ); 93 | } 94 | } 95 | 96 | 97 | 98 | void add( T* t ) 99 | { 100 | BOOST_ASSERT( ptrs_.get() != 0 ); 101 | ptrs_[stored_] = t; 102 | ++stored_; 103 | } 104 | 105 | 106 | 107 | void release() 108 | { 109 | released_ = true; 110 | } 111 | 112 | 113 | 114 | T** begin() 115 | { 116 | BOOST_ASSERT( ptrs_.get() != 0 ); 117 | return &ptrs_[0]; 118 | } 119 | 120 | 121 | 122 | T** end() 123 | { 124 | BOOST_ASSERT( ptrs_.get() != 0 ); 125 | return &ptrs_[stored_]; 126 | } 127 | 128 | }; // class 'scoped_deleter' 129 | } 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/serialize_ptr_map_adapter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_PTR_MAP_ADAPTER_HPP 7 | #define BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_PTR_MAP_ADAPTER_HPP 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace boost 14 | { 15 | 16 | namespace serialization 17 | { 18 | 19 | template 20 | void save(Archive& ar, const ptr_container_detail::ptr_map_adapter_base& c, unsigned int /*version*/) 21 | { 22 | typedef ptr_container_detail::ptr_map_adapter_base container; 23 | typedef BOOST_DEDUCED_TYPENAME container::const_iterator const_iterator; 24 | 25 | ar << boost::serialization::make_nvp( ptr_container_detail::count(), 26 | ptr_container_detail::serialize_as_const(c.size()) ); 27 | 28 | const_iterator i = c.begin(), e = c.end(); 29 | for(; i != e; ++i) 30 | { 31 | ar << boost::serialization::make_nvp( ptr_container_detail::first(), i->first ); 32 | ar << boost::serialization::make_nvp( ptr_container_detail::second(), 33 | ptr_container_detail::serialize_as_const(i->second) ); 34 | } 35 | } 36 | 37 | template 38 | void load(Archive& ar, ptr_map_adapter& c, unsigned int /*version*/) 39 | { 40 | typedef ptr_map_adapter container; 41 | typedef BOOST_DEDUCED_TYPENAME container::key_type key_type; 42 | typedef BOOST_DEDUCED_TYPENAME container::size_type size_type; 43 | typedef BOOST_DEDUCED_TYPENAME container::iterator iterator; 44 | 45 | c.clear(); 46 | size_type n; 47 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); 48 | 49 | for(size_type i = 0u; i != n; ++i) 50 | { 51 | key_type key; 52 | T* value; 53 | ar >> boost::serialization::make_nvp( ptr_container_detail::first(), key ); 54 | ar >> boost::serialization::make_nvp( ptr_container_detail::second(), value ); 55 | std::pair p = c.insert(key, value); 56 | ar.reset_object_address(&p.first->first, &key); 57 | } 58 | } 59 | 60 | template 61 | void load(Archive& ar, ptr_multimap_adapter& c, unsigned int /*version*/) 62 | { 63 | typedef ptr_multimap_adapter container; 64 | typedef BOOST_DEDUCED_TYPENAME container::key_type key_type; 65 | typedef BOOST_DEDUCED_TYPENAME container::size_type size_type; 66 | typedef BOOST_DEDUCED_TYPENAME container::iterator iterator; 67 | 68 | c.clear(); 69 | size_type n; 70 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); 71 | 72 | for(size_type i = 0u; i != n; ++i) 73 | { 74 | key_type key; 75 | T* value; 76 | ar >> boost::serialization::make_nvp( ptr_container_detail::first(), key ); 77 | ar >> boost::serialization::make_nvp( ptr_container_detail::second(), value ); 78 | iterator p = c.insert(key, value); 79 | ar.reset_object_address(&p->first, &key); 80 | } 81 | } 82 | 83 | } // namespace serialization 84 | } // namespace boost 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/serialize_reversible_cont.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_REVERSIBLE_PTR_CONTAINER_HPP 7 | #define BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_REVERSIBLE_PTR_CONTAINER_HPP 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace boost 14 | { 15 | 16 | namespace ptr_container_detail 17 | { 18 | 19 | template 20 | void save_helper(Archive& ar, const ptr_container_detail::reversible_ptr_container& c) 21 | { 22 | typedef ptr_container_detail::reversible_ptr_container container_type; 23 | typedef BOOST_DEDUCED_TYPENAME container_type::const_iterator const_iterator; 24 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; 25 | 26 | const_iterator i = c.begin(), e = c.end(); 27 | for(; i != e; ++i) 28 | ar << boost::serialization::make_nvp( ptr_container_detail::item(), 29 | ptr_container_detail::serialize_as_const(static_cast(*i.base()))); 30 | } 31 | 32 | template 33 | void load_helper(Archive& ar, ptr_container_detail::reversible_ptr_container& c, 34 | BOOST_DEDUCED_TYPENAME ptr_container_detail::reversible_ptr_container::size_type n) 35 | { 36 | typedef ptr_container_detail::reversible_ptr_container container_type; 37 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; 38 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; 39 | 40 | // 41 | // Called after an appropriate reserve on c. 42 | // 43 | 44 | c.clear(); 45 | for(size_type i = 0u; i != n; ++i) 46 | { 47 | // 48 | // Remark: pointers are not tracked, 49 | // so we need not call ar.reset_object_address(v, u) 50 | // 51 | value_type ptr; 52 | ar >> boost::serialization::make_nvp( ptr_container_detail::item(), ptr ); 53 | c.insert(c.end(), ptr); 54 | } 55 | } 56 | 57 | } // namespace ptr_container_detail 58 | 59 | namespace serialization 60 | { 61 | 62 | template 63 | void save(Archive& ar, const ptr_container_detail::reversible_ptr_container& c, unsigned int /*version*/) 64 | { 65 | ar << boost::serialization::make_nvp( ptr_container_detail::count(), 66 | ptr_container_detail::serialize_as_const(c.size()) ); 67 | ptr_container_detail::save_helper(ar, c); 68 | } 69 | 70 | template 71 | void load(Archive& ar, ptr_container_detail::reversible_ptr_container& c, unsigned int /*version*/) 72 | { 73 | typedef ptr_container_detail::reversible_ptr_container container_type; 74 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; 75 | 76 | size_type n; 77 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); 78 | ptr_container_detail::load_helper(ar, c, n); 79 | 80 | } 81 | 82 | } // namespace serialization 83 | } // namespace boost 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/serialize_xml_names.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2007. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_XML_NAMES 13 | #define BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_XML_NAMES 14 | 15 | namespace boost 16 | { 17 | namespace ptr_container_detail 18 | { 19 | inline const char* count() { return "count"; } 20 | inline const char* item() { return "item"; } 21 | inline const char* first() { return "first"; } 22 | inline const char* second() { return "second"; } 23 | 24 | template 25 | inline T const& serialize_as_const(T const& r) 26 | { 27 | return r; 28 | } 29 | } 30 | } 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /include/boost/ptr_container/detail/throw_exception.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2006. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_DETAIL_THROW_EXCEPTION 13 | #define BOOST_PTR_CONTAINER_DETAIL_THROW_EXCEPTION 14 | 15 | #include 16 | #include 17 | 18 | #ifdef BOOST_NO_EXCEPTIONS 19 | #define BOOST_PTR_CONTAINER_NO_EXCEPTIONS 20 | #endif 21 | 22 | #ifdef BOOST_PTR_CONTAINER_NO_EXCEPTIONS 23 | 24 | #define BOOST_PTR_CONTAINER_THROW_EXCEPTION( If, Ex, Msg ) BOOST_ASSERT( !(If) && Msg ) 25 | 26 | #else 27 | 28 | #define BOOST_PTR_CONTAINER_THROW_EXCEPTION( If, Ex, Msg ) if( (If) ) throw Ex ( Msg ) 29 | 30 | #endif // BOOST_PTR_CONTAINER_NO_EXCEPTIONS 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/boost/ptr_container/exception.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_EXCEPTION_HPP 13 | #define BOOST_PTR_CONTAINER_EXCEPTION_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | 21 | namespace boost 22 | { 23 | class bad_ptr_container_operation : public std::exception 24 | { 25 | const char* what_; 26 | public: 27 | bad_ptr_container_operation( const char* what ) : what_( what ) 28 | { } 29 | 30 | virtual const char* what() const throw() 31 | { 32 | return what_; 33 | } 34 | }; 35 | 36 | 37 | 38 | class bad_index : public bad_ptr_container_operation 39 | { 40 | public: 41 | bad_index( const char* what ) : bad_ptr_container_operation( what ) 42 | { } 43 | }; 44 | 45 | 46 | 47 | class bad_pointer : public bad_ptr_container_operation 48 | { 49 | public: 50 | bad_pointer() : bad_ptr_container_operation( "Null pointer not allowed in a pointer container!" ) 51 | { } 52 | 53 | bad_pointer( const char* text ) : bad_ptr_container_operation( text ) 54 | { } 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/boost/ptr_container/indirect_fun.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2007. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP 13 | #define BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | #pragma once 17 | #endif 18 | 19 | #include 20 | 21 | #ifdef BOOST_NO_SFINAE 22 | #else 23 | #include 24 | #include 25 | #endif // BOOST_NO_SFINAE 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace boost 34 | { 35 | 36 | namespace ptr_container_detail 37 | { 38 | template 39 | struct make_lazy 40 | { 41 | typedef typename Type::type type; 42 | }; 43 | } 44 | 45 | template 46 | < 47 | class Fun 48 | #ifdef BOOST_NO_SFINAE 49 | , class Result = bool 50 | #endif 51 | > 52 | class indirect_fun 53 | { 54 | Fun fun; 55 | public: 56 | indirect_fun() : fun(Fun()) 57 | { } 58 | 59 | indirect_fun( Fun f ) : fun(f) 60 | { } 61 | 62 | template< class T > 63 | #ifdef BOOST_NO_SFINAE 64 | Result 65 | #else 66 | typename boost::result_of< const Fun( typename pointee::type& ) >::type 67 | #endif 68 | operator()( const T& r ) const 69 | { 70 | return fun( *r ); 71 | } 72 | 73 | template< class T, class U > 74 | #ifdef BOOST_NO_SFINAE 75 | Result 76 | #else 77 | typename boost::result_of< const Fun( typename pointee::type&, 78 | typename pointee::type& ) >::type 79 | #endif 80 | operator()( const T& r, const U& r2 ) const 81 | { 82 | return fun( *r, *r2 ); 83 | } 84 | }; 85 | 86 | template< class Fun > 87 | inline indirect_fun make_indirect_fun( Fun f ) 88 | { 89 | return indirect_fun( f ); 90 | } 91 | 92 | 93 | template 94 | < 95 | class Fun, 96 | class Arg1, 97 | class Arg2 = Arg1 98 | #ifdef BOOST_NO_SFINAE 99 | , class Result = bool 100 | #endif 101 | > 102 | class void_ptr_indirect_fun 103 | { 104 | Fun fun; 105 | 106 | public: 107 | 108 | void_ptr_indirect_fun() : fun(Fun()) 109 | { } 110 | 111 | void_ptr_indirect_fun( Fun f ) : fun(f) 112 | { } 113 | 114 | template< class Void > 115 | #ifdef BOOST_NO_SFINAE 116 | Result 117 | #else 118 | typename ptr_container_detail::make_lazy< 119 | boost::result_of, Void>::type 120 | #endif 121 | operator()( const Void* r ) const 122 | { 123 | BOOST_STATIC_ASSERT(boost::is_void::value); 124 | BOOST_ASSERT( r != 0 ); 125 | return fun( * static_cast( r ) ); 126 | } 127 | 128 | template< class Void > 129 | #ifdef BOOST_NO_SFINAE 130 | Result 131 | #else 132 | typename ptr_container_detail::make_lazy< 133 | boost::result_of, Void>::type 134 | #endif 135 | operator()( const Void* l, const Void* r ) const 136 | { 137 | BOOST_STATIC_ASSERT(boost::is_void::value); 138 | BOOST_ASSERT( l != 0 && r != 0 ); 139 | return fun( * static_cast( l ), * static_cast( r ) ); 140 | } 141 | }; 142 | 143 | template< class Arg, class Fun > 144 | inline void_ptr_indirect_fun make_void_ptr_indirect_fun( Fun f ) 145 | { 146 | return void_ptr_indirect_fun( f ); 147 | } 148 | 149 | } // namespace 'boost' 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /include/boost/ptr_container/nullable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | 13 | #ifndef BOOST_INDIRECT_CONTAINER_NULLABLE_HPP 14 | #define BOOST_INDIRECT_CONTAINER_NULLABLE_HPP 15 | 16 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 17 | # pragma once 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace boost 27 | { 28 | 29 | template< class T > 30 | struct nullable 31 | { 32 | typedef T type; 33 | }; 34 | 35 | namespace ptr_container_detail 36 | { 37 | template< class T > 38 | type_traits::yes_type is_nullable( const nullable* ); 39 | 40 | type_traits::no_type is_nullable( ... ); 41 | } 42 | 43 | template< class T > 44 | struct is_nullable 45 | { 46 | private: 47 | BOOST_STATIC_CONSTANT( T*, var ); 48 | public: 49 | 50 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 51 | #pragma warning(push) 52 | #pragma warning(disable:6334) 53 | #endif 54 | 55 | BOOST_STATIC_CONSTANT(bool, value = sizeof( ptr_container_detail::is_nullable( var ) ) 56 | == sizeof( type_traits::yes_type ) ); 57 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 58 | #pragma warning(pop) 59 | #endif 60 | 61 | }; 62 | 63 | template< class T > 64 | struct remove_nullable 65 | { 66 | typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< is_nullable, 67 | T, 68 | mpl::identity >::type 69 | type; 70 | }; 71 | 72 | namespace ptr_container_detail 73 | { 74 | template< class T > 75 | struct void_ptr 76 | { 77 | typedef BOOST_DEDUCED_TYPENAME 78 | mpl::if_c< boost::is_const< 79 | BOOST_DEDUCED_TYPENAME boost::remove_nullable::type >::value, 80 | const void*, void* >::type type; 81 | }; 82 | } 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /include/boost/ptr_container/ptr_container.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_HPP 13 | #define BOOST_PTR_CONTAINER_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /include/boost/ptr_container/ptr_deque.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_PTR_DEQUE_HPP 13 | #define BOOST_PTR_CONTAINER_PTR_DEQUE_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 24 | #pragma GCC diagnostic push 25 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 26 | #endif 27 | 28 | namespace boost 29 | { 30 | 31 | template 32 | < 33 | class T, 34 | class CloneAllocator = heap_clone_allocator, 35 | class Allocator = std::allocator::type> 36 | > 37 | class ptr_deque : public 38 | ptr_sequence_adapter< T, std::deque< 39 | typename ptr_container_detail::void_ptr::type,Allocator>, 40 | CloneAllocator > 41 | { 42 | typedef ptr_sequence_adapter< T, std::deque< 43 | typename ptr_container_detail::void_ptr::type,Allocator>, 44 | CloneAllocator > 45 | base_class; 46 | 47 | typedef ptr_deque this_type; 48 | 49 | public: 50 | 51 | BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_deque, 52 | base_class, 53 | this_type ) 54 | }; 55 | 56 | ////////////////////////////////////////////////////////////////////////////// 57 | // clonability 58 | 59 | template< typename T, typename CA, typename A > 60 | inline ptr_deque* new_clone( const ptr_deque& r ) 61 | { 62 | return r.clone().release(); 63 | } 64 | 65 | ///////////////////////////////////////////////////////////////////////// 66 | // swap 67 | 68 | template< typename T, typename CA, typename A > 69 | inline void swap( ptr_deque& l, ptr_deque& r ) 70 | { 71 | l.swap(r); 72 | } 73 | } 74 | 75 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 76 | #pragma GCC diagnostic pop 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/boost/ptr_container/ptr_list.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_PTR_LIST_HPP 13 | #define BOOST_PTR_CONTAINER_PTR_LIST_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 24 | #pragma GCC diagnostic push 25 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 26 | #endif 27 | 28 | namespace boost 29 | { 30 | 31 | template 32 | < 33 | class T, 34 | class CloneAllocator = heap_clone_allocator, 35 | class Allocator = std::allocator::type> 36 | > 37 | class ptr_list : public 38 | ptr_sequence_adapter< T, std::list< 39 | typename ptr_container_detail::void_ptr::type,Allocator>, 40 | CloneAllocator > 41 | { 42 | typedef ptr_sequence_adapter< T, std::list< 43 | typename ptr_container_detail::void_ptr::type,Allocator>, 44 | CloneAllocator > 45 | base_class; 46 | 47 | typedef ptr_list this_type; 48 | typedef BOOST_DEDUCED_TYPENAME boost::remove_nullable::type U; 49 | 50 | public: 51 | BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_list, 52 | base_class, 53 | this_type ) 54 | 55 | typedef BOOST_DEDUCED_TYPENAME base_class::value_type value_type; 56 | 57 | public: 58 | using base_class::merge; 59 | 60 | void merge( ptr_list& x ) 61 | { 62 | merge( x, std::less() ); 63 | } 64 | 65 | template< typename Compare > 66 | void merge( ptr_list& x, Compare comp ) 67 | { 68 | this->base().merge( x.base(), void_ptr_indirect_fun( comp ) ); } 69 | 70 | void sort() 71 | { 72 | sort( std::less() ); 73 | }; 74 | 75 | template< typename Compare > 76 | void sort( Compare comp ) 77 | { 78 | this->base().sort( void_ptr_indirect_fun( comp ) ); 79 | } 80 | 81 | template< class Pred > 82 | void erase_if( iterator first, iterator last, Pred pred ) 83 | { 84 | base_class::erase_if( first, last, pred ); 85 | } 86 | 87 | template< class Pred > 88 | void erase_if( Pred pred ) 89 | { 90 | this->base().remove_if( BOOST_DEDUCED_TYPENAME base_class:: 91 | BOOST_NESTED_TEMPLATE void_ptr_delete_if 92 | (pred) ); 93 | } 94 | 95 | }; // class 'ptr_list' 96 | 97 | ////////////////////////////////////////////////////////////////////////////// 98 | // clonability 99 | 100 | template< typename T, typename CA, typename A > 101 | inline ptr_list* new_clone( const ptr_list& r ) 102 | { 103 | return r.clone().release(); 104 | } 105 | 106 | ///////////////////////////////////////////////////////////////////////// 107 | // swap 108 | 109 | template< typename T, typename CA, typename A > 110 | inline void swap( ptr_list& l, ptr_list& r ) 111 | { 112 | l.swap(r); 113 | } 114 | } 115 | 116 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 117 | #pragma GCC diagnostic pop 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /include/boost/ptr_container/ptr_vector.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_PTR_VECTOR_HPP 13 | #define BOOST_PTR_CONTAINER_PTR_VECTOR_HPP 14 | 15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 26 | #pragma GCC diagnostic push 27 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 28 | #endif 29 | 30 | namespace boost 31 | { 32 | 33 | template 34 | < 35 | class T, 36 | class CloneAllocator = heap_clone_allocator, 37 | class Allocator = void 38 | > 39 | class ptr_vector : public 40 | ptr_sequence_adapter< T, 41 | std::vector< 42 | typename ptr_container_detail::void_ptr::type, 43 | typename boost::mpl::if_, 44 | std::allocator::type>, Allocator>::type 45 | >, 46 | CloneAllocator > 47 | { 48 | typedef 49 | 50 | ptr_sequence_adapter< T, 51 | std::vector< 52 | typename ptr_container_detail::void_ptr::type, 53 | typename boost::mpl::if_, 54 | std::allocator::type>, Allocator>::type 55 | >, 56 | CloneAllocator > 57 | 58 | base_class; 59 | 60 | typedef ptr_vector this_type; 61 | 62 | public: 63 | 64 | BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_vector, 65 | base_class, 66 | this_type ) 67 | 68 | explicit ptr_vector( size_type n, 69 | const allocator_type& alloc = allocator_type() ) 70 | : base_class(alloc) 71 | { 72 | this->base().reserve( n ); 73 | } 74 | }; 75 | 76 | ////////////////////////////////////////////////////////////////////////////// 77 | // clonability 78 | 79 | template< typename T, typename CA, typename A > 80 | inline ptr_vector* new_clone( const ptr_vector& r ) 81 | { 82 | return r.clone().release(); 83 | } 84 | 85 | ///////////////////////////////////////////////////////////////////////// 86 | // swap 87 | 88 | template< typename T, typename CA, typename A > 89 | inline void swap( ptr_vector& l, ptr_vector& r ) 90 | { 91 | l.swap(r); 92 | } 93 | 94 | } 95 | 96 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 97 | #pragma GCC diagnostic pop 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_ARRAY_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_ARRAY_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void save(Archive& ar, const ptr_array& c, unsigned int /*version*/) 20 | { 21 | ptr_container_detail::save_helper(ar, c); 22 | } 23 | 24 | template 25 | void load(Archive& ar, ptr_array& c, unsigned int /*version*/) 26 | { 27 | typedef ptr_array container_type; 28 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; 29 | 30 | for(size_type i = 0u; i != N; ++i) 31 | { 32 | T* p; 33 | ar >> boost::serialization::make_nvp( ptr_container_detail::item(), p ); 34 | c.replace(i, p); 35 | } 36 | } 37 | 38 | template 39 | void serialize(Archive& ar, ptr_array& c, const unsigned int version) 40 | { 41 | core::split_free(ar, c, version); 42 | } 43 | 44 | } // namespace serialization 45 | } // namespace boost 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_circular_buffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_CIRCULAR_BUFFER_HPP 13 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_CIRCULAR_BUFFER_HPP 14 | 15 | #include 16 | #include 17 | 18 | namespace boost 19 | { 20 | 21 | namespace serialization 22 | { 23 | 24 | template 25 | void load(Archive& ar, ptr_circular_buffer& c, unsigned int version) 26 | { 27 | typedef ptr_circular_buffer container_type; 28 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; 29 | 30 | size_type n; 31 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); 32 | c.reserve(n); 33 | 34 | ptr_container_detail::load_helper(ar, c, n); 35 | } 36 | 37 | template 38 | void serialize(Archive& ar, ptr_circular_buffer& c, const unsigned int version) 39 | { 40 | core::split_free(ar, c, version); 41 | } 42 | 43 | } // namespace serialization 44 | } // namespace boost 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_container.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_HPP 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_deque.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_DEQUE_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_DEQUE_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void serialize(Archive& ar, ptr_deque& c, const unsigned int version) 20 | { 21 | core::split_free(ar, c, version); 22 | } 23 | 24 | } // namespace serialization 25 | } // namespace boost 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_list.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_LIST_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_LIST_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void serialize(Archive& ar, ptr_list& c, const unsigned int version) 20 | { 21 | core::split_free(ar, c, version); 22 | } 23 | 24 | } // namespace serialization 25 | } // namespace boost 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_map.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_MAP_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_MAP_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void serialize(Archive& ar, ptr_map& c, const unsigned int version) 20 | { 21 | core::split_free(ar, c, version); 22 | } 23 | 24 | template 25 | void serialize(Archive& ar, ptr_multimap& c, const unsigned int version) 26 | { 27 | core::split_free(ar, c, version); 28 | } 29 | 30 | } // namespace serialization 31 | } // namespace boost 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_set.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_SET_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_SET_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void serialize(Archive& ar, ptr_set& c, const unsigned int version) 20 | { 21 | core::split_free(ar, c, version); 22 | } 23 | 24 | template 25 | void serialize(Archive& ar, ptr_multiset& c, const unsigned int version) 26 | { 27 | core::split_free(ar, c, version); 28 | } 29 | 30 | } // namespace serialization 31 | } // namespace boost 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_unordered_map.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_UNORDERED_PTR_MAP_HPP 13 | #define BOOST_PTR_CONTAINER_SERIALIZE_UNORDERED_PTR_MAP_HPP 14 | 15 | #include 16 | #include 17 | 18 | namespace boost 19 | { 20 | 21 | namespace serialization 22 | { 23 | 24 | template 25 | void serialize(Archive& ar, ptr_unordered_map& c, const unsigned int version) 26 | { 27 | core::split_free(ar, c, version); 28 | } 29 | 30 | template 31 | void serialize(Archive& ar, ptr_unordered_multimap& c, const unsigned int version) 32 | { 33 | core::split_free(ar, c, version); 34 | } 35 | 36 | } // namespace serialization 37 | } // namespace boost 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_unordered_set.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_UNORDERED_SET_HPP 13 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_UNORDERED_SET_HPP 14 | 15 | #include 16 | #include 17 | 18 | namespace boost 19 | { 20 | 21 | namespace serialization 22 | { 23 | 24 | template 25 | void serialize(Archive& ar, ptr_unordered_set& c, const unsigned int version) 26 | { 27 | core::split_free(ar, c, version); 28 | } 29 | 30 | template 31 | void serialize(Archive& ar, ptr_unordered_multiset& c, const unsigned int version) 32 | { 33 | core::split_free(ar, c, version); 34 | } 35 | 36 | } // namespace serialization 37 | } // namespace boost 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/ptr_container/serialize_ptr_vector.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Sebastian Ramacher, 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PTR_CONTAINER_SERIALIZE_PTR_VECTOR_HPP 7 | #define BOOST_PTR_CONTAINER_SERIALIZE_PTR_VECTOR_HPP 8 | 9 | #include 10 | #include 11 | 12 | namespace boost 13 | { 14 | 15 | namespace serialization 16 | { 17 | 18 | template 19 | void load(Archive& ar, ptr_vector& c, unsigned int /*version*/) 20 | { 21 | typedef ptr_vector container_type; 22 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; 23 | 24 | size_type n; 25 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); 26 | c.reserve(n); 27 | 28 | ptr_container_detail::load_helper(ar, c, n); 29 | } 30 | 31 | template 32 | void serialize(Archive& ar, ptr_vector& c, const unsigned int version) 33 | { 34 | core::split_free(ar, c, version); 35 | } 36 | 37 | } // namespace serialization 38 | } // namespace boost 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/ptr_container/fa5071af867bfd2480e3b004a4bee27127b951b6/index.html -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "ptr_container", 3 | "name": "Pointer Container", 4 | "authors": [ 5 | "Thorsten Ottosen" 6 | ], 7 | "description": "Containers for storing heap-allocated polymorphic objects to ease OO-programming.", 8 | "category": [ 9 | "Containers", 10 | "Data" 11 | ], 12 | "maintainers": [ 13 | "Thorsten Ottosen " 14 | ], 15 | "cxxstd": "11" 16 | } 17 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | #// 2 | #// Boost.Pointer Container 3 | #// 4 | #// Copyright Thorsten Ottosen 2003-2008. Use, modification and 5 | #// distribution is subject to the Boost Software License, Version 6 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | #// http://www.boost.org/LICENSE_1_0.txt) 8 | #// 9 | #// For more information, see http://www.boost.org/libs/ptr_container/ 10 | #// 11 | 12 | import testing ; 13 | 14 | project : requirements 15 | /boost/ptr_container//boost_ptr_container 16 | /boost/test//boost_unit_test_framework/static ; 17 | 18 | run ptr_inserter.cpp /boost/assign//boost_assign ; 19 | run ptr_vector.cpp /boost/assign//boost_assign /boost/lexical_cast//boost_lexical_cast ; 20 | run ptr_list.cpp /boost/assign//boost_assign /boost/lexical_cast//boost_lexical_cast ; 21 | run ptr_deque.cpp /boost/assign//boost_assign /boost/lexical_cast//boost_lexical_cast ; 22 | run ptr_set.cpp /boost/lexical_cast//boost_lexical_cast ; 23 | run ptr_map.cpp /boost/lexical_cast//boost_lexical_cast ; 24 | run ptr_map_adapter.cpp /boost/lexical_cast//boost_lexical_cast ; 25 | run ptr_array.cpp /boost/lexical_cast//boost_lexical_cast ; 26 | run tree_test.cpp /boost/lexical_cast//boost_lexical_cast ; 27 | run incomplete_type_test.cpp /boost/lexical_cast//boost_lexical_cast ; 28 | run view_example.cpp ; 29 | run iterator_test.cpp ; 30 | run tut1.cpp ; 31 | run indirect_fun.cpp /boost/assign//boost_assign ; 32 | run serialization.cpp /boost/serialization//boost_serialization : : : norecover:no ; 33 | run no_exceptions.cpp /boost/assign//boost_assign /boost/lexical_cast//boost_lexical_cast ; 34 | 35 | run ptr_unordered_set.cpp /boost/lexical_cast//boost_lexical_cast ; 36 | run ptr_unordered_map.cpp /boost/lexical_cast//boost_lexical_cast ; 37 | run ptr_circular_buffer.cpp /boost/assign//boost_assign /boost/lexical_cast//boost_lexical_cast ; 38 | compile const_element_containers.cpp ; 39 | 40 | compile issue_23.cpp ; 41 | -------------------------------------------------------------------------------- /test/cmake_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2021-2024 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.16) 6 | 7 | project(cmake_subdir_test LANGUAGES CXX) 8 | 9 | # Those 2 should work the same 10 | # while using find_package for the installed Boost avoids the need to manually specify dependencies 11 | if(BOOST_CI_INSTALL_TEST) 12 | find_package(boost_ptr_container REQUIRED) 13 | else() 14 | set(BOOST_INCLUDE_LIBRARIES ptr_container) 15 | add_subdirectory(../../../.. deps/boost EXCLUDE_FROM_ALL) 16 | endif() 17 | 18 | add_executable(main main.cpp) 19 | target_link_libraries(main Boost::ptr_container) 20 | 21 | enable_testing() 22 | add_test(NAME main COMMAND main) 23 | -------------------------------------------------------------------------------- /test/const_element_containers.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2009. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | 14 | // force instantiation of all members 15 | 16 | template class boost::ptr_array; 17 | template class boost::ptr_array, 42>; 18 | 19 | template class boost::ptr_deque; 20 | template class boost::ptr_deque< boost::nullable >; 21 | 22 | template class boost::ptr_list; 23 | template class boost::ptr_list< boost::nullable >; 24 | 25 | template class boost::ptr_map; 26 | template class boost::ptr_map >; 27 | 28 | template class boost::ptr_vector; 29 | template class boost::ptr_vector< boost::nullable >; 30 | 31 | //@todo problem with constructor forwarding 32 | // 33 | //template class boost::ptr_unordered_map; 34 | 35 | // @todo: there seems to be some problems with 36 | // argument passing in circular_buffer 37 | // 38 | //boost::ptr_circular_buffer buffer(32); 39 | //buffer.push_back( new int(42) ); 40 | 41 | template class boost::ptr_set; 42 | 43 | // @todo: problem with constructor forwarding 44 | // 45 | //template class boost::ptr_unordered_set; 46 | -------------------------------------------------------------------------------- /test/incomplete_type_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include "test_data.hpp" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | using namespace boost; 20 | 21 | // 22 | // Forward declare 'allocate_clone()' to be able 23 | // use clonability of 'Composite' inline in the class. 24 | // This is normally not needed when using .hpp + .cpp files. 25 | // 26 | class Composite; 27 | Composite* new_clone( const Composite& ); 28 | 29 | 30 | class Composite 31 | { 32 | typedef ptr_vector composite_t; 33 | typedef composite_t::iterator iterator; 34 | typedef composite_t::const_iterator const_iterator; 35 | typedef composite_t::size_type size_type; 36 | composite_t elements_; 37 | 38 | // 39 | // only used internally for 'clone()' 40 | // 41 | Composite( const Composite& r ) : elements_( r.elements_.clone() ) 42 | { } 43 | 44 | // 45 | // this class is not Copyable nor Assignable 46 | // 47 | void operator=( const Composite& ); 48 | 49 | public: 50 | Composite() 51 | { } 52 | 53 | // 54 | // of course detructor is virtual 55 | // 56 | virtual ~Composite() 57 | { } 58 | 59 | // 60 | // one way of adding new elements 61 | // 62 | void add( Composite* c ) 63 | { 64 | elements_.push_back( c ); 65 | } 66 | 67 | // 68 | // second way of adding new elements 69 | // 70 | void add( Composite& c ) 71 | { 72 | elements_.push_back( new_clone( c ) ); 73 | } 74 | 75 | void remove( iterator where ) 76 | { 77 | elements_.erase( where ); 78 | } 79 | 80 | // 81 | // recusively count the elements 82 | // 83 | size_type size() const 84 | { 85 | size_type res = 0; 86 | for( const_iterator i = elements_.begin(); i != elements_.end(); ++i ) 87 | res += i->size(); 88 | return 1 /* this */ + res; 89 | } 90 | 91 | void foo() 92 | { 93 | do_foo(); 94 | for( iterator i = elements_.begin(); i != elements_.end(); ++i ) 95 | i->foo(); 96 | } 97 | 98 | // 99 | // this class is clonable and this is the callback for 'allocate_clone()' 100 | // 101 | Composite* clone() const 102 | { 103 | return do_clone(); 104 | } 105 | 106 | private: 107 | virtual void do_foo() 108 | { 109 | cout << "composite base" << "\n"; 110 | } 111 | 112 | virtual Composite* do_clone() const 113 | { 114 | return new Composite( *this ); 115 | } 116 | }; 117 | 118 | // 119 | // make 'Composite' clonable; note that we do not need to overload 120 | // the function in the 'boost' namespace. 121 | // 122 | Composite* new_clone( const Composite& c ) 123 | { 124 | return c.clone(); 125 | } 126 | 127 | 128 | class ConcreteComposite1 : public Composite 129 | { 130 | virtual void do_foo() 131 | { 132 | cout << "composite 1" << "\n"; 133 | } 134 | 135 | virtual Composite* do_clone() const 136 | { 137 | return new ConcreteComposite1(); 138 | } 139 | }; 140 | 141 | 142 | class ConcreteComposite2 : public Composite 143 | { 144 | virtual void do_foo() 145 | { 146 | cout << "composite 2" << "\n"; 147 | } 148 | 149 | virtual Composite* do_clone() const 150 | { 151 | return new ConcreteComposite2(); 152 | } 153 | }; 154 | 155 | void test_incomplete() 156 | { 157 | Composite c; 158 | c.add( new ConcreteComposite1 ); 159 | c.add( new ConcreteComposite2 ); 160 | BOOST_CHECK_EQUAL( c.size(), 3u ); 161 | c.add( new_clone( c ) ); // add c to itself 162 | BOOST_CHECK_EQUAL( c.size(), 6u ); 163 | c.add( c ); // add c to itself 164 | BOOST_CHECK_EQUAL( c.size(), 12u ); 165 | c.foo(); 166 | } 167 | 168 | using namespace boost; 169 | 170 | 171 | #include 172 | using boost::unit_test::test_suite; 173 | 174 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 175 | { 176 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 177 | 178 | test->add( BOOST_TEST_CASE( &test_incomplete ) ); 179 | 180 | return test; 181 | } 182 | 183 | // 184 | // todo: remake example with shared_ptr 185 | // 186 | 187 | -------------------------------------------------------------------------------- /test/indirect_fun.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | bool lesser_than( const std::string& l, const std::string& r ) 21 | { 22 | return l < r; 23 | } 24 | 25 | 26 | void test_fun() 27 | { 28 | using namespace boost; 29 | ptr_vector vec; 30 | 31 | indirect_fun< std::less > fun; 32 | 33 | std::string s1("bar"); 34 | std::string* ptr1 = &s1; 35 | std::string s2("foo"); 36 | std::string* ptr2 = &s2; 37 | BOOST_CHECK( fun( ptr1, ptr2 ) == true ); 38 | 39 | void* vptr1 = ptr1; 40 | void* vptr2 = ptr2; 41 | 42 | void_ptr_indirect_fun< std::less, std::string> cast_fun; 43 | BOOST_CHECK( cast_fun( vptr1, vptr2 ) == true ); 44 | 45 | assign::push_back( vec )( new std::string("aa") ) 46 | ( new std::string("bb") ) 47 | ( new std::string("dd") ) 48 | ( new std::string("cc") ) 49 | ( new std::string("a") ); 50 | 51 | std::sort( vec.begin().base(), vec.end().base(), cast_fun ); 52 | BOOST_CHECK( vec[0] == "a" ); 53 | BOOST_CHECK( vec[4] == "dd" ); 54 | 55 | std::sort( vec.begin().base(), vec.end().base(), 56 | make_void_ptr_indirect_fun( &lesser_than ) ); 57 | BOOST_CHECK( vec[1] == "aa" ); 58 | BOOST_CHECK( vec[2] == "bb" ); 59 | 60 | int i1 = 2; 61 | void *iptr1 = &i1; 62 | int i2 = 3; 63 | void* iptr2 = &i2; 64 | 65 | void_ptr_indirect_fun, int> int_cast_fun; 66 | BOOST_CHECK( int_cast_fun(iptr1,iptr2) ); 67 | 68 | } 69 | 70 | #include 71 | using boost::unit_test::test_suite; 72 | 73 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 74 | { 75 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 76 | 77 | test->add( BOOST_TEST_CASE( &test_fun ) ); 78 | 79 | return test; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /test/issue_23.cpp: -------------------------------------------------------------------------------- 1 | // Use, modification and distribution is subject to the 2 | // Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | 7 | template struct Foo 8 | { 9 | static void test(boost::ptr_vector >& /*t*/) 10 | { 11 | } 12 | }; 13 | 14 | int main() 15 | { 16 | boost::ptr_vector > ptr; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/iterator_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | void test_iterator() 17 | { 18 | using namespace boost; 19 | ptr_vector vec; 20 | vec.push_back( new int(0) ); 21 | ptr_vector::iterator mutable_i = vec.begin(); 22 | ptr_vector::const_iterator const_i = vec.begin(); 23 | 24 | BOOST_CHECK( mutable_i == const_i ); 25 | BOOST_CHECK( ! (mutable_i != const_i ) ); 26 | BOOST_CHECK( const_i == mutable_i ); 27 | BOOST_CHECK( ! ( const_i != mutable_i ) ); 28 | 29 | BOOST_CHECK( !( mutable_i < const_i ) ); 30 | BOOST_CHECK( mutable_i <= const_i ); 31 | BOOST_CHECK( ! ( mutable_i > const_i ) ); 32 | BOOST_CHECK( mutable_i >= const_i ); 33 | BOOST_CHECK( !( const_i < mutable_i ) ); 34 | BOOST_CHECK( const_i <= mutable_i ); 35 | BOOST_CHECK( ! ( const_i > mutable_i ) ); 36 | BOOST_CHECK( const_i >= mutable_i ); 37 | 38 | BOOST_CHECK( const_i - mutable_i == 0 ); 39 | BOOST_CHECK( mutable_i - const_i == 0 ); 40 | 41 | const ptr_vector& rvec = vec; 42 | const_i = rvec.begin(); 43 | 44 | ptr_map map; 45 | int i = 0; 46 | map.insert( i, new int(0) ); 47 | ptr_map::iterator map_mutable_i = map.begin(); 48 | ptr_map::const_iterator map_const_i = map.begin(); 49 | 50 | #if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006)) 51 | // This only works for library implementations which conform to the 52 | // proposed resolution of the C++ Standard Library DR#179. See 53 | // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179. 54 | BOOST_CHECK( map_mutable_i == map_const_i ); 55 | BOOST_CHECK( ! ( map_mutable_i != map_const_i ) ); 56 | BOOST_CHECK( map_const_i == map_mutable_i ); 57 | BOOST_CHECK( ! ( map_const_i != map_mutable_i ) ); 58 | #endif 59 | 60 | const ptr_map& rmap = map; 61 | map_const_i = rmap.begin(); 62 | } 63 | 64 | #include 65 | using boost::unit_test::test_suite; 66 | 67 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 68 | { 69 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 70 | 71 | test->add( BOOST_TEST_CASE( &test_iterator ) ); 72 | 73 | return test; 74 | } 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /test/no_exceptions.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2006. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #define BOOST_PTR_CONTAINER_NO_EXCEPTIONS 1 13 | 14 | #include "ptr_vector.cpp" 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/pointainer_speed.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include "test_data.hpp" 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | using namespace boost; 19 | using namespace std; 20 | 21 | 22 | typedef shared_ptr PolyPtr; 23 | 24 | struct PolyPtrOps 25 | { 26 | void operator()( const PolyPtr& a ) 27 | { a->foo(); } 28 | }; 29 | 30 | struct less_than 31 | { 32 | bool operator()( const PolyPtr& l, const PolyPtr& r ) const 33 | { 34 | return *l < *r; 35 | } 36 | 37 | bool operator()( const Base* l, const Base* r ) const 38 | { 39 | return *l < *r; 40 | } 41 | }; 42 | 43 | struct greater_than 44 | { 45 | bool operator()( const PolyPtr& l, const PolyPtr& r ) const 46 | { 47 | return *l > *r; 48 | } 49 | 50 | bool operator()( const Base* l, const Base* r ) const 51 | { 52 | return *l > *r; 53 | } 54 | }; 55 | 56 | struct data_less_than 57 | { 58 | bool operator()( const PolyPtr& l, const PolyPtr& r ) const 59 | { 60 | return l->data_less_than(*r); 61 | } 62 | 63 | bool operator()( const Base* l, const Base* r ) const 64 | { 65 | return l->data_less_than(*r); 66 | } 67 | }; 68 | 69 | struct data_less_than2 70 | { 71 | bool operator()( const PolyPtr& l, const PolyPtr& r ) const 72 | { 73 | return l->data_less_than2(*r); 74 | } 75 | 76 | bool operator()( const Base* l, const Base* r ) const 77 | { 78 | return l->data_less_than2(*r); 79 | } 80 | }; 81 | 82 | 83 | void test_speed() 84 | { 85 | enum { size = 50000 }; 86 | vector svec; 87 | ptr_vector pvec; 88 | 89 | { 90 | progress_timer timer; 91 | for( int i = 0; i < size; ++i ) 92 | svec.push_back( PolyPtr( new Derived ) ); 93 | cout << "\n shared_ptr call new: "; 94 | } 95 | 96 | { 97 | progress_timer timer; 98 | for( int i = 0; i < size; ++i ) 99 | pvec.push_back( new Derived ); 100 | cout << "\n smart container call new: "; 101 | } 102 | 103 | { 104 | progress_timer timer; 105 | for_each( svec.begin(), svec.end(), PolyPtrOps() ); 106 | cout << "\n shared_ptr call foo(): "; 107 | } 108 | 109 | { 110 | progress_timer timer; 111 | for_each( pvec.begin(), pvec.end(), mem_fun_ref( &Base::foo ) ); 112 | cout << "\n smart container call foo(): "; 113 | } 114 | 115 | { 116 | progress_timer timer; 117 | sort( svec.begin(), svec.end(), less_than() ); 118 | cout << "\n shared_ptr call sort(): "; 119 | } 120 | 121 | { 122 | progress_timer timer; 123 | sort( pvec.ptr_begin(), pvec.ptr_end(), less_than() ); 124 | cout << "\n smart container call sort(): "; 125 | } 126 | 127 | { 128 | progress_timer timer; 129 | sort( svec.begin(), svec.end(), greater_than() ); 130 | cout << "\n shared_ptr call sort() #2: "; 131 | } 132 | 133 | { 134 | progress_timer timer; 135 | sort( pvec.ptr_begin(), pvec.ptr_end(), greater_than() ); 136 | cout << "\n smart container call sort() #2: "; 137 | } 138 | 139 | { 140 | progress_timer timer; 141 | sort( svec.begin(), svec.end(), data_less_than() ); 142 | cout << "\n shared_ptr call sort() #3: "; 143 | } 144 | 145 | { 146 | progress_timer timer; 147 | sort( pvec.ptr_begin(), pvec.ptr_end(), data_less_than() ); 148 | cout << "\n smart container call sort() #3: "; 149 | } 150 | 151 | { 152 | progress_timer timer; 153 | sort( svec.begin(), svec.end(), data_less_than2() ); 154 | cout << "\n shared_ptr call sort() #4: "; 155 | } 156 | 157 | { 158 | progress_timer timer; 159 | sort( pvec.ptr_begin(), pvec.ptr_end(), data_less_than2() ); 160 | cout << "\n smart container call sort() #4: "; 161 | } 162 | 163 | vector copy1; 164 | for( ptr_vector::ptr_iterator i = pvec.ptr_begin(); i != pvec.ptr_end(); ++ i ) 165 | copy1.push_back( *i ); 166 | 167 | sort( pvec.ptr_begin(), pvec.ptr_end() ); 168 | 169 | 170 | vector copy2; 171 | for( ptr_vector::ptr_iterator i = pvec.ptr_begin(); i != pvec.ptr_end(); ++ i ) 172 | copy2.push_back( *i ); 173 | 174 | 175 | for( unsigned int i = 0; i < copy1.size(); ++i ) 176 | { 177 | bool found = false; 178 | for( int j = 0; j < copy1.size(); ++ j ) 179 | if( copy1[i] == copy2[j] ) 180 | found = true; 181 | 182 | if( !found ) 183 | cout << copy1[i] << endl; 184 | } 185 | 186 | BOOST_REQUIRE( pvec.size() == size ); 187 | cout << endl; 188 | } 189 | 190 | 191 | #include 192 | using boost::unit_test::test_suite; 193 | 194 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 195 | { 196 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 197 | 198 | test->add( BOOST_TEST_CASE( &test_speed ) ); 199 | 200 | return test; 201 | } 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /test/ptr_container_adapter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include "sequence_test_data.hpp" 13 | #include 14 | #include 15 | 16 | 17 | template< class T > 18 | class my_list : public std::list 19 | { 20 | typedef BOOST_DEDUCED_TYPENAME std::list base_class; 21 | 22 | public: 23 | /* 24 | my_list( const base_class::allocator_type& alloc = base_class::allocator_type() ) 25 | : base_class( alloc ) {} 26 | 27 | my_list( size_type n, const T& x, const base_class::allocator_type& alloc = base_class::allocator_type() ) 28 | : base_class( n, x, alloc ) {} 29 | 30 | template< class InputIterator > 31 | my_list( InputIterator first, InputIterator last ) : base_class( first, last ) {} 32 | */ 33 | }; 34 | 35 | void test_container_adapter() 36 | { 37 | typedef ptr_container_adapter< my_list > base_ptr_list; 38 | typedef ptr_container_adapter< my_list > value_ptr_list; 39 | 40 | typedef_test< base_ptr_list, Derived_class >(); 41 | typedef_test< value_ptr_list, Value >(); 42 | 43 | // reversible_container_test< base_ptr_list, Base, Derived_class >(); 44 | // reversible_container_test< value_ptr_list, Value, Value >(); 45 | 46 | base_ptr_list l; 47 | l.push_back( new Derived_class ); 48 | l.push_back( new Derived_class ); 49 | 50 | // algo_test< ptr_list, Value >(); 51 | // algo_test_polymorphic< ptr_list, Derived_class >(); 52 | } 53 | 54 | #include 55 | 56 | using boost::unit_test::test_suite; 57 | 58 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 59 | { 60 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 61 | 62 | test->add( BOOST_TEST_CASE( &test_container_adapter ) ); 63 | 64 | return test; 65 | } 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /test/ptr_deque.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include "sequence_test_data.hpp" 14 | #include 15 | #include 16 | 17 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 18 | #pragma GCC diagnostic push 19 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 20 | #endif 21 | 22 | void test_ptr_deque() 23 | { 24 | reversible_container_test< ptr_deque, Base, Derived_class >(); 25 | reversible_container_test< ptr_deque, Value, Value >(); 26 | reversible_container_test< ptr_deque< nullable >, Base, Derived_class >(); 27 | reversible_container_test< ptr_deque< nullable >, Value, Value >(); 28 | 29 | container_assignment_test< ptr_deque, ptr_deque, 30 | Derived_class>(); 31 | container_assignment_test< ptr_deque< nullable >, 32 | ptr_deque< nullable >, 33 | Derived_class>(); 34 | container_assignment_test< ptr_deque< nullable >, 35 | ptr_deque, 36 | Derived_class>(); 37 | container_assignment_test< ptr_deque, 38 | ptr_deque< nullable >, 39 | Derived_class>(); 40 | 41 | test_transfer< ptr_deque, ptr_deque, Derived_class>(); 42 | 43 | random_access_algorithms_test< ptr_deque >(); 44 | ptr_deque di; 45 | di.push_front( new int(0) ); 46 | std::size_t size = 1u; 47 | BOOST_CHECK_EQUAL( di.size(), size ); 48 | #ifndef BOOST_NO_AUTO_PTR 49 | di.push_front( std::auto_ptr( new int(1) ) ); 50 | ++size; 51 | #endif 52 | #ifndef BOOST_NO_CXX11_SMART_PTR 53 | di.push_front( std::unique_ptr( new int(2) ) ); 54 | ++size; 55 | #endif 56 | BOOST_CHECK_EQUAL( di.size(), size ); 57 | } 58 | 59 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 60 | #pragma GCC diagnostic pop 61 | #endif 62 | 63 | using boost::unit_test::test_suite; 64 | 65 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 66 | { 67 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 68 | 69 | test->add( BOOST_TEST_CASE( &test_ptr_deque ) ); 70 | 71 | return test; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /test/ptr_inserter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2008. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | template< class T > 24 | struct caster_to 25 | { 26 | typedef T result_type; 27 | 28 | T operator()( void* obj ) const 29 | { 30 | return static_cast( obj ); 31 | } 32 | }; 33 | 34 | template< class PtrSequence > 35 | void test_ptr_inserter_helper() 36 | { 37 | using namespace boost; 38 | PtrSequence seq; 39 | const int size = 1000; 40 | for( int i = 0; i != size; ++i ) 41 | seq.push_back( i % 3 == 0 ? 0 : new int(i) ); 42 | 43 | PtrSequence seq2; 44 | // 45 | // @remark: we call .base() to avoid null pointer indirection. 46 | // The clone_inserter will handle the nulls correctly. 47 | // 48 | std::copy( boost::make_transform_iterator( seq.begin().base(), caster_to() ), 49 | boost::make_transform_iterator( seq.end().base(), caster_to() ), 50 | ptr_container::ptr_back_inserter( seq2 ) ); 51 | 52 | std::copy( boost::make_transform_iterator( seq.begin().base(), caster_to() ), 53 | boost::make_transform_iterator( seq.end().base(), caster_to() ), 54 | ptr_container::ptr_front_inserter( seq2 ) ); 55 | BOOST_CHECK_EQUAL( seq.size()*2, seq2.size() ); 56 | 57 | PtrSequence seq3; 58 | for( int i = 0; i != size; ++i ) 59 | seq3.push_back( new int(i%3) ); 60 | 61 | // 62 | // @remark: since there are no nulls in this container, it 63 | // is easier to handle. 64 | // 65 | std::copy( seq3.begin(), seq3.end(), 66 | ptr_container::ptr_inserter( seq, seq.end() ) ); 67 | BOOST_CHECK_EQUAL( seq.size(), seq2.size() ); 68 | } 69 | 70 | 71 | void test_ptr_inserter() 72 | { 73 | test_ptr_inserter_helper< boost::ptr_list< boost::nullable > >(); 74 | test_ptr_inserter_helper< boost::ptr_deque< boost::nullable > >(); 75 | 76 | 77 | } 78 | 79 | 80 | 81 | #include 82 | using boost::unit_test::test_suite; 83 | 84 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 85 | { 86 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 87 | 88 | test->add( BOOST_TEST_CASE( &test_ptr_inserter ) ); 89 | 90 | return test; 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /test/ptr_list.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #define PTR_LIST_TEST 1 13 | #define PTR_CONTAINER_DEBUG 0 14 | 15 | #include 16 | #include "sequence_test_data.hpp" 17 | #include 18 | #include 19 | 20 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 21 | #pragma GCC diagnostic push 22 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 23 | #endif 24 | 25 | void test_list() 26 | { 27 | 28 | reversible_container_test< ptr_list, Base, Derived_class >(); 29 | reversible_container_test< ptr_list, Value, Value >(); 30 | reversible_container_test< ptr_list< nullable >, Base, Derived_class >(); 31 | reversible_container_test< ptr_list< nullable >, Value, Value >(); 32 | 33 | container_assignment_test< ptr_list, ptr_list, 34 | Derived_class>(); 35 | container_assignment_test< ptr_list< nullable >, 36 | ptr_list< nullable >, 37 | Derived_class>(); 38 | container_assignment_test< ptr_list< nullable >, 39 | ptr_list, 40 | Derived_class>(); 41 | container_assignment_test< ptr_list, 42 | ptr_list< nullable >, 43 | Derived_class>(); 44 | 45 | test_transfer< ptr_list, ptr_list, Derived_class>(); 46 | 47 | random_access_algorithms_test< ptr_list >(); 48 | ptr_list list; 49 | list.push_back( new int(0) ); 50 | list.push_back( new int(2) ); 51 | list.push_back( new int(1) ); 52 | list.push_front( new int(3) ); 53 | #ifndef BOOST_NO_AUTO_PTR 54 | list.push_front( std::auto_ptr( new int(42) ) ); 55 | #endif 56 | #ifndef BOOST_NO_CXX11_SMART_PTR 57 | list.push_front( std::unique_ptr( new int(43) ) ); 58 | #endif 59 | list.reverse(); 60 | ptr_list::const_iterator it = list.begin(); 61 | BOOST_CHECK(1 == *it++); 62 | BOOST_CHECK(2 == *it++); 63 | BOOST_CHECK(0 == *it++); 64 | BOOST_CHECK(3 == *it++); 65 | #ifndef BOOST_NO_AUTO_PTR 66 | BOOST_CHECK(42 == *it++); 67 | #endif 68 | #ifndef BOOST_NO_CXX11_SMART_PTR 69 | BOOST_CHECK(43 == *it++); 70 | #endif 71 | BOOST_CHECK(list.end() == it); 72 | } 73 | 74 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 75 | #pragma GCC diagnostic pop 76 | #endif 77 | 78 | using boost::unit_test::test_suite; 79 | 80 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 81 | { 82 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 83 | 84 | test->add( BOOST_TEST_CASE( &test_list ) ); 85 | 86 | return test; 87 | } 88 | -------------------------------------------------------------------------------- /test/ptr_map_adapter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include "test_data.hpp" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using namespace std; 19 | 20 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 21 | #pragma GCC diagnostic push 22 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 23 | #endif 24 | 25 | void test_ptr_map_adapter() 26 | { 27 | //typedef_test< ptr_map, Derived >(); 28 | //typedef_test< ptr_map, Value >(); 29 | 30 | //associative_container_test< ptr_map, Base, Derived >(); 31 | //associative_container_test< ptr_map, Value, Value >(); 32 | 33 | //typedef_test< ptr_multimap, Derived >(); 34 | //typedef_test< ptr_multimap, Value >(); 35 | 36 | //associative_container_test< ptr_multimap, Base, Derived >(); 37 | //associative_container_test< ptr_multimap, Value, Value >(); 38 | 39 | string joe = "joe"; 40 | string brian = "brian"; 41 | 42 | ptr_map m; 43 | m.insert( joe, new int( 4 ) ); 44 | #ifndef BOOST_NO_AUTO_PTR 45 | m.insert( brian, std::auto_ptr( new int( 6 ) ) ); 46 | #endif 47 | #ifndef BOOST_NO_CXX11_SMART_PTR 48 | m.insert( brian, std::unique_ptr( new int( 6 ) ) ); 49 | #endif 50 | m[ joe ] += 56; 51 | m[ brian ] += 10; 52 | 53 | try 54 | { 55 | m[ "hans" ] = 4; 56 | } 57 | catch( const bad_ptr_container_operation& ) 58 | { } 59 | 60 | ptr_map m2; 61 | m2.insert( m2.begin(), *m.begin() ); 62 | BOOST_CHECK( m != m2 ); 63 | BOOST_CHECK( m2 < m ); 64 | m2.insert( m2.begin(), joe, new int(5) ); 65 | BOOST_CHECK( m != m2 ); 66 | BOOST_CHECK( m2 > m ); 67 | 68 | ptr_multimap m3; 69 | m3.insert( m3.begin(), *m.begin() ); 70 | BOOST_CHECK( m3.size() == 1u ); 71 | m3.insert( m3.begin(), brian, new int(11 ) ); 72 | BOOST_CHECK( m3.size() == 2u ); 73 | } 74 | 75 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 76 | #pragma GCC diagnostic pop 77 | #endif 78 | 79 | using boost::unit_test::test_suite; 80 | 81 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 82 | { 83 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 84 | 85 | test->add( BOOST_TEST_CASE( &test_ptr_map_adapter ) ); 86 | 87 | return test; 88 | } 89 | -------------------------------------------------------------------------------- /test/ptr_set.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include "associative_test_data.hpp" 14 | #include 15 | #include 16 | 17 | template< class SetDerived, class SetBase, class T > 18 | void test_transfer() 19 | { 20 | SetBase to; 21 | SetDerived from; 22 | from.insert( new T ); 23 | from.insert( new T ); 24 | transfer_test( from, to ); 25 | } 26 | 27 | template< class BaseContainer, class DerivedContainer, class Derived > 28 | void test_copy() 29 | { 30 | DerivedContainer derived; 31 | derived.insert( new Derived ); 32 | derived.insert( new Derived ); 33 | 34 | BaseContainer base( derived ); 35 | BOOST_CHECK_EQUAL( derived.size(), base.size() ); 36 | base.clear(); 37 | base = derived; 38 | BOOST_CHECK_EQUAL( derived.size(), base.size() ); 39 | base = base; 40 | } 41 | 42 | 43 | 44 | template< class PtrSet > 45 | void test_erase() 46 | { 47 | PtrSet s; 48 | typedef typename PtrSet::key_type T; 49 | 50 | T t; 51 | T* t2 = t.clone(); 52 | s.insert ( new T ); 53 | s.insert ( t2 ); 54 | s.insert ( new T ); 55 | BOOST_CHECK_EQUAL( s.size(), 3u ); 56 | BOOST_CHECK_EQUAL( t, *t2 ); 57 | BOOST_CHECK( ! (t < *t2) ); 58 | BOOST_CHECK( ! (*t2 < t) ); 59 | BOOST_CHECK_EQUAL( t, *t2 ); 60 | 61 | unsigned n = s.erase( t ); 62 | BOOST_CHECK( n > 0 ); 63 | } 64 | 65 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 66 | #pragma GCC diagnostic push 67 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 68 | #endif 69 | 70 | void test_set() 71 | { 72 | srand( 0 ); 73 | ptr_set_test< ptr_set, Base, Derived_class, true >(); 74 | ptr_set_test< ptr_set, Value, Value, true >(); 75 | 76 | ptr_set_test< ptr_multiset, Base, Derived_class, true >(); 77 | ptr_set_test< ptr_multiset, Value, Value, true >(); 78 | 79 | test_copy< ptr_set, ptr_set, 80 | Derived_class>(); 81 | test_copy< ptr_multiset, ptr_multiset, 82 | Derived_class>(); 83 | 84 | test_transfer< ptr_set, ptr_set, Derived_class>(); 85 | test_transfer< ptr_multiset, ptr_multiset, Derived_class>(); 86 | 87 | ptr_set set; 88 | 89 | BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); 90 | set.insert( new int(0) ); 91 | #ifndef BOOST_NO_AUTO_PTR 92 | std::auto_ptr ap( new int(1) ); 93 | set.insert( ap ); 94 | #endif 95 | #ifndef BOOST_NO_CXX11_SMART_PTR 96 | std::unique_ptr up( new int(2) ); 97 | set.insert( std::move( up ) ); 98 | #endif 99 | BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); 100 | #ifndef BOOST_NO_AUTO_PTR 101 | BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr(0) )), bad_ptr_container_operation ); 102 | #endif 103 | #if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_NULLPTR) 104 | BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr(nullptr) )), bad_ptr_container_operation ); 105 | #endif 106 | 107 | test_erase< ptr_set >(); 108 | test_erase< ptr_multiset >(); 109 | } 110 | 111 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 112 | #pragma GCC diagnostic pop 113 | #endif 114 | 115 | using boost::unit_test::test_suite; 116 | 117 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 118 | { 119 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 120 | 121 | test->add( BOOST_TEST_CASE( &test_set ) ); 122 | 123 | return test; 124 | } 125 | -------------------------------------------------------------------------------- /test/ptr_unordered_set.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include "associative_test_data.hpp" 14 | #include 15 | #include 16 | 17 | template< class SetDerived, class SetBase, class T > 18 | void test_transfer() 19 | { 20 | SetBase to; 21 | SetDerived from; 22 | from.insert( new T ); 23 | from.insert( new T ); 24 | transfer_test( from, to ); 25 | } 26 | 27 | template< class BaseContainer, class DerivedContainer, class Derived > 28 | void test_copy() 29 | { 30 | DerivedContainer derived; 31 | derived.insert( new Derived ); 32 | derived.insert( new Derived ); 33 | 34 | BaseContainer base( derived ); 35 | BOOST_CHECK_EQUAL( derived.size(), base.size() ); 36 | base.clear(); 37 | base = derived; 38 | BOOST_CHECK_EQUAL( derived.size(), base.size() ); 39 | base = base; 40 | } 41 | 42 | template< class Cont, class T > 43 | void test_unordered_interface() 44 | { 45 | Cont c; 46 | T* t = new T; 47 | c.insert( t ); 48 | typename Cont::local_iterator i = c.begin( 0 ); 49 | typename Cont::const_local_iterator ci = i; 50 | ci = c.cbegin( 0 ); 51 | i = c.end( 0 ); 52 | ci = c.cend( 0 ); 53 | typename Cont::size_type s = c.bucket_count(); 54 | hide_warning(s); 55 | s = c.max_bucket_count(); 56 | s = c.bucket_size( 0 ); 57 | s = c.bucket( *t ); 58 | float f = c.load_factor(); 59 | f = c.max_load_factor(); 60 | c.max_load_factor(f); 61 | c.rehash(1000); 62 | } 63 | 64 | 65 | 66 | template< class PtrSet > 67 | void test_erase() 68 | { 69 | PtrSet s; 70 | typedef typename PtrSet::key_type T; 71 | 72 | T t; 73 | s.insert ( new T ); 74 | T* t2 = t.clone(); 75 | s.insert ( t2 ); 76 | s.insert ( new T ); 77 | BOOST_CHECK_EQUAL( s.size(), 3u ); 78 | BOOST_CHECK_EQUAL( hash_value(t), hash_value(*t2) ); 79 | BOOST_CHECK_EQUAL( t, *t2 ); 80 | 81 | typename PtrSet::iterator i = s.find( t ); 82 | 83 | BOOST_CHECK( i != s.end() ); 84 | unsigned n = s.erase( t ); 85 | BOOST_CHECK( n > 0 ); 86 | } 87 | 88 | 89 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 90 | #pragma GCC diagnostic push 91 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 92 | #endif 93 | 94 | void test_set() 95 | { 96 | srand( 0 ); 97 | ptr_set_test< ptr_unordered_set, Base, Derived_class, false >(); 98 | ptr_set_test< ptr_unordered_set, Value, Value, false >(); 99 | 100 | ptr_set_test< ptr_unordered_multiset, Base, Derived_class, false >(); 101 | ptr_set_test< ptr_unordered_multiset, Value, Value, false >(); 102 | 103 | test_copy< ptr_unordered_set, ptr_unordered_set, 104 | Derived_class>(); 105 | test_copy< ptr_unordered_multiset, ptr_unordered_multiset, 106 | Derived_class>(); 107 | 108 | test_transfer< ptr_unordered_set, ptr_unordered_set, Derived_class>(); 109 | test_transfer< ptr_unordered_multiset, ptr_unordered_multiset, Derived_class>(); 110 | 111 | ptr_unordered_set set; 112 | 113 | BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); 114 | set.insert( new int(0) ); 115 | #ifndef BOOST_NO_AUTO_PTR 116 | std::auto_ptr ap( new int(1) ); 117 | set.insert( ap ); 118 | #endif 119 | #ifndef BOOST_NO_CXX11_SMART_PTR 120 | std::unique_ptr up( new int(2) ); 121 | set.insert( std::move( up ) ); 122 | #endif 123 | BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); 124 | #ifndef BOOST_NO_AUTO_PTR 125 | BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr(0) )), bad_ptr_container_operation ); 126 | #endif 127 | #if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_CXX11_NULLPTR) 128 | BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr(nullptr) )), bad_ptr_container_operation ); 129 | #endif 130 | 131 | test_unordered_interface< ptr_unordered_set, Derived_class >(); 132 | test_unordered_interface< ptr_unordered_multiset, Derived_class >(); 133 | 134 | test_erase< ptr_unordered_set >(); 135 | test_erase< ptr_unordered_multiset >(); 136 | } 137 | 138 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 139 | #pragma GCC diagnostic pop 140 | #endif 141 | 142 | using boost::unit_test::test_suite; 143 | 144 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 145 | { 146 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 147 | 148 | test->add( BOOST_TEST_CASE( &test_set ) ); 149 | 150 | return test; 151 | } 152 | -------------------------------------------------------------------------------- /test/ptr_vector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include "sequence_test_data.hpp" 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 20 | #pragma GCC diagnostic push 21 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 22 | #endif 23 | 24 | void test_ptr_vector() 25 | { 26 | reversible_container_test< ptr_vector, Base, Derived_class >(); 27 | reversible_container_test< ptr_vector, Value, Value >(); 28 | 29 | #ifdef BOOST_NO_SFINAE 30 | #else 31 | reversible_container_test< ptr_vector< nullable >, Base, Derived_class >(); 32 | reversible_container_test< ptr_vector< nullable >, Value, Value >(); 33 | #endif 34 | 35 | container_assignment_test< ptr_vector, ptr_vector, 36 | Derived_class>(); 37 | container_assignment_test< ptr_vector< nullable >, 38 | ptr_vector< nullable >, 39 | Derived_class>(); 40 | container_assignment_test< ptr_vector< nullable >, 41 | ptr_vector, 42 | Derived_class>(); 43 | container_assignment_test< ptr_vector, 44 | ptr_vector< nullable >, 45 | Derived_class>(); 46 | 47 | test_transfer< ptr_vector, ptr_vector, Derived_class>(); 48 | test_transfer< ptr_vector, ptr_list, Derived_class>(); 49 | 50 | random_access_algorithms_test< ptr_vector >(); 51 | 52 | 53 | ptr_vector vec( 100u ); 54 | BOOST_CHECK( vec.capacity() >= 100u ); 55 | 56 | #ifdef BOOST_PTR_CONTAINER_NO_EXCEPTIONS 57 | #else 58 | 59 | BOOST_CHECK_THROW( vec.push_back(0), bad_ptr_container_operation ); 60 | BOOST_CHECK_THROW( (vec.insert( vec.begin(), 0 )), bad_ptr_container_operation ); 61 | BOOST_CHECK_THROW( vec.at( 42 ), bad_ptr_container_operation ); 62 | vec.push_back( new int(0) ); 63 | BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation ); 64 | BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation ); 65 | BOOST_CHECK_THROW( (vec.replace(vec.begin(), 0 )), bad_ptr_container_operation ); 66 | 67 | #endif 68 | 69 | vec.clear(); 70 | assign::push_back( vec )( new int(2) ) 71 | ( new int(4) ) 72 | ( new int(6) ) 73 | ( new int(8) ); 74 | ptr_vector vec2; 75 | assign::push_back( vec2 ) 76 | ( new int(1) ) 77 | ( new int(3) ) 78 | ( new int(5) ) 79 | ( new int(7) ); 80 | BOOST_CHECK_EQUAL( vec.size(), vec2.size() ); 81 | BOOST_CHECK( vec > vec2 ); 82 | BOOST_CHECK( vec != vec2 ); 83 | BOOST_CHECK( !(vec == vec2) ); 84 | BOOST_CHECK( vec2 < vec ); 85 | BOOST_CHECK( vec2 <= vec ); 86 | BOOST_CHECK( vec >= vec2 ); 87 | 88 | const int data_size = 10; 89 | int** array = new int*[data_size]; 90 | for( int i = 0; i != data_size; ++i ) 91 | array[i] = new int(i); 92 | 93 | vec.transfer( vec.begin(), array, data_size ); 94 | int** array2 = vec.c_array(); 95 | BOOST_CHECK( array2 != array ); 96 | 97 | } 98 | 99 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) 100 | #pragma GCC diagnostic pop 101 | #endif 102 | 103 | using boost::unit_test::test_suite; 104 | 105 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 106 | { 107 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 108 | 109 | test->add( BOOST_TEST_CASE( &test_ptr_vector ) ); 110 | 111 | return test; 112 | } 113 | -------------------------------------------------------------------------------- /test/ptr_vector_size.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | 14 | template class 15 | boost::ptr_vector; 16 | 17 | template class 18 | boost::ptr_vector; 19 | 20 | template class 21 | boost::ptr_vector; 22 | 23 | template class 24 | boost::ptr_vector; 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/simple_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | // 20 | // A simple polymorphic class 21 | // 22 | class Poly 23 | { 24 | int i_; 25 | static int cnt_; 26 | 27 | public: 28 | Poly() : i_( cnt_++ ) { } 29 | virtual ~Poly() { } 30 | void foo() { doFoo(); } 31 | 32 | private: 33 | virtual void doFoo() { ++i_; } 34 | 35 | public: 36 | friend inline bool operator>( const Poly& l, const Poly r ) 37 | { 38 | return l.i_ > r.i_; 39 | } 40 | }; 41 | 42 | int Poly::cnt_ = 0; 43 | 44 | // 45 | // Normally we need something like this to compare pointers to objects 46 | // 47 | template< typename T > 48 | struct sptr_greater 49 | { 50 | bool operator()( const boost::shared_ptr& l, const boost::shared_ptr& r ) const 51 | { 52 | return *l > *r; 53 | } 54 | }; 55 | 56 | // 57 | // one doesn't need to introduce new names or live with long ones 58 | // 59 | typedef boost::shared_ptr PolyPtr; 60 | 61 | 62 | void simple_test() 63 | { 64 | enum { size = 2000 }; 65 | typedef vector vector_t; 66 | typedef boost::ptr_vector ptr_vector_t; 67 | vector_t svec; 68 | ptr_vector_t pvec; 69 | 70 | for( int i = 0; i < size; ++i ) 71 | { 72 | svec.push_back( PolyPtr( new Poly ) ); 73 | pvec.push_back( new Poly ); // no extra syntax 74 | } 75 | 76 | for( int i = 0; i < size; ++i ) 77 | { 78 | svec[i]->foo(); 79 | pvec[i].foo(); // automatic indirection 80 | svec[i] = PolyPtr( new Poly ); 81 | pvec.replace( i, new Poly ); // direct pointer assignment not possible, original element is deleted 82 | } 83 | 84 | for( vector_t::iterator i = svec.begin(); i != svec.end(); ++i ) 85 | (*i)->foo(); 86 | 87 | for( ptr_vector_t::iterator i = pvec.begin(); i != pvec.end(); ++i ) 88 | i->foo(); // automatic indirection 89 | } 90 | 91 | #include 92 | using boost::unit_test::test_suite; 93 | 94 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 95 | { 96 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); 97 | 98 | test->add( BOOST_TEST_CASE( &simple_test ) ); 99 | 100 | return test; 101 | } 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /test/tut34.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | template< class T > 18 | struct my_ptr_vector : 19 | public boost::ptr_sequence_adapter< std::vector > 20 | { 21 | 22 | }; 23 | 24 | 25 | template< class Key, class T, class Pred = std::less, 26 | class Allocator = std::allocator< std::pair > > 27 | struct my_map : public std::map 28 | { 29 | explicit my_map( const Pred& pred = Pred(), 30 | const Allocator& alloc = Allocator() ) 31 | { } 32 | }; 33 | 34 | #include 35 | struct Foo {}; 36 | 37 | typedef boost::ptr_map_adapter< my_map > foo_map; 38 | 39 | template< class Key, class T, class Pred = std::less > 40 | struct my_ptr_map : public boost::ptr_map_adapter< std::map > 41 | { 42 | 43 | }; 44 | 45 | typedef my_ptr_map foo_map2; 46 | 47 | 48 | int main() 49 | { 50 | 51 | my_ptr_vector vec; 52 | vec.push_back( new Foo ); 53 | foo_map m1; 54 | foo_map2 m2; 55 | std::string s(""); 56 | m1.insert( s, new Foo ); 57 | m2.insert( s, new Foo ); 58 | 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /test/view_example.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Boost.Pointer Container 3 | // 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 5 | // distribution is subject to the Boost Software License, Version 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // For more information, see http://www.boost.org/libs/ptr_container/ 10 | // 11 | 12 | // 13 | // This example is intended to show you how to 14 | // use the 'view_clone_manager'. The idea 15 | // is that we have a container of non-polymorphic 16 | // objects and want to keep then sorted by different 17 | // criteria at the same time. 18 | // 19 | 20 | // 21 | // We'll go for 'ptr_vector' here. Using a node-based 22 | // container would be a waste of space here. 23 | // All container headers will also include 24 | // the Clone Managers. 25 | // 26 | #include 27 | #include 28 | 29 | #include // For 'binary_fnuction' 30 | #include // For 'rand()' 31 | #include // For 'std::sort()' 32 | #include // For 'std::cout' 33 | 34 | using namespace std; 35 | 36 | // 37 | // This is our simple example data-structure. It can 38 | // be ordered in three ways. 39 | // 40 | struct photon 41 | { 42 | photon() : color( rand() ), 43 | direction( rand() ), 44 | power( rand() ) 45 | { } 46 | 47 | int color; 48 | int direction; 49 | int power; 50 | }; 51 | 52 | // 53 | // Our big container is a standard vector 54 | // 55 | typedef std::vector vector_type; 56 | 57 | // 58 | // Now we define our view type by adding a second template argument. 59 | // The 'view_clone_manager' will implements Cloning by taking address 60 | // of objects. 61 | // 62 | // Notice the first template argument is 'photon' and not 63 | // 'const photon' to allow the view container write access. 64 | // 65 | typedef boost::ptr_vector view_type; 66 | 67 | // 68 | // Our first sort criterium 69 | // 70 | struct sort_by_color 71 | { 72 | typedef photon first_argument_type; 73 | typedef photon second_argument_type; 74 | typedef bool result_type; 75 | 76 | bool operator()( const photon& l, const photon& r ) const 77 | { 78 | return l.color < r.color; 79 | } 80 | }; 81 | 82 | // 83 | // Our second sort criterium 84 | // 85 | struct sort_by_direction 86 | { 87 | typedef photon first_argument_type; 88 | typedef photon second_argument_type; 89 | typedef bool result_type; 90 | 91 | bool operator()( const photon& l, const photon& r ) const 92 | { 93 | return l.direction < r.direction; 94 | } 95 | }; 96 | 97 | 98 | // 99 | // Our third sort criterium 100 | // 101 | struct sort_by_power 102 | { 103 | typedef photon first_argument_type; 104 | typedef photon second_argument_type; 105 | typedef bool result_type; 106 | 107 | bool operator()( const photon& l, const photon& r ) const 108 | { 109 | return l.power < r.power; 110 | } 111 | }; 112 | 113 | // 114 | // This function inserts "Clones" into the 115 | // the view. 116 | // 117 | // We need to pass the first argument 118 | // as a non-const reference to be able to store 119 | // 'T*' instead of 'const T*' objects. Alternatively, 120 | // we might change the declaration of the 'view_type' 121 | // to 122 | // typedef boost::ptr_vector 123 | // view_type; ^^^^^^ 124 | // 125 | void insert( vector_type& from, view_type& to ) 126 | { 127 | to.insert( to.end(), 128 | from.begin(), 129 | from.end() ); 130 | } 131 | 132 | int main() 133 | { 134 | enum { sz = 10, count = 500 }; 135 | 136 | // 137 | // First we create the main container and two views 138 | // 139 | std::vector photons; 140 | view_type color_view; 141 | view_type direction_view; 142 | 143 | // 144 | // Then we fill the main container with some random data 145 | // 146 | for( int i = 0; i != sz; ++i ) 147 | { 148 | photons.push_back( vector_type() ); 149 | 150 | for( int j = 0; j != count; ++j ) 151 | photons[i].push_back( photon() ); 152 | } 153 | 154 | // 155 | // Then we create the two views. 156 | // 157 | for( int i = 0; i != sz; ++i ) 158 | { 159 | insert( photons[i], color_view ); 160 | insert( photons[i], direction_view ); 161 | } 162 | 163 | // 164 | // First we sort the original photons, using one of 165 | // the view classes. This may sound trivial, but consider that 166 | // the objects are scatered all around 'sz' different vectors; 167 | // the view makes them act as one big vector. 168 | // 169 | std::sort( color_view.begin(), color_view.end(), sort_by_power() ); 170 | 171 | // 172 | // And now we can sort the views themselves. Notice how 173 | // we switch to different iterators and different predicates: 174 | // 175 | color_view.sort( sort_by_color() ); 176 | 177 | direction_view.sort( sort_by_direction() ); 178 | 179 | return 0; 180 | } 181 | --------------------------------------------------------------------------------