From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../libs/smart_ptr/example/scoped_ptr_example.cpp | 23 ++++++ .../libs/smart_ptr/example/scoped_ptr_example.hpp | 29 +++++++ .../smart_ptr/example/scoped_ptr_example_test.cpp | 17 ++++ .../libs/smart_ptr/example/shared_ptr_example.cpp | 95 ++++++++++++++++++++++ .../libs/smart_ptr/example/shared_ptr_example2.cpp | 22 +++++ .../libs/smart_ptr/example/shared_ptr_example2.hpp | 31 +++++++ .../smart_ptr/example/shared_ptr_example2_test.cpp | 22 +++++ 7 files changed, 239 insertions(+) create mode 100644 src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp create mode 100644 src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp create mode 100644 src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp create mode 100644 src/boost/libs/smart_ptr/example/shared_ptr_example.cpp create mode 100644 src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp create mode 100644 src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp create mode 100644 src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp (limited to 'src/boost/libs/smart_ptr/example') diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp new file mode 100644 index 000000000..3dcfbb1f2 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example.cpp @@ -0,0 +1,23 @@ +// Boost scoped_ptr_example implementation file -----------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "scoped_ptr_example.hpp" +#include + +class example::implementation +{ + public: + ~implementation() { std::cout << "destroying implementation\n"; } +}; + +example::example() : _imp( new implementation ) {} + +void example::do_something() { std::cout << "did something\n"; } + +example::~example() {} diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp new file mode 100644 index 000000000..0d9c603ea --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example.hpp @@ -0,0 +1,29 @@ +// Boost scoped_ptr_example header file ------------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include +#include + +// The point of this example is to prove that even though +// example::implementation is an incomplete type in translation units using +// this header, scoped_ptr< implementation > is still valid because the type +// is complete where it counts - in the inplementation translation unit where +// destruction is actually instantiated. + +class example : private boost::noncopyable +{ + public: + example(); + ~example(); + void do_something(); + private: + class implementation; + boost::scoped_ptr< implementation > _imp; // hide implementation details +}; + diff --git a/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp b/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp new file mode 100644 index 000000000..26b3a1810 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/scoped_ptr_example_test.cpp @@ -0,0 +1,17 @@ +// Boost scoped_ptr_example_test main program -------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "scoped_ptr_example.hpp" + +int main() +{ + example my_example; + my_example.do_something(); + return 0; +} diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp new file mode 100644 index 000000000..c3b1f3b42 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example.cpp @@ -0,0 +1,95 @@ +// Boost shared_ptr_example.cpp --------------------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +// Revision History +// 21 May 01 Initial complete version (Beman Dawes) + +// The original code for this example appeared in the shared_ptr documentation. +// Ray Gallimore pointed out that foo_set was missing a Compare template +// argument, so would not work as intended. At that point the code was +// turned into an actual .cpp file so it could be compiled and tested. + +#include +#include +#include +#include +#include + +// The application will produce a series of +// objects of type Foo which later must be +// accessed both by occurrence (std::vector) +// and by ordering relationship (std::set). + +struct Foo +{ + Foo( int _x ) : x(_x) {} + ~Foo() { std::cout << "Destructing a Foo with x=" << x << "\n"; } + int x; + /* ... */ +}; + +typedef boost::shared_ptr FooPtr; + +struct FooPtrOps +{ + bool operator()( const FooPtr & a, const FooPtr & b ) + { return a->x > b->x; } + void operator()( const FooPtr & a ) + { std::cout << a->x << "\n"; } +}; + +int main() +{ + std::vector foo_vector; + std::set foo_set; // NOT multiset! + + FooPtr foo_ptr( new Foo( 2 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset( new Foo( 1 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset( new Foo( 3 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + foo_ptr.reset ( new Foo( 2 ) ); + foo_vector.push_back( foo_ptr ); + foo_set.insert( foo_ptr ); + + std::cout << "foo_vector:\n"; + std::for_each( foo_vector.begin(), foo_vector.end(), FooPtrOps() ); + + std::cout << "\nfoo_set:\n"; + std::for_each( foo_set.begin(), foo_set.end(), FooPtrOps() ); + std::cout << "\n"; + +// Expected output: +// +// foo_vector: +// 2 +// 1 +// 3 +// 2 +// +// foo_set: +// 3 +// 2 +// 1 +// +// Destructing a Foo with x=2 +// Destructing a Foo with x=1 +// Destructing a Foo with x=3 +// Destructing a Foo with x=2 + + return 0; +} + diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp new file mode 100644 index 000000000..fdefc8d91 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2.cpp @@ -0,0 +1,22 @@ +// Boost shared_ptr_example2 implementation file -----------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "shared_ptr_example2.hpp" +#include + +class example::implementation +{ + public: + ~implementation() { std::cout << "destroying implementation\n"; } +}; + +example::example() : _imp( new implementation ) {} + +void example::do_something() + { std::cout << "use_count() is " << _imp.use_count() << "\n"; } diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp new file mode 100644 index 000000000..5ca7a07db --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2.hpp @@ -0,0 +1,31 @@ +// Boost shared_ptr_example2 header file -----------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include + +// This example demonstrates the handle/body idiom (also called pimpl and +// several other names). It separates the interface (in this header file) +// from the implementation (in shared_ptr_example2.cpp). + +// Note that even though example::implementation is an incomplete type in +// some translation units using this header, shared_ptr< implementation > +// is still valid because the type is complete where it counts - in the +// shared_ptr_example2.cpp translation unit where functions requiring a +// complete type are actually instantiated. + +class example +{ +public: + example(); + void do_something(); +private: + class implementation; + boost::shared_ptr< implementation > _imp; // hide implementation details +}; + diff --git a/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp b/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp new file mode 100644 index 000000000..2702cb871 --- /dev/null +++ b/src/boost/libs/smart_ptr/example/shared_ptr_example2_test.cpp @@ -0,0 +1,22 @@ +// Boost shared_ptr_example2_test main program ------------------------------// + +// Copyright Beman Dawes 2001. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org/libs/smart_ptr for documentation. + +#include "shared_ptr_example2.hpp" + +int main() +{ + example a; + a.do_something(); + example b(a); + b.do_something(); + example c; + c = a; + c.do_something(); + return 0; +} -- cgit v1.2.3