$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r51039 - in sandbox/thread_safe_signals/trunk/libs/signals2: doc example
From: fmhess_at_[hidden]
Date: 2009-02-05 17:10:15
Author: fmhess
Date: 2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
New Revision: 51039
URL: http://svn.boost.org/trac/boost/changeset/51039
Log:
Added a bunch of example programs extracted from tutorial.
Added:
   sandbox/thread_safe_signals/trunk/libs/signals2/doc/examples.xml   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_multi_slot.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_slot.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/ordering_slots.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp   (contents, props changed)
   sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp   (contents, props changed)
Text files modified: 
   sandbox/thread_safe_signals/trunk/libs/signals2/doc/Makefile                         |     1 +                                       
   sandbox/thread_safe_signals/trunk/libs/signals2/doc/signals.xml                      |     1 +                                       
   sandbox/thread_safe_signals/trunk/libs/signals2/doc/tutorial.xml                     |    19 +++++++++++++------                     
   sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm.cpp             |     2 +-                                      
   sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm_deconstruct.cpp |     2 +-                                      
   5 files changed, 17 insertions(+), 8 deletions(-)
Modified: sandbox/thread_safe_signals/trunk/libs/signals2/doc/Makefile
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/doc/Makefile	(original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/doc/Makefile	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -4,6 +4,7 @@
 BOOSTBOOK_TOOL_DIR=$(BOOST_SRC_DIR)/tools/boostbook
 
 XML_SRCS=\
+	examples.xml \
         faq.xml \
         introduction.xml \
         porting.xml \
Added: sandbox/thread_safe_signals/trunk/libs/signals2/doc/examples.xml
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/doc/examples.xml	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,167 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
+  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<section last-revision="$Date: 2007-06-12 14:01:23 -0400 (Tue, 12 Jun 2007) $" id="signals2.examples">
+  <title>Example programs</title>
+
+  <using-namespace name="boost"/>
+  <using-namespace name="boost::signals2"/>
+
+  <section id="signals2.examples.misc">
+    <title>Miscellaneous</title>
+    <section id="signals2.examples.tutorial.hello_world_slot">
+      <title>hello_world_slot</title>
+      <para>
+        This is a basic example of connecting a slot to a signal
+        and then invoking the signal.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/hello_world_slot.cpp">hello_world_slot.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.hello_world_multi_slot">
+      <title>hello_world_multi_slot</title>
+      <para>
+        This extends the hello_world_slot example slightly by connecting more than one
+        slot to the signal before invoking it.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/hello_world_multi_slot.cpp">hello_world_multi_slot.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.ordering_slots">
+      <title>ordering_slots</title>
+      <para>
+        This extends the hello_world_multi_slot example slightly by
+        using slot groups to specify
+        the order slots should be invoked.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/ordering_slots.cpp">ordering_slots.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.slot_arguments">
+      <title>slot_arguments</title>
+      <para>
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/slot_arguments.cpp">slot_arguments.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.signal_return_value">
+      <title>signal_return_value</title>
+      <para>
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/signal_return_value.cpp">signal_return_value.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.custom_combiners">
+      <title>custom_combiners</title>
+      <para>
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/custom_combiners.cpp">custom_combiners.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.disconnect_and_block">
+      <title>disconnect_and_block</title>
+      <para>
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/disconnect_and_block.cpp">disconnect_and_block.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.tutorial.passing_slots">
+      <title>passing_slots</title>
+      <para>
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/passing_slots.cpp">passing_slots.cpp</ulink>.
+      </para>
+    </section>
+  </section>
+  <section id="signals2.examples.document-view">
+    <title>Document-View</title>
+    <section id="signals2.examples.document-view.doc_view">
+      <title>doc_view</title>
+      <para>
+        This is the document-view example program which is described in the
+        <link linkend="signals2.tutorial.document-view">tutorial</link>.  It shows
+        usage of a signal and slots to implement two different views of
+        a text document.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/doc_view.cpp">doc_view.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.document-view.doc_view_acm">
+      <title>doc_view_acm</title>
+      <para>
+        This program modifies the original doc_view.cpp example to employ
+        automatic connection management.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/doc_view_acm.cpp">doc_view_acm.cpp</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.document-view.doc_view_acm_deconstruct">
+      <title>doc_view_acm_deconstruct</title>
+      <para>
+        This program modifies the doc_view_acm.cpp example to use postconstructors
+        and the <functionname>deconstruct()</functionname> factory function.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/doc_view_acm_deconstruct.cpp">doc_view_acm_deconstruct.cpp</ulink>.
+      </para>
+    </section>
+  </section>
+  <section id="signals2.examples.deconstruct">
+    <title>Postconstructors and Predestructors with <functionname>deconstruct()</functionname></title>
+    <section id="signals2.examples.deconstruct.postconstructor_ex1">
+      <title>postconstructor_ex1</title>
+      <para>
+        This program is a basic example of how to define a class with a postconstructor which
+        uses <functionname>deconstruct()</functionname> as its factory function.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/postconstructor_ex1.cpp">postconstructor_ex1</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.deconstruct.postconstructor_ex2">
+      <title>postconstructor_ex2</title>
+      <para>
+        This program extends the postconstructor_ex1 example slightly, by additionally passing arguments from
+        the <functionname>deconstruct()</functionname> call through to the class' constructor
+        and postconstructor.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/postconstructor_ex2.cpp">postconstructor_ex2</ulink>.
+      </para>
+    </section>
+    <section id="signals2.examples.deconstruct.predestructor_example">
+      <title>predestructor_example</title>
+      <para>
+        This program is a basic example of how to define a class with a predestructor which
+        uses <functionname>deconstruct()</functionname> as its factory function.
+      </para>
+      <para>
+  <!-- FIXME: url needs to have two "../" stripped from it to work once we are merged into main boost doc build -->
+        Download <ulink url="../../../../libs/signals2/example/predestructor_example.cpp">predestructor_example</ulink>.
+      </para>
+    </section>
+  </section>
+</section>
Modified: sandbox/thread_safe_signals/trunk/libs/signals2/doc/signals.xml
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/doc/signals.xml	(original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/doc/signals.xml	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -45,6 +45,7 @@
 <title>Boost.Signals2</title>
   <xi:include href="introduction.xml"/>
   <xi:include href="tutorial.xml"/>
+  <xi:include href="examples.xml"/>
   <xi:include href="reference/reference.xml"/>
   <xi:include href="thread_safety.xml"/>
   <xi:include href="faq.xml"/>
Modified: sandbox/thread_safe_signals/trunk/libs/signals2/doc/tutorial.xml
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/doc/tutorial.xml	(original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/doc/tutorial.xml	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -240,9 +240,16 @@
 <code>boost::signals2::at_front</code> or <code>boost::signals2::at_back</code>
 as the last parameter to <code><methodname
 alt="boost::signals2::signalN::connect">connect</methodname></code>, respectively), and defaults to the end of the list. When
-a group is specified, the final parameter describes where the slot
-will be placed within the group ordering. If we add a new slot
-to our example like this:</para>
+a group is specified, the final <code>at_front</code> or <code>at_back</code>
+parameter describes where the slot
+will be placed within the group ordering.  Ungrouped slots connected with
+<code>at_front</code> will always precede all grouped slots.  Ungrouped
+slots connected with <code>at_back</code> will always succeed all
+grouped slots.
+</para>
+<para>
+  If we add a new slot to our example like this:
+</para>
 <programlisting>
 struct GoodMorning
 {
@@ -1006,7 +1013,7 @@
 </section>
 </section>
 
-<section>
+<section id="signals2.tutorial.document-view">
   <title>Example: Document-View</title>
 
   <para>Signals can be used to implement flexible Document-View
@@ -1139,8 +1146,8 @@
 }</programlisting>
 
   <para>The complete example source, contributed by Keith MacDonald,
-    is available in <ulink
-    url="../../libs/signals/example/doc_view.cpp"><code>libs/signals/example/doc_view.cpp</code></ulink>.</para>
+    is available in the <link linkend="signals2.examples.document-view">examples</link> section.
+  </para>
 </section>
 
   <section id="signals2.tutorial.extended-slot-type">
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/custom_combiners.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,101 @@
+// Example program showing signals with custom combiners.
+//
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+#include <vector>
+
+float product(float x, float y) { return x * y; }
+float quotient(float x, float y) { return x / y; }
+float sum(float x, float y) { return x + y; }
+float difference(float x, float y) { return x - y; }
+
+// combiner which returns the maximum value returned by all slots
+template<typename T>
+struct maximum
+{
+  typedef T result_type;
+
+  template<typename InputIterator>
+  T operator()(InputIterator first, InputIterator last) const
+  {
+    // If there are no slots to call, just return the
+    // default-constructed value
+    if(first == last ) return T();
+    T max_value = *first++;
+    while (first != last) {
+      if (max_value < *first)
+        max_value = *first;
+      ++first;
+    }
+
+    return max_value;
+  }
+};
+
+void maximum_combiner_example()
+{
+  // signal which uses our custom "maximum" combiner
+  boost::signals2::signal<float (float x, float y), maximum<float> > sig;
+
+  sig.connect(&product);
+  sig.connect("ient);
+  sig.connect(&sum);
+  sig.connect(&difference);
+
+  // Outputs the maximum value returned by the connected slots, in this case
+  // 15 from the product function.
+  std::cout << "maximum: " << sig(5, 3) << std::endl;
+}
+
+// aggregate_values is a combiner which places all the values returned
+// from slots into a container
+template<typename Container>
+struct aggregate_values
+{
+  typedef Container result_type;
+
+  template<typename InputIterator>
+  Container operator()(InputIterator first, InputIterator last) const
+  {
+    Container values;
+
+    while(first != last) {
+      values.push_back(*first);
+      ++first;
+    }
+    return values;
+  }
+};
+
+void aggregate_values_example()
+{
+  // signal which uses aggregate_values as its combiner
+  boost::signals2::signal<float (float, float),
+    aggregate_values<std::vector<float> > > sig;
+
+  sig.connect("ient);
+  sig.connect(&product);
+  sig.connect(&sum);
+  sig.connect(&difference);
+
+  std::vector<float> results = sig(5, 3);
+  std::cout << "aggregate values: ";
+  std::copy(results.begin(), results.end(),
+    std::ostream_iterator<float>(std::cout, " "));
+  std::cout << "\n";
+}
+
+int main()
+{
+  maximum_combiner_example();
+  aggregate_values_example();
+};
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/disconnect_and_block.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,105 @@
+// Various simple examples involving disconnecting and blocking slots.
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+struct HelloWorld
+{
+  void operator()() const
+  {
+    std::cout << "Hello, World!" << std::endl;
+  }
+};
+
+void disconnect_example()
+{
+  boost::signals2::signal<void ()> sig;
+
+  boost::signals2::connection c = sig.connect(HelloWorld());
+  // c is connected
+  std::cout << "c.connected() is " << c.connected() << ".\n";
+  sig(); // Prints "Hello, World!"
+
+  c.disconnect(); // Disconnect the HelloWorld object
+  std::cout << "c.connected() is " << c.connected() << ".\n";
+  sig(); // Does nothing: there are no connected slots
+}
+
+void block_example()
+{
+  boost::signals2::signal<void ()> sig;
+
+  boost::signals2::connection c = sig.connect(HelloWorld());
+  // connection is not blocked
+  std::cout << "c.blocked() is " << c.blocked() << ".\n";
+  sig(); // Prints "Hello, World!"
+
+  {
+    boost::signals2::shared_connection_block block(c); // block the slot
+    std::cout << "c.blocked() is " << c.blocked() << ".\n";
+    sig(); // No output: the slot is blocked
+  } // shared_connection_block going out of scope unblocks the slot
+  std::cout << "c.blocked() is " << c.blocked() << ".\n";
+  sig(); // Prints "Hello, World!"}
+}
+
+struct ShortLived
+{
+  void operator()() const
+  {
+    std::cout << "Life is short!" << std::endl;
+  }
+};
+
+void scoped_connection_example()
+{
+  boost::signals2::signal<void ()> sig;
+
+  {
+    boost::signals2::scoped_connection c(sig.connect(ShortLived()));
+    sig(); // will call ShortLived function object
+  } // scoped_connection goes out of scope and disconnects
+
+  sig(); // ShortLived function object no longer connected to sig
+}
+
+void foo() { std::cout << "foo"; }
+void bar() { std::cout << "bar\n"; }
+
+void disconnect_by_slot_example()
+{
+  boost::signals2::signal<void()> sig;
+
+  sig.connect(&foo);
+  sig.connect(&bar);
+  sig();
+
+  // disconnects foo, but not bar
+  sig.disconnect(&foo);
+  sig();
+}
+
+int main()
+{
+  std::cout << "Disconnect example:\n";
+  disconnect_example();
+
+  std::cout << "\nBlock example:\n";
+  block_example();
+
+  std::cout << "\nScoped connection example:\n";
+  scoped_connection_example();
+
+  std::cout << "\nDisconnect by slot example:\n";
+  disconnect_by_slot_example();
+
+  return 0;
+};
Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm.cpp	(original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -1,4 +1,4 @@
-// Document/View sample for Boost.Signals.
+// Document/View sample for Boost.Signals2.
 // Expands on doc_view.cpp example by using automatic
 // connection management.
 //
Modified: sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm_deconstruct.cpp
==============================================================================
--- sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm_deconstruct.cpp	(original)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/doc_view_acm_deconstruct.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -1,4 +1,4 @@
-// Document/View sample for Boost.Signals.
+// Document/View sample for Boost.Signals2.
 // Expands on doc_view_acm.cpp example by using boost::signals2::deconstruct
 // as a post-constructing factory function.
 //
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_multi_slot.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_multi_slot.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,40 @@
+// Multiple slot hello world example for Boost.Signals2
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+struct Hello
+{
+  void operator()() const
+  {
+    std::cout << "Hello";
+  }
+};
+
+struct World
+{
+  void operator()() const
+  {
+    std::cout << ", World!" << std::endl;
+  }
+};
+
+int main()
+{
+  boost::signals2::signal<void ()> sig;
+
+  sig.connect(Hello());
+  sig.connect(World());
+
+  sig();
+
+  return 0;
+};
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_slot.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/hello_world_slot.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,35 @@
+// Beginner hello world example for Boost.Signals2
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+struct HelloWorld
+{
+  void operator()() const
+  {
+    std::cout << "Hello, World!" << std::endl;
+  }
+};
+
+int main()
+{
+  // Signal with no arguments and a void return value
+  boost::signals2::signal<void ()> sig;
+
+  // Connect a HelloWorld slot
+  HelloWorld hello;
+  sig.connect(hello);
+
+  // Call all of the slots
+  sig();
+
+  return 0;
+};
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/ordering_slots.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/ordering_slots.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,54 @@
+// Ordered slots hello world example for Boost.Signals2
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+struct Hello
+{
+  void operator()() const
+  {
+    std::cout << "Hello";
+  }
+};
+
+struct World
+{
+  void operator()() const
+  {
+    std::cout << ", World!" << std::endl;
+  }
+};
+
+struct GoodMorning
+{
+  void operator()() const
+  {
+    std::cout << "... and good morning!" << std::endl;
+  }
+};
+
+int main()
+{
+  boost::signals2::signal<void ()> sig;
+
+  sig.connect(1, World());  // connect with group 1
+  sig.connect(0, Hello());  // connect with group 0
+  // by default slots are connected at the end of the slot list
+  sig.connect(GoodMorning());
+
+  // slots are invoked this order:
+  // 1) ungrouped slots connected with boost::signals2::at_front
+  // 2) grouped slots according to ordering of their groups
+  // 3) ungrouped slots connected with boost::signals2::at_back
+  sig();
+
+  return 0;
+};
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/passing_slots.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,47 @@
+// Example program showing passing of slots through an interface.
+//
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+// a pretend GUI button
+class Button
+{
+  typedef boost::signals2::signal<void (int x, int y)> OnClick;
+public:
+  typedef OnClick::slot_type OnClickSlotType;
+  // forward slots through Button interface to its private signal
+  boost::signals2::connection doOnClick(const OnClickSlotType & slot)
+  {
+    return onClick.connect(slot);
+  }
+
+  // simulate user clicking on GUI button at coordinates 52, 38
+  void simulateClick()
+  {
+    onClick(52, 38);
+  }
+private:
+  OnClick onClick;
+};
+
+void printCoordinates(long x, long y)
+{
+  std::cout << "(" << x << ", " << y << ")\n";
+}
+
+int main()
+{
+  Button button;
+  button.doOnClick(&printCoordinates);
+  button.simulateClick();
+  return 0;
+}
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/signal_return_value.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,33 @@
+// Example program for returning a value from slots to signal invocation.
+//
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+float product(float x, float y) { return x * y; }
+float quotient(float x, float y) { return x / y; }
+float sum(float x, float y) { return x + y; }
+float difference(float x, float y) { return x - y; }
+
+int main()
+{
+  boost::signals2::signal<float (float x, float y)> sig;
+
+  sig.connect(&product);
+  sig.connect("ient);
+  sig.connect(&sum);
+  sig.connect(&difference);
+
+  // The default combiner returns a boost::optional containing the return
+  // value of the last slot in the slot list, in this case the
+  // difference function.
+  std::cout << *sig(5, 3) << std::endl;
+};
Added: sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp
==============================================================================
--- (empty file)
+++ sandbox/thread_safe_signals/trunk/libs/signals2/example/slot_arguments.cpp	2009-02-05 17:10:13 EST (Thu, 05 Feb 2009)
@@ -0,0 +1,52 @@
+// Example program for passing arguments from signal invocations to slots.
+//
+// Copyright Douglas Gregor 2001-2004.
+// Copyright Frank Mori Hess 2009.
+//
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+
+#include <iostream>
+#include <boost/signals2/signal.hpp>
+
+void print_args(float x, float y)
+{
+  std::cout << "The arguments are " << x << " and " << y << std::endl;
+}
+
+void print_sum(float x, float y)
+{
+  std::cout << "The sum is " << x + y << std::endl;
+}
+
+void print_product(float x, float y)
+{
+  std::cout << "The product is " << x * y << std::endl;
+}
+
+void print_difference(float x, float y)
+{
+  std::cout << "The difference is " << x - y << std::endl;
+}
+
+void print_quotient(float x, float y)
+{
+  std::cout << "The quotient is " << x / y << std::endl;
+}
+
+int main()
+{
+  boost::signals2::signal<void (float, float)> sig;
+
+  sig.connect(&print_args);
+  sig.connect(&print_sum);
+  sig.connect(&print_product);
+  sig.connect(&print_difference);
+  sig.connect(&print_quotient);
+
+  sig(5., 3.);
+  return 0;
+};