2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-19 04:02:17 +00:00

pass ecv2 a universal reference to context-fn

This commit is contained in:
Oliver Kowalke
2016-10-07 19:20:30 +02:00
parent 9e0698cae7
commit d7e39b4c18
17 changed files with 175 additions and 139 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<library id="context" name="Context" dirname="context" last-revision="$Date: 2016/03/04 17:27:33 $"
<library id="context" name="Context" dirname="context" last-revision="$Date: 2016/10/07 16:36:33 $"
xmlns:xi="http://www.w3.org/2001/XInclude">
<libraryinfo>
<authorgroup>
@@ -64,11 +64,11 @@
<para>
All functions and classes are contained in the namespace <emphasis>boost::context</emphasis>.
</para>
<important>
<note>
<para>
<emphasis>execution_context</emphasis> requires C++11!
This library requires C++11!
</para>
</important>
</note>
</section>
<section id="context.requirements">
<title><link linkend="context.requirements">Requirements</link></title>
@@ -195,7 +195,7 @@
</bridgehead>
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">=</phrase><phrase role="number">35</phrase><phrase role="special">;</phrase>
<phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
<phrase role="special">[</phrase><phrase role="identifier">n</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase><phrase role="special">)</phrase> <phrase role="keyword">mutable</phrase> <phrase role="special">{</phrase>
<phrase role="special">[</phrase><phrase role="identifier">n</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase><phrase role="special">)</phrase> <phrase role="keyword">mutable</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">int</phrase> <phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase>
<phrase role="keyword">int</phrase> <phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
<phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--&gt;</phrase><phrase role="number">0</phrase><phrase role="special">){</phrase>
@@ -205,7 +205,7 @@
<phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="identifier">b</phrase><phrase role="special">;</phrase>
<phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="identifier">next</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">sink</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">sink</phrase><phrase role="special">);</phrase>
<phrase role="special">});</phrase>
<phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase><phrase role="identifier">i</phrase><phrase role="special">&lt;</phrase><phrase role="number">10</phrase><phrase role="special">;++</phrase><phrase role="identifier">i</phrase><phrase role="special">){</phrase>
<phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">source</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
@@ -253,7 +253,7 @@
role="keyword">void</phrase><phrase role="special">&gt;</phrase></code> no
data will be transferred, only the context switch is executed.
</para>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">){</phrase>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">){</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1\n&quot;</phrase><phrase role="special">);</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">();</phrase>
<phrase role="special">});</phrase>
@@ -282,9 +282,10 @@
to <emphasis>execution_context::operator()</emphasis>, in one context, is returned
by <emphasis>execution_context::operator()</emphasis> in the other context.
</para>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1, j == %d\n&quot;</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase><phrase role="special">);</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">j</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">j</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">);</phrase>
<phrase role="special">});</phrase>
<phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase> <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
@@ -314,9 +315,10 @@
If more than one argument has to be transferred, the signature of the context-function
is simply extended.
</para>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1, i == %d j == %d\n&quot;</phrase><phrase role="special">,</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase><phrase role="special">);</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">+</phrase><phrase role="identifier">j</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">-</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">+</phrase><phrase role="identifier">j</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">-</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">);</phrase>
<phrase role="special">});</phrase>
<phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">2</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase> <phrase role="special">=</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
@@ -339,7 +341,7 @@
<phrase role="identifier">X</phrase><phrase role="special">():</phrase>
<phrase role="identifier">excptr_</phrase><phrase role="special">(),</phrase>
<phrase role="identifier">ctx_</phrase><phrase role="special">(</phrase>
<phrase role="special">[=](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">data</phrase><phrase role="special">){</phrase>
<phrase role="special">[=](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">data</phrase><phrase role="special">){</phrase>
<phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">for</phrase> <phrase role="special">(;;)</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">data</phrase><phrase role="special">);</phrase>
@@ -350,7 +352,7 @@
<phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_cast</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">excptr_</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">current_exception</phrase><phrase role="special">();</phrase>
<phrase role="special">}</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
<phrase role="special">})</phrase>
<phrase role="special">{}</phrase>
@@ -404,16 +406,16 @@
to be used. The function passed as argument must return a tuple of execution_context
and arguments.
</para>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered first time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered second time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered third time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f2</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f2</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f2: entered: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">make_tuple</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">),-</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
@@ -462,7 +464,7 @@
<phrase role="special">}</phrase>
<phrase role="special">};</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">for</phrase> <phrase role="special">(;;)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1()&quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
@@ -472,12 +474,12 @@
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1(): interrupted&quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="identifier">ctx</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f2</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f2</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
<phrase role="keyword">throw</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">));</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">f1</phrase><phrase role="special">);</phrase>
@@ -496,8 +498,8 @@
in <code><phrase role="identifier">f1</phrase><phrase role="special">()</phrase></code>.
</para>
<bridgehead renderas="sect3" id="context.ecv2.h4">
<phrase id="context.ecv2.stack_destruction"/><link linkend="context.ecv2.stack_destruction">Stack
destruction</link>
<phrase id="context.ecv2.stack_unwinding"/><link linkend="context.ecv2.stack_unwinding">stack
unwinding</link>
</bridgehead>
<para>
On construction of <emphasis>execution_context</emphasis> a stack is allocated.
@@ -507,6 +509,15 @@
bool()</emphasis> returns <code><phrase role="keyword">true</phrase></code>)
is called, the stack will be destructed too.
</para>
<important>
<para>
Code executed by <emphasis>context-function</emphasis> must not prevent the
propagation of the <emphasis>detail::forced_unwind</emphasis> exception.
Absorbing that exception will cause stack unwinding to fail. Thus, any code
that catches all exceptions must re-throw any pending <emphasis>detail::forced_unwind</emphasis>
exception.
</para>
</important>
<anchor id="ecv2_prealloc"/>
<bridgehead renderas="sect3" id="context.ecv2.h5">
<phrase id="context.ecv2.allocating_control_structures_on_top_of_stack"/><link
@@ -570,7 +581,7 @@
<phrase role="comment">// execute parser in new execution context</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
<phrase role="special">[&amp;</phrase><phrase role="identifier">is</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">done</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">except</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase><phrase role="keyword">char</phrase><phrase role="special">){</phrase>
<phrase role="special">[&amp;</phrase><phrase role="identifier">is</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">done</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">except</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase><phrase role="keyword">char</phrase><phrase role="special">){</phrase>
<phrase role="comment">// create parser with callback function</phrase>
<phrase role="identifier">Parser</phrase> <phrase role="identifier">p</phrase><phrase role="special">(</phrase> <phrase role="identifier">is</phrase><phrase role="special">,</phrase>
<phrase role="special">[&amp;</phrase><phrase role="identifier">sink</phrase><phrase role="special">](</phrase><phrase role="keyword">char</phrase> <phrase role="identifier">ch</phrase><phrase role="special">){</phrase>
@@ -588,7 +599,7 @@
<phrase role="comment">// set termination flag</phrase>
<phrase role="identifier">done</phrase><phrase role="special">=</phrase><phrase role="keyword">true</phrase><phrase role="special">;</phrase>
<phrase role="comment">// resume main execution context</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">sink</phrase><phrase role="special">;</phrase>
<phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">sink</phrase><phrase role="special">);</phrase>
<phrase role="special">});</phrase>
<phrase role="comment">// user-code pulls parsed data from parser</phrase>
@@ -1385,13 +1396,17 @@
the application is terminated. <emphasis>std::exception_ptr</emphasis> can
be used to transfer exceptions between different execution contexts.
</para>
<bridgehead renderas="sect3" id="context.ecv1.h2">
<phrase id="context.ecv1.stack_unwinding"/><link linkend="context.ecv1.stack_unwinding">stack
unwinding</link>
</bridgehead>
<para>
Sometimes it is necessary to unwind the stack of an unfinished context to destroy
local stack variables so they can release allocated resources (RAII pattern).
The user is responsible for this task.
</para>
<anchor id="ecv1_prealloc"/>
<bridgehead renderas="sect3" id="context.ecv1.h2">
<bridgehead renderas="sect3" id="context.ecv1.h3">
<phrase id="context.ecv1.allocating_control_structures_on_top_of_stack"/><link
linkend="context.ecv1.allocating_control_structures_on_top_of_stack">allocating
control structures on top of stack</link>
@@ -1432,7 +1447,7 @@
<phrase role="special">...</phrase>
<phrase role="special">};</phrase>
</programlisting>
<bridgehead renderas="sect3" id="context.ecv1.h3">
<bridgehead renderas="sect3" id="context.ecv1.h4">
<phrase id="context.ecv1.exception_handling"/><link linkend="context.ecv1.exception_handling">exception
handling</link>
</bridgehead>
@@ -1448,7 +1463,7 @@
another execution context.
</para>
</important>
<bridgehead renderas="sect3" id="context.ecv1.h4">
<bridgehead renderas="sect3" id="context.ecv1.h5">
<phrase id="context.ecv1.parameter_passing"/><link linkend="context.ecv1.parameter_passing">parameter
passing</link>
</bridgehead>
@@ -1496,7 +1511,7 @@
<phrase role="identifier">output</phrase><phrase role="special">:</phrase>
<phrase role="number">7</phrase>
</programlisting>
<bridgehead renderas="sect3" id="context.ecv1.h5">
<bridgehead renderas="sect3" id="context.ecv1.h6">
<phrase id="context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_"/><link
linkend="context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_">Class
<code><phrase role="identifier">execution_context</phrase></code></link>

View File

@@ -59,7 +59,7 @@ passed/returned arguments.
int n=35;
ctx::execution_context<int> source(
[n](ctx::execution_context<int> sink, int) mutable {
[n](ctx::execution_context<int> && sink, int) mutable {
int a=0;
int b=1;
while(n-->0){
@@ -69,7 +69,7 @@ passed/returned arguments.
a=b;
b=next;
}
return sink;
return std::move(sink);
});
for(int i=0;i<10;++i){
auto result=source(i);
@@ -104,7 +104,7 @@ and the stack is exchanged by each context switch.
With `execution_context<void>` no data will be transferred, only the context
switch is executed.
boost::context::execution_context<void> ctx1([](boost::context::execution_context<void> ctx2){
boost::context::execution_context<void> ctx1([](boost::context::execution_context<void> && ctx2){
std::printf("inside ctx1\n");
return ctx2();
});
@@ -124,10 +124,10 @@ arguments of the __context_fn__ if the context is started for the first time.
In all following invocations of __ec_op__ the arguments passed to __ec_op__, in
one context, is returned by __ec_op__ in the other context.
boost::context::execution_context<int> ctx1([](boost::context::execution_context<int> ctx2, int j){
boost::context::execution_context<int> ctx1([](boost::context::execution_context<int> && ctx2, int j){
std::printf("inside ctx1, j == %d\n", j);
std::tie(ctx2, j) = ctx2(j+1);
return ctx2;
return std::move(ctx2);
});
int i = 1;
std::tie(ctx1, i) = ctx1(i);
@@ -145,10 +145,10 @@ value of `j+1`.
If more than one argument has to be transferred, the signature of the
context-function is simply extended.
boost::context::execution_context<int,int> ctx1([](boost::context::execution_context<int,int> ctx2, int i, int j){
boost::context::execution_context<int,int> ctx1([](boost::context::execution_context<int,int> && ctx2, int i, int j){
std::printf("inside ctx1, i == %d j == %d\n", i, j);
std::tie(ctx2, i, j) = ctx2(i+j,i-j);
return ctx2;
return std::move(ctx2);
});
int i = 2, j = 1;
std::tie(ctx1, i, j) = ctx1(i,j);
@@ -170,7 +170,7 @@ direction, ['boost::variant<>] could be used.
X():
excptr_(),
ctx_(
[=](boost::context::execution_context<boost::variant<int,std::string>> ctx, boost::variant<int,std::string> data){
[=](boost::context::execution_context<boost::variant<int,std::string>> && ctx, boost::variant<int,std::string> data){
try {
for (;;) {
int i = boost::get<int>(data);
@@ -181,7 +181,7 @@ direction, ['boost::variant<>] could be used.
} catch (std::bad_cast const&) {
excptr_=std::current_exception();
}
return ctx;
return std::move( ctx);
})
{}
@@ -222,16 +222,16 @@ For this purpose __ec_op__ with first argument `exec_ontop_arg` has to be used.
The function passed as argument must return a tuple of execution_context and
arguments.
boost::context::execution_context<int> f1(boost::context::execution_context<int> ctx,int data) {
boost::context::execution_context<int> f1(boost::context::execution_context<int> && ctx,int data) {
std::cout << "f1: entered first time: " << data << std::endl;
std::tie(ctx,data) = ctx(data+1);
std::cout << "f1: entered second time: " << data << std::endl;
std::tie(ctx,data) = ctx(data+1);
std::cout << "f1: entered third time: " << data << std::endl;
return ctx;
return std::move(ctx);
}
std::tuple<boost::context::execution_context<int>,int> f2(boost::context::execution_context<int> ctx,int data) {
std::tuple<boost::context::execution_context<int>,int> f2(boost::context::execution_context<int> && ctx,int data) {
std::cout << "f2: entered: " << data << std::endl;
return std::make_tuple(std::move(ctx),-1);
}
@@ -268,7 +268,7 @@ exception.
}
};
boost::context::execution_context<void> f1(boost::context::execution_context<void> ctx) {
boost::context::execution_context<void> f1(boost::context::execution_context<void> && ctx) {
try {
for (;;) {
std::cout << "f1()" << std::endl;
@@ -278,12 +278,12 @@ exception.
std::cout << "f1(): interrupted" << std::endl;
ctx = std::move( e.ctx);
}
return ctx;
return std::move(ctx);
}
boost::context::execution_context<void> f2(boost::context::execution_context<void> ctx) {
boost::context::execution_context<void> f2(boost::context::execution_context<void> && ctx) {
throw interrupt(std::move(ctx));
return ctx;
return std::move(ctx);
}
boost::context::execution_context< void > ctx(f1);
@@ -365,7 +365,7 @@ of the stack.]
// execute parser in new execution context
boost::context::execution_context<char> source(
[&is,&done,&except](ctx::execution_context<char> sink,char){
[&is,&done,&except](ctx::execution_context<char> && sink,char){
// create parser with callback function
Parser p( is,
[&sink](char ch){
@@ -383,7 +383,7 @@ of the stack.]
// set termination flag
done=true;
// resume main execution context
return sink;
return std::move(sink);
});
// user-code pulls parsed data from parser

View File

@@ -189,13 +189,18 @@
the application is terminated. <span class="emphasis"><em>std::exception_ptr</em></span> can
be used to transfer exceptions between different execution contexts.
</p>
<h4>
<a name="context.ecv1.h2"></a>
<span><a name="context.ecv1.stack_unwinding"></a></span><a class="link" href="ecv1.html#context.ecv1.stack_unwinding">stack
unwinding</a>
</h4>
<p>
Sometimes it is necessary to unwind the stack of an unfinished context to destroy
local stack variables so they can release allocated resources (RAII pattern).
The user is responsible for this task.
</p>
<a name="ecv1_prealloc"></a><h4>
<a name="context.ecv1.h2"></a>
<a name="context.ecv1.h3"></a>
<span><a name="context.ecv1.allocating_control_structures_on_top_of_stack"></a></span><a class="link" href="ecv1.html#context.ecv1.allocating_control_structures_on_top_of_stack">allocating
control structures on top of stack</a>
</h4>
@@ -240,7 +245,7 @@
<span class="special">};</span>
</pre>
<h4>
<a name="context.ecv1.h3"></a>
<a name="context.ecv1.h4"></a>
<span><a name="context.ecv1.exception_handling"></a></span><a class="link" href="ecv1.html#context.ecv1.exception_handling">exception
handling</a>
</h4>
@@ -261,7 +266,7 @@
</p></td></tr>
</table></div>
<h4>
<a name="context.ecv1.h4"></a>
<a name="context.ecv1.h5"></a>
<span><a name="context.ecv1.parameter_passing"></a></span><a class="link" href="ecv1.html#context.ecv1.parameter_passing">parameter
passing</a>
</h4>
@@ -310,7 +315,7 @@
<span class="number">7</span>
</pre>
<h4>
<a name="context.ecv1.h5"></a>
<a name="context.ecv1.h6"></a>
<span><a name="context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_"></a></span><a class="link" href="ecv1.html#context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_">Class
<code class="computeroutput"><span class="identifier">execution_context</span></code></a>
</h4>

View File

@@ -111,7 +111,7 @@
</h4>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">n</span><span class="special">=</span><span class="number">35</span><span class="special">;</span>
<span class="identifier">ctx</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">source</span><span class="special">(</span>
<span class="special">[</span><span class="identifier">n</span><span class="special">](</span><span class="identifier">ctx</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span> <span class="keyword">mutable</span> <span class="special">{</span>
<span class="special">[</span><span class="identifier">n</span><span class="special">](</span><span class="identifier">ctx</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">sink</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span> <span class="keyword">mutable</span> <span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">a</span><span class="special">=</span><span class="number">0</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">b</span><span class="special">=</span><span class="number">1</span><span class="special">;</span>
<span class="keyword">while</span><span class="special">(</span><span class="identifier">n</span><span class="special">--&gt;</span><span class="number">0</span><span class="special">){</span>
@@ -121,7 +121,7 @@
<span class="identifier">a</span><span class="special">=</span><span class="identifier">b</span><span class="special">;</span>
<span class="identifier">b</span><span class="special">=</span><span class="identifier">next</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">return</span> <span class="identifier">sink</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">sink</span><span class="special">);</span>
<span class="special">});</span>
<span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="number">0</span><span class="special">;</span><span class="identifier">i</span><span class="special">&lt;</span><span class="number">10</span><span class="special">;++</span><span class="identifier">i</span><span class="special">){</span>
<span class="keyword">auto</span> <span class="identifier">result</span><span class="special">=</span><span class="identifier">source</span><span class="special">(</span><span class="identifier">i</span><span class="special">);</span>
@@ -168,7 +168,7 @@
With <code class="computeroutput"><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span></code> no
data will be transferred, only the context switch is executed.
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">ctx2</span><span class="special">){</span>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx2</span><span class="special">){</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span><span class="special">(</span><span class="string">"inside ctx1\n"</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">ctx2</span><span class="special">();</span>
<span class="special">});</span>
@@ -195,9 +195,10 @@
to <span class="emphasis"><em>execution_context::operator()</em></span>, in one context, is returned
by <span class="emphasis"><em>execution_context::operator()</em></span> in the other context.
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx2</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">j</span><span class="special">){</span>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx2</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">j</span><span class="special">){</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span><span class="special">(</span><span class="string">"inside ctx1, j == %d\n"</span><span class="special">,</span> <span class="identifier">j</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">ctx2</span><span class="special">(</span><span class="identifier">j</span><span class="special">+</span><span class="number">1</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx2</span><span class="special">,</span> <span class="identifier">j</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx2</span><span class="special">(</span><span class="identifier">j</span><span class="special">+</span><span class="number">1</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx2</span><span class="special">);</span>
<span class="special">});</span>
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx1</span><span class="special">,</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx1</span><span class="special">(</span><span class="identifier">i</span><span class="special">);</span>
@@ -220,9 +221,10 @@
If more than one argument has to be transferred, the signature of the context-function
is simply extended.
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx2</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">j</span><span class="special">){</span>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx1</span><span class="special">([](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx2</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">j</span><span class="special">){</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">printf</span><span class="special">(</span><span class="string">"inside ctx1, i == %d j == %d\n"</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">ctx2</span><span class="special">(</span><span class="identifier">i</span><span class="special">+</span><span class="identifier">j</span><span class="special">,</span><span class="identifier">i</span><span class="special">-</span><span class="identifier">j</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx2</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx2</span><span class="special">(</span><span class="identifier">i</span><span class="special">+</span><span class="identifier">j</span><span class="special">,</span><span class="identifier">i</span><span class="special">-</span><span class="identifier">j</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx2</span><span class="special">);</span>
<span class="special">});</span>
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx1</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx1</span><span class="special">(</span><span class="identifier">i</span><span class="special">,</span><span class="identifier">j</span><span class="special">);</span>
@@ -245,7 +247,7 @@
<span class="identifier">X</span><span class="special">():</span>
<span class="identifier">excptr_</span><span class="special">(),</span>
<span class="identifier">ctx_</span><span class="special">(</span>
<span class="special">[=](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;&gt;</span> <span class="identifier">ctx</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">data</span><span class="special">){</span>
<span class="special">[=](</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">variant</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">data</span><span class="special">){</span>
<span class="keyword">try</span> <span class="special">{</span>
<span class="keyword">for</span> <span class="special">(;;)</span> <span class="special">{</span>
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(</span><span class="identifier">data</span><span class="special">);</span>
@@ -256,7 +258,7 @@
<span class="special">}</span> <span class="keyword">catch</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span> <span class="keyword">const</span><span class="special">&amp;)</span> <span class="special">{</span>
<span class="identifier">excptr_</span><span class="special">=</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">current_exception</span><span class="special">();</span>
<span class="special">}</span>
<span class="keyword">return</span> <span class="identifier">ctx</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span> <span class="identifier">ctx</span><span class="special">);</span>
<span class="special">})</span>
<span class="special">{}</span>
@@ -315,16 +317,16 @@
to be used. The function passed as argument must return a tuple of execution_context
and arguments.
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">f1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">data</span><span class="special">)</span> <span class="special">{</span>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">f1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">data</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f1: entered first time: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">data</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">,</span><span class="identifier">data</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx</span><span class="special">(</span><span class="identifier">data</span><span class="special">+</span><span class="number">1</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f1: entered second time: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">data</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">,</span><span class="identifier">data</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">ctx</span><span class="special">(</span><span class="identifier">data</span><span class="special">+</span><span class="number">1</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f1: entered third time: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">data</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">ctx</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">f2</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">ctx</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">data</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;,</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">f2</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">data</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f2: entered: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">data</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">),-</span><span class="number">1</span><span class="special">);</span>
<span class="special">}</span>
@@ -365,7 +367,7 @@
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">f1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">ctx</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">f1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">try</span> <span class="special">{</span>
<span class="keyword">for</span> <span class="special">(;;)</span> <span class="special">{</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f1()"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
@@ -375,12 +377,12 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"f1(): interrupted"</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="identifier">ctx</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">ctx</span><span class="special">);</span>
<span class="special">}</span>
<span class="keyword">return</span> <span class="identifier">ctx</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">f2</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">ctx</span><span class="special">)</span> <span class="special">{</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="identifier">f2</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">void</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">ctx</span><span class="special">)</span> <span class="special">{</span>
<span class="keyword">throw</span> <span class="identifier">interrupt</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">));</span>
<span class="keyword">return</span> <span class="identifier">ctx</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">ctx</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="identifier">ctx</span><span class="special">(</span><span class="identifier">f1</span><span class="special">);</span>
@@ -400,8 +402,8 @@
</p>
<h4>
<a name="context.ecv2.h4"></a>
<span><a name="context.ecv2.stack_destruction"></a></span><a class="link" href="ecv2.html#context.ecv2.stack_destruction">Stack
destruction</a>
<span><a name="context.ecv2.stack_unwinding"></a></span><a class="link" href="ecv2.html#context.ecv2.stack_unwinding">stack
unwinding</a>
</h4>
<p>
On construction of <span class="emphasis"><em>execution_context</em></span> a stack is allocated.
@@ -411,6 +413,19 @@
bool()</em></span> returns <code class="computeroutput"><span class="keyword">true</span></code>)
is called, the stack will be destructed too.
</p>
<div class="important"><table border="0" summary="Important">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
<th align="left">Important</th>
</tr>
<tr><td align="left" valign="top"><p>
Code executed by <span class="emphasis"><em>context-function</em></span> must not prevent the
propagation of the <span class="emphasis"><em>detail::forced_unwind</em></span> exception.
Absorbing that exception will cause stack unwinding to fail. Thus, any code
that catches all exceptions must re-throw any pending <span class="emphasis"><em>detail::forced_unwind</em></span>
exception.
</p></td></tr>
</table></div>
<a name="ecv2_prealloc"></a><h4>
<a name="context.ecv2.h5"></a>
<span><a name="context.ecv2.allocating_control_structures_on_top_of_stack"></a></span><a class="link" href="ecv2.html#context.ecv2.allocating_control_structures_on_top_of_stack">allocating
@@ -478,7 +493,7 @@
<span class="comment">// execute parser in new execution context</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">source</span><span class="special">(</span>
<span class="special">[&amp;</span><span class="identifier">is</span><span class="special">,&amp;</span><span class="identifier">done</span><span class="special">,&amp;</span><span class="identifier">except</span><span class="special">](</span><span class="identifier">ctx</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">sink</span><span class="special">,</span><span class="keyword">char</span><span class="special">){</span>
<span class="special">[&amp;</span><span class="identifier">is</span><span class="special">,&amp;</span><span class="identifier">done</span><span class="special">,&amp;</span><span class="identifier">except</span><span class="special">](</span><span class="identifier">ctx</span><span class="special">::</span><span class="identifier">execution_context</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span> <span class="identifier">sink</span><span class="special">,</span><span class="keyword">char</span><span class="special">){</span>
<span class="comment">// create parser with callback function</span>
<span class="identifier">Parser</span> <span class="identifier">p</span><span class="special">(</span> <span class="identifier">is</span><span class="special">,</span>
<span class="special">[&amp;</span><span class="identifier">sink</span><span class="special">](</span><span class="keyword">char</span> <span class="identifier">ch</span><span class="special">){</span>
@@ -496,7 +511,7 @@
<span class="comment">// set termination flag</span>
<span class="identifier">done</span><span class="special">=</span><span class="keyword">true</span><span class="special">;</span>
<span class="comment">// resume main execution context</span>
<span class="keyword">return</span> <span class="identifier">sink</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">sink</span><span class="special">);</span>
<span class="special">});</span>
<span class="comment">// user-code pulls parsed data from parser</span>

View File

@@ -65,13 +65,13 @@
<p>
All functions and classes are contained in the namespace <span class="emphasis"><em>boost::context</em></span>.
</p>
<div class="important"><table border="0" summary="Important">
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
<th align="left">Important</th>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
<span class="emphasis"><em>execution_context</em></span> requires C++11!
This library requires C++11!
</p></td></tr>
</table></div>
</div>

View File

@@ -68,7 +68,7 @@
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: March 04, 2016 at 17:27:37 GMT</small></p></td>
<td align="left"><p><small>Last revised: October 07, 2016 at 16:36:39 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>

View File

@@ -23,14 +23,14 @@ void echoSSE( int i) {
std::cout << v32[3];
}
boost::context::execution_context< int > echo( boost::context::execution_context< int > ctx, int i) {
boost::context::execution_context< int > echo( boost::context::execution_context< int > && ctx, int i) {
for (;;) {
std::cout << i;
echoSSE( i);
std::cout << " ";
std::tie( ctx, i) = ctx( 0);
}
return ctx;
return std::move( ctx);
}
int main( int argc, char * argv[]) {

View File

@@ -15,7 +15,7 @@ namespace ctx = boost::context;
int main() {
int n=35;
ctx::execution_context< int > source(
[n](ctx::execution_context< int > sink, int) mutable {
[n](ctx::execution_context< int > && sink, int) mutable {
int a=0;
int b=1;
while(n-->0){
@@ -25,7 +25,7 @@ int main() {
a=b;
b=next;
}
return sink;
return std::move( sink);
});
for(int i=0;i<10;++i){
auto result=source(i);

View File

@@ -11,11 +11,11 @@
namespace ctx = boost::context;
ctx::execution_context< int > f1( ctx::execution_context< int > ctxm, int data) {
ctx::execution_context< int > f1( ctx::execution_context< int > && ctxm, int data) {
std::cout << "f1: entered first time: " << data << std::endl;
std::tie( ctxm, data) = ctxm( data + 2);
std::cout << "f1: entered second time: " << data << std::endl;
return ctxm;
return std::move( ctxm);
}
int main() {

View File

@@ -11,11 +11,11 @@
namespace ctx = boost::context;
ctx::execution_context< void > f1( ctx::execution_context< void > ctxm) {
ctx::execution_context< void > f1( ctx::execution_context< void > && ctxm) {
std::cout << "f1: entered first time" << std::endl;
ctxm = ctxm();
std::cout << "f1: entered second time" << std::endl;
return ctxm;
return std::move( ctxm);
}
int main() {

View File

@@ -12,16 +12,16 @@
namespace ctx = boost::context;
ctx::execution_context< int > f1( ctx::execution_context< int > ctx, int data) {
ctx::execution_context< int > f1( ctx::execution_context< int > && ctx, int data) {
std::cout << "f1: entered first time: " << data << std::endl;
std::tie( ctx, data) = ctx( data + 1);
std::cout << "f1: entered second time: " << data << std::endl;
std::tie( ctx, data) = ctx( data + 1);
std::cout << "f1: entered third time: " << data << std::endl;
return ctx;
return std::move( ctx);
}
std::tuple< ctx::execution_context< int >, int > f2( ctx::execution_context< int > ctx, int data) {
std::tuple< ctx::execution_context< int >, int > f2( ctx::execution_context< int > && ctx, int data) {
std::cout << "f2: entered: " << data << std::endl;
return std::make_tuple( std::move( ctx), -1);
}

View File

@@ -12,18 +12,18 @@
namespace ctx = boost::context;
ctx::execution_context< void > f1( ctx::execution_context< void > ctx) {
ctx::execution_context< void > f1( ctx::execution_context< void > && ctx) {
std::cout << "f1: entered first time" << std::endl;
ctx = ctx();
std::cout << "f1: entered second time" << std::endl;
ctx = ctx();
std::cout << "f1: entered third time" << std::endl;
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > f2( ctx::execution_context< void > ctx) {
ctx::execution_context< void > f2( ctx::execution_context< void > && ctx) {
std::cout << "f2: entered" << std::endl;
return ctx;
return std::move( ctx);
}
int main() {

View File

@@ -27,7 +27,7 @@ public:
X():
excptr_(),
ctx_(
[this](ctx::execution_context<variant_t> ctx, variant_t data){
[this](ctx::execution_context<variant_t> && ctx, variant_t data){
try {
for (;;) {
int i = boost::get<int>(data);
@@ -39,7 +39,7 @@ public:
} catch ( std::bad_cast const&) {
excptr_=std::current_exception();
}
return ctx;
return std::move( ctx);
})
{}

View File

@@ -97,7 +97,7 @@ int main() {
// execute parser in new execution context
boost::context::execution_context<char> source(
[&is,&done,&except](ctx::execution_context<char> sink,char){
[&is,&done,&except](ctx::execution_context<char> && sink,char){
// create parser with callback function
Parser p( is,
[&sink](char ch){
@@ -115,7 +115,7 @@ int main() {
// set termination flag
done=true;
// resume main execution context
return sink;
return std::move( sink);
});
// user-code pulls parsed data from parser

View File

@@ -19,7 +19,7 @@ struct my_exception {
}
};
boost::context::execution_context<void> f1(boost::context::execution_context<void> ctx) {
boost::context::execution_context<void> f1(boost::context::execution_context<void> && ctx) {
try {
for (;;) {
std::cout << "f1()" << std::endl;
@@ -29,12 +29,12 @@ boost::context::execution_context<void> f1(boost::context::execution_context<voi
std::cout << "f1(): my_exception catched" << std::endl;
ctx = std::move( e.ctx);
}
return ctx;
return std::move( ctx);
}
boost::context::execution_context<void> f2(boost::context::execution_context<void> ctx) {
boost::context::execution_context<void> f2(boost::context::execution_context<void> && ctx) {
throw my_exception( std::move( ctx) );
return ctx;
return std::move( ctx);
}
int main() {

View File

@@ -19,10 +19,11 @@
boost::uint64_t jobs = 1000;
static boost::context::execution_context< void > foo( boost::context::execution_context< void > ctx) {
static boost::context::execution_context< void > foo( boost::context::execution_context< void > && ctx) {
while ( true) {
ctx = ctx();
}
return std::move( ctx);
}
duration_type measure_time() {

View File

@@ -31,9 +31,9 @@ std::string value2;
double value3 = 0.;
struct X {
ctx::execution_context< void > foo( int i, ctx::execution_context< void > ctx) {
ctx::execution_context< void > foo( int i, ctx::execution_context< void > && ctx) {
value1 = i;
return ctx;
return std::move( ctx);
}
};
@@ -109,39 +109,39 @@ void seh( bool & catched) {
}
#endif
ctx::execution_context< void > fn1( int i, ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn1( int i, ctx::execution_context< void > && ctx) {
value1 = i;
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn2( const char * what, ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn2( const char * what, ctx::execution_context< void > && ctx) {
try {
throw std::runtime_error( what);
} catch ( std::runtime_error const& e) {
value2 = e.what();
}
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn3( double d, ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn3( double d, ctx::execution_context< void > && ctx) {
d += 3.45;
value3 = d;
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn5( ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn5( ctx::execution_context< void > && ctx) {
value1 = 3;
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn4( ctx::execution_context< void > ctx) {
ctx::execution_context< void > ctx1( fn5);
ctx::execution_context< void > fn4( ctx::execution_context< void > && ctx) {
ctx::execution_context< void > && ctx1( fn5);
ctx1();
value3 = 3.14;
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn6( ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn6( ctx::execution_context< void > && ctx) {
try {
value1 = 3;
ctx = ctx();
@@ -151,63 +151,63 @@ ctx::execution_context< void > fn6( ctx::execution_context< void > ctx) {
value2 = e.what();
ctx = std::move( e.ctx);
}
return ctx;
return std::move( ctx);
}
ctx::execution_context< void > fn7( ctx::execution_context< void > ctx) {
ctx::execution_context< void > fn7( ctx::execution_context< void > && ctx) {
Y y;
return ctx();
}
ctx::execution_context< int > fn8( ctx::execution_context< int > ctx, int i) {
ctx::execution_context< int > fn8( ctx::execution_context< int > && ctx, int i) {
value1 = i;
return ctx;
return std::move( ctx);
}
ctx::execution_context< int > fn9( ctx::execution_context< int > ctx, int i) {
ctx::execution_context< int > fn9( ctx::execution_context< int > && ctx, int i) {
value1 = i;
std::tie( ctx, i) = ctx( i);
value1 = i;
return ctx;
return std::move( ctx);
}
ctx::execution_context< int & > fn10( ctx::execution_context< int & > ctx, int & i) {
ctx::execution_context< int & > fn10( ctx::execution_context< int & > && ctx, int & i) {
std::tie( ctx, i) = ctx( i);
return ctx;
return std::move( ctx);
}
ctx::execution_context< moveable > fn11( ctx::execution_context< moveable > ctx, moveable m) {
ctx::execution_context< moveable > fn11( ctx::execution_context< moveable > && ctx, moveable m) {
std::tie( ctx, m) = ctx( std::move( m) );
return ctx;
return std::move( ctx);
}
ctx::execution_context< int, std::string > fn12( ctx::execution_context< int, std::string > ctx, int i, std::string str) {
ctx::execution_context< int, std::string > fn12( ctx::execution_context< int, std::string > && ctx, int i, std::string str) {
std::tie( ctx, i, str) = ctx( i, str);
return ctx;
return std::move( ctx);
}
ctx::execution_context< int, moveable > fn13( ctx::execution_context< int, moveable > ctx, int i, moveable m) {
ctx::execution_context< int, moveable > fn13( ctx::execution_context< int, moveable > && ctx, int i, moveable m) {
std::tie( ctx, i, m) = ctx( i, std::move( m) );
return ctx;
return std::move( ctx);
}
ctx::execution_context< variant_t > fn14( ctx::execution_context< variant_t > ctx, variant_t data) {
ctx::execution_context< variant_t > fn14( ctx::execution_context< variant_t > && ctx, variant_t data) {
int i = boost::get< int >( data);
data = boost::lexical_cast< std::string >( i);
std::tie( ctx, data) = ctx( data);
return ctx;
return std::move( ctx);
}
ctx::execution_context< Y * > fn15( ctx::execution_context< Y * > ctx, Y * py) {
ctx::execution_context< Y * > fn15( ctx::execution_context< Y * > && ctx, Y * py) {
ctx( py);
return ctx;
return std::move( ctx);
}
ctx::execution_context< int > fn16( ctx::execution_context< int > ctx, int i) {
ctx::execution_context< int > fn16( ctx::execution_context< int > && ctx, int i) {
value1 = i;
std::tie( ctx, i) = ctx( i);
value1 = i;
return ctx;
return std::move( ctx);
}
@@ -250,9 +250,9 @@ void test_exception() {
{
bool catched = false;
std::thread([&catched](){
ctx::execution_context< void > ctx([&catched](ctx::execution_context< void > ctx){
ctx::execution_context< void > ctx([&catched](ctx::execution_context< void > && ctx){
seh( catched);
return ctx;
return std::move( ctx);
});
BOOST_CHECK( ctx);
ctx();
@@ -360,9 +360,9 @@ void test_ontop_exception() {
BOOST_CHECK_EQUAL( 3, value1);
const char * what = "hello world";
ctx( ctx::exec_ontop_arg,
[what](ctx::execution_context< void > ctx){
[what](ctx::execution_context< void > && ctx){
throw my_exception( what, std::move( ctx) );
return ctx;
return std::move( ctx);
});
BOOST_CHECK_EQUAL( 3, value1);
BOOST_CHECK_EQUAL( std::string( what), value2);
@@ -488,10 +488,10 @@ void test_variant() {
#ifdef BOOST_WINDOWS
void test_bug12215() {
ctx::execution_context< void > ctx(
[](ctx::execution_context< void > ctx) {
[](ctx::execution_context< void > && ctx) {
char buffer[MAX_PATH];
GetModuleFileName( nullptr, buffer, MAX_PATH);
return ctx;
return std::move( ctx);
});
ctx();