[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# Copyright Oliver Kowalke 2014.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
# For more information, see http://www.boost.org/
import common ;
import feature ;
import indirect ;
import modules ;
import os ;
import toolset ;
project boost/coroutine2/example
: requirements
<library>/boost/context//boost_context
<toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS
<link>static
<threading>multi
;
exe fibonacci
: fibonacci.cpp
;
exe same_fringe
: same_fringe.cpp
;
exe layout
: layout.cpp
;
exe parser
: parser.cpp
;
exe segmented
: segmented.cpp
;

View File

@@ -0,0 +1,30 @@
// Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <boost/coroutine2/all.hpp>
int main() {
boost::coroutines2::coroutine< int >::pull_type source(
[]( boost::coroutines2::coroutine< int >::push_type & sink) {
int first = 1, second = 1;
sink( first);
sink( second);
for ( int i = 0; i < 8; ++i) {
int third = first + second;
first = second;
second = third;
sink( third);
}
});
for ( auto i : source) {
std::cout << i << " ";
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,50 @@
// Copyright Nat Goodspeed 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <utility>
#include <boost/coroutine2/all.hpp>
struct FinalEOL{
~FinalEOL(){
std::cout << std::endl;
}
};
int main(int argc,char* argv[]){
using std::begin;
using std::end;
std::vector<std::string> words{
"peas", "porridge", "hot", "peas",
"porridge", "cold", "peas", "porridge",
"in", "the", "pot", "nine",
"days", "old" };
int num=5,width=15;
boost::coroutines2::coroutine<std::string>::push_type writer(
[&](boost::coroutines2::coroutine<std::string>::pull_type& in){
// finish the last line when we leave by whatever means
FinalEOL eol;
// pull values from upstream, lay them out 'num' to a line
for (;;){
for(int i=0;i<num;++i){
// when we exhaust the input, stop
if(!in) return;
std::cout << std::setw(width) << in.get();
// now that we've handled this item, advance to next
in();
}
// after 'num' items, line break
std::cout << std::endl;
}
});
std::copy(begin(words),end(words),begin(writer));
std::cout << "\nDone";
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,122 @@
// Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cctype>
#include <cstdio>
#include <exception>
#include <functional>
#include <iostream>
#include <sstream>
#include <boost/coroutine2/all.hpp>
class parser_error : public std::runtime_error {
public:
parser_error() :
std::runtime_error("parsing failed") {
}
};
/*
* grammar:
* P ---> E '\0'
* E ---> T {('+'|'-') T}
* T ---> S {('*'|'/') S}
* S ---> digit | '(' E ')'
*/
class Parser{
char next;
std::istream& is;
std::function<void(char)> cb;
char pull(){
return std::char_traits<char>::to_char_type(is.get());
}
void scan(){
do{
next=pull();
}
while(isspace(next));
}
public:
Parser(std::istream& is_,std::function<void(char)> cb_) :
next(), is(is_), cb(cb_)
{}
void run() {
scan();
E();
}
private:
void E(){
T();
while (next=='+'||next=='-'){
cb(next);
scan();
T();
}
}
void T(){
S();
while (next=='*'||next=='/'){
cb(next);
scan();
S();
}
}
void S(){
if (std::isdigit(next)){
cb(next);
scan();
}
else if(next=='('){
cb(next);
scan();
E();
if (next==')'){
cb(next);
scan();
}else{
throw parser_error();
}
}
else{
throw parser_error();
}
}
};
typedef boost::coroutines2::coroutine< char > coro_t;
int main() {
try {
std::istringstream is("1+1");
// invert control flow
coro_t::pull_type seq(
[&is]( coro_t::push_type & yield) {
Parser p( is,
[&yield](char ch){
yield(ch);
});
p.run();
});
// user-code pulls parsed data from parser
for(char c:seq){
printf("Parsed: %c\n",c);
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
} catch ( std::exception const& ex) {
std::cerr << "exception: " << ex.what() << std::endl;
}
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,172 @@
// Copyright Nat Goodspeed 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSEstd::placeholders::_1_0.txt or copy at
// http://www.boost.org/LICENSEstd::placeholders::_1_0.txt)
#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <string>
#include <utility>
#include <boost/coroutine2/all.hpp>
struct node {
typedef std::shared_ptr< node > ptr_t;
// Each tree node has an optional left subtree, an optional right subtree
// and a value of its own. The value is considered to be between the left
// subtree and the right.
ptr_t left, right;
std::string value;
// construct leaf
node(const std::string& v):
left(),right(),value(v) {
}
// construct nonleaf
node(ptr_t l, const std::string& v, ptr_t r):
left(l),right(r),value(v) {
}
static ptr_t create(const std::string& v) {
return ptr_t(new node(v));
}
static ptr_t create(ptr_t l, const std::string& v, ptr_t r) {
return ptr_t(new node(l, v, r));
}
};
node::ptr_t create_left_tree_from(const std::string& root) {
/* --------
root
/ \
b e
/ \
a c
-------- */
return node::create(
node::create(
node::create("a"),
"b",
node::create("c")),
root,
node::create("e"));
}
node::ptr_t create_right_tree_from(const std::string& root) {
/* --------
root
/ \
a d
/ \
c e
-------- */
return node::create(
node::create("a"),
root,
node::create(
node::create("c"),
"d",
node::create("e")));
}
// recursively walk the tree, delivering values in order
void traverse(node::ptr_t n, boost::coroutines2::coroutine<std::string>::push_type& out) {
if (n->left)
traverse(n->left,out);
out(n->value);
if (n->right)
traverse(n->right,out);
}
int main() {
{
node::ptr_t left_d(create_left_tree_from("d"));
node::ptr_t right_b(create_right_tree_from("b"));
node::ptr_t right_x(create_right_tree_from("x"));
{
boost::coroutines2::coroutine<std::string>::pull_type left_d_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(left_d,out);
});
std::cout << "left tree from d:\n";
std::copy(begin(left_d_reader),
end(left_d_reader),
std::ostream_iterator<std::string>(std::cout, " "));
std::cout << std::endl;
boost::coroutines2::coroutine<std::string>::pull_type right_b_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(right_b,out);
});
std::cout << "right tree from b:\n";
std::copy(begin(right_b_reader),
end(right_b_reader),
std::ostream_iterator<std::string>(std::cout, " "));
std::cout << std::endl;
boost::coroutines2::coroutine<std::string>::pull_type right_x_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(right_x,out);
});
std::cout << "right tree from x:\n";
std::copy(begin(right_x_reader),
end(right_x_reader),
std::ostream_iterator<std::string>(std::cout, " "));
std::cout << std::endl;
}
}
{
node::ptr_t left_d(create_left_tree_from("d"));
node::ptr_t right_b(create_right_tree_from("b"));
{
boost::coroutines2::coroutine<std::string>::pull_type left_d_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(left_d,out);
});
boost::coroutines2::coroutine<std::string>::pull_type right_b_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(right_b,out);
});
std::cout << "left tree from d == right tree from b? "
<< std::boolalpha
<< std::equal(begin(left_d_reader),
end(left_d_reader),
begin(right_b_reader))
<< std::endl;
}
}
{
node::ptr_t left_d(create_left_tree_from("d"));
node::ptr_t right_x(create_right_tree_from("x"));
{
boost::coroutines2::coroutine<std::string>::pull_type left_d_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(left_d,out);
});
boost::coroutines2::coroutine<std::string>::pull_type right_x_reader(
[&]( boost::coroutines2::coroutine<std::string>::push_type & out) {
traverse(right_x,out);
});
std::cout << "left tree from d == right tree from x? "
<< std::boolalpha
<< std::equal(begin(left_d_reader),
end(left_d_reader),
begin(right_x_reader))
<< std::endl;
}
}
std::cout << "Done" << std::endl;
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,48 @@
// Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <memory>
#include <boost/coroutine2/all.hpp>
#ifdef BOOST_MSVC //MS VisualStudio
__declspec(noinline) void access( char *buf);
#else // GCC
void access( char *buf) __attribute__ ((noinline));
#endif
void access( char *buf) {
buf[0] = '\0';
}
void bar( int i) {
char buf[4 * 1024];
if ( i > 0) {
access( buf);
std::cout << i << ". iteration" << std::endl;
bar( i - 1);
}
}
int main() {
int count = 384;
#if defined(BOOST_USE_SEGMENTED_STACKS)
std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
std::cout << "initial stack size = " << boost::context::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
std::cout << "application should not fail" << std::endl;
#else
std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
std::cout << "initial stack size = " << boost::context::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
std::cout << "application might fail" << std::endl;
#endif
boost::coroutines2::coroutine< void >::pull_type coro{
[count](boost::coroutines2::coroutine< void >::push_type & coro){
bar( count);
}};
std::cout << "main: done" << std::endl;
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,97 @@
// Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef TREE_H
#define TREE_H
#include <cstddef>
#include <string>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/intrusive_ptr.hpp>
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable:4355)
#endif
struct branch;
struct leaf;
struct visitor
{
virtual ~visitor() {};
virtual void visit( branch & b) = 0;
virtual void visit( leaf & l) = 0;
};
struct node
{
typedef boost::intrusive_ptr< node > ptr_t;
std::size_t use_count;
node() :
use_count( 0)
{}
virtual ~node() {}
virtual void accept( visitor & v) = 0;
friend inline void intrusive_ptr_add_ref( node * p)
{ ++p->use_count; }
friend inline void intrusive_ptr_release( node * p)
{ if ( 0 == --p->use_count) delete p; }
};
struct branch : public node
{
node::ptr_t left;
node::ptr_t right;
static ptr_t create( node::ptr_t left_, node::ptr_t right_)
{ return ptr_t( new branch( left_, right_) ); }
branch( node::ptr_t left_, node::ptr_t right_) :
left( left_), right( right_)
{}
void accept( visitor & v)
{ v.visit( * this); }
};
struct leaf : public node
{
std::string value;
static ptr_t create( std::string const& value_)
{ return ptr_t( new leaf( value_) ); }
leaf( std::string const& value_) :
value( value_)
{}
void accept( visitor & v)
{ v.visit( * this); }
};
inline
bool operator==( leaf const& l, leaf const& r)
{ return l.value == r.value; }
inline
bool operator!=( leaf const& l, leaf const& r)
{ return l.value != r.value; }
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#endif // TREE_H