Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48725 - sandbox/move/libs/move/doc
From: daniel_james_at_[hidden]
Date: 2008-09-11 03:11:01


Author: danieljames
Date: 2008-09-11 03:11:00 EDT (Thu, 11 Sep 2008)
New Revision: 48725
URL: http://svn.boost.org/trac/boost/changeset/48725

Log:
Combine all the listings into one file, so that they all compile.
Removed:
   sandbox/move/libs/move/doc/listing2.cpp
   sandbox/move/libs/move/doc/listing3.cpp
Text files modified:
   sandbox/move/libs/move/doc/listing1.cpp | 53 +++++++++++++++++++++++++++++++++------
   sandbox/move/libs/move/doc/move.qbk | 22 +++++++---------
   2 files changed, 55 insertions(+), 20 deletions(-)

Modified: sandbox/move/libs/move/doc/listing1.cpp
==============================================================================
--- sandbox/move/libs/move/doc/listing1.cpp (original)
+++ sandbox/move/libs/move/doc/listing1.cpp 2008-09-11 03:11:00 EDT (Thu, 11 Sep 2008)
@@ -1,4 +1,4 @@
-//[listing1
+//[movable_example
 #include <iostream>
 #include <algorithm>
 
@@ -58,14 +58,14 @@
     implementation* member;
 };
 
-void example1()
+void movable_example()
 {
     movable x(10);
     movable y = x;
 }
 //]
 
-//[move_only
+//[move_only_example
 class move_only : public boost::equality_comparable<move_only>
 {
     move_only(move_only&);
@@ -98,16 +98,53 @@
     implementation* member;
 };
 
-void example2()
+void move_only_example()
 {
     move_only x(20);
     move_only y = boost::move(x);
 }
 //]
 
+//[return_example
+//...
+move_only f(int x, int y)
+{ return move_only(x * y); }
+
+void return_example()
+{
+ move_only x = f(10, 5);
+ move_only y;
+ y = f(4,3);
+}
+//]
+
+//[sink_example
+//...
+movable g(int x, int y)
+{ return movable(x * y); }
+
+struct sink
+{
+ explicit sink(movable x) : member(boost::move(x)) { }
+
+ movable member;
+};
+
+void example4()
+{
+ movable x = g(10, 5);
+ sink y(x); // must copy.
+ sink z(g(20, 2)); // no copy.
+}
+//]
+
 int main() {
- std::cout<<"Example 1:\n\n";
- example1();
- std::cout<<"\nExample 2:\n\n";
- example2();
+ std::cout<<"Movable Example:\n\n";
+ movable_example();
+ std::cout<<"\nMove Only Example:\n\n";
+ move_only_example();
+ std::cout<<"\nReturn Example:\n\n";
+ return_example();
+ std::cout<<"\nSink Example:\n\n";
+ sink_example();
 }

Deleted: sandbox/move/libs/move/doc/listing2.cpp
==============================================================================
--- sandbox/move/libs/move/doc/listing2.cpp 2008-09-11 03:11:00 EDT (Thu, 11 Sep 2008)
+++ (empty file)
@@ -1,14 +0,0 @@
-//[listing2
-//...
-movable f(int x, int y)
-{ return movable(x * y); }
-
-int main()
-{
- movable x = f(10, 5);
- movable y;
- y = f(4, 3);
-
- return 0;
-}
-//]

Deleted: sandbox/move/libs/move/doc/listing3.cpp
==============================================================================
--- sandbox/move/libs/move/doc/listing3.cpp 2008-09-11 03:11:00 EDT (Thu, 11 Sep 2008)
+++ (empty file)
@@ -1,19 +0,0 @@
-//[listing3
-//...
-
-struct sink
-{
- explicit sink(movable x) : member(boost::move(x)) { }
-
- movable member;
-};
-
-int main()
-{
- movable x = f(10, 5);
- sink y(x); // must copy.
- sink z(f(20, 2)); // no copy.
-
- return 0;
-}
-//]

Modified: sandbox/move/libs/move/doc/move.qbk
==============================================================================
--- sandbox/move/libs/move/doc/move.qbk (original)
+++ sandbox/move/libs/move/doc/move.qbk 2008-09-11 03:11:00 EDT (Thu, 11 Sep 2008)
@@ -52,13 +52,13 @@
 contents with the operand. This is similar to the copy-ctor and swap idiom for implementing
 assignment.
         
-'''<xref linkend="listing1"/>''' shows an example movable class that implements a typical pointer-to-implementation
+'''<xref linkend="movable_example"/>''' shows an example movable class that implements a typical pointer-to-implementation
 (PiPl) idiom and shows that it can be used as any regular type.
 
 [import listing1.cpp]
-'''<example id="listing1">
+'''<example id="movable_example">
 <title>Movable class</title>
-'''[listing1]'''
+'''[movable_example]'''
 <simpara>Output:</simpara>
 <screen>
 copy remote part: 10
@@ -69,9 +69,9 @@
 
 [section Move Only]
 
-'''<example id="listing1.1">
+'''<example id="move_only_example">
 <title>Movable class</title>
-'''[move_only]'''
+'''[move_only_example]'''
 <simpara>Output:</simpara>
 <screen>
 </screen>
@@ -86,10 +86,9 @@
 We can return a movable type from a function by value and unnessary copies will be avoided as
 the following example illustrates:
 
-[import listing2.cpp]
-'''<example id="listing2">
+'''<example id="return_example">
 <title>Return a movable type</title>
-'''[listing2]'''
+'''[return_example]'''
 <simpara>Output:</simpara>
 <screen>
 
@@ -109,13 +108,12 @@
 A sink is often a constructor or an insert function on a container. The `operator=()` on a movable
 type is a form of a sink function. To implement a sink function pass the argument by value and then
 use `boost::move()` to move the argument into place. Note that this technique cannot be used to
-implement `operator=()` on because it relies on assignment. '''<xref linkend="listing3"/>''' implements an example sink
+implement `operator=()` on because it relies on assignment. '''<xref linkend="sink_example"/>''' implements an example sink
 function.
 
-[import listing3.cpp]
-'''<example id="listing3">
+'''<example id="sink_example">
 <title>Sink Function</title>
-'''[listing3]'''
+'''[sink_example]'''
 <simpara>Output:</simpara>
 <screen>
 copy remote part: 50


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk