Read egg oven

24
PStade.OvenEggを読む。 Boost.勉強会 #6 札幌 @hotwatermorning

Transcript of Read egg oven

Page 1: Read egg oven

PStade.OvenとEggを読む。

Boost.勉強会 #6 札幌

@hotwatermorning

Page 2: Read egg oven

はじめに。

Page 3: Read egg oven

はじめに。● この発表の主なターゲット

Page 4: Read egg oven

はじめに。● この発表の主なターゲット● 日常的にBoostを使ってる人or使われている人

Page 5: Read egg oven

はじめに。● この発表の主なターゲット● 日常的にBoostを使ってる人or使われている人● 日常的にPStade.Oven, PStade.Eggを使ってい

る人

Page 6: Read egg oven

はじめに。● この発表の主なターゲット● 日常的にBoostを使ってる人or使われている人● 日常的にPStade.Oven, PStade.Eggを使ってい

る人● EggやOvenの実装に興味がある人

Page 7: Read egg oven

PStadeとは?

Page 8: Read egg oven

PStadeとは?● Shunsuke Sogame氏によって開発された、

C++ Template Libraryです。● Biscuit Parser Library● Ketchup Message Map Library● Egg Functional Library● Oven Range Library

などが含まれています。

Page 9: Read egg oven

PStadeとは?● Shunsuke Sogame氏によって開発された、

C++ Template Libraryです。● Biscuit Parser Library● Ketchup Message Map Library● Egg Functional Library● Oven Range Library

などが含まれています。← 今日はこの2つを 取り上げます

Page 10: Read egg oven

PStade.Egg

● A framework of making function objects.

“http://p-stade.sourceforge.net/”

● Egg is a small header-only framework of building functions, and offers higher-order functions.

“Introduction”

“http://p-stade.sourceforge.net/egg/doc/html/”

Page 11: Read egg oven

PStade.Oven

● A Boost.Range Extension Library

“http://p-stade.sourceforge.net/”

● Oven is an advanced implementation of Range Library Proposal

“Introduction”

“http://p-stade.sourceforge.net/oven/doc/html/”

Page 12: Read egg oven

PStade.Oven

● そして、PStade.Ovenの実装には、PStade.Eggが使われています。

● なので、Ovenを読もうと思うと、Eggを読む必要がある。

● 逆にEggを読めば、Ovenの理解も進みます。

Page 13: Read egg oven

というわけで、今日はOvenとEggのソースを

覗いていきたいと思います。

Page 14: Read egg oven

Ovenの使用例namespace oven = pstade::oven;

std::string const x = "ab123cde5f";

oven::copy(

x

| oven::filtered(isalpha)

| oven::transformed(toupper),

std::ostream_iterator<char>(std::cout) );

//outputs : ABCDEF

Page 15: Read egg oven

Ovenの使用例namespace oven = pstade::oven;

std::string const x = "ab123cde5f";

oven::copy(

x

| oven::filtered(isalpha)

| oven::transformed(toupper),

std::ostream_iterator<char>(std::cout) );

//outputs : ABCDEF

Range

Page 16: Read egg oven

Range

● 何らかの値の列の範囲を表す物● 生配列, std::vector, std::list, std::map,

boost::array, etc, …● コンテナじゃなくても、例えば指定された範囲

の自然数列を返すcounting rangeなんてものもある。

Page 17: Read egg oven

Ovenの使用例namespace oven = pstade::oven;

std::string const x = "ab123cde5f";

oven::copy(

x

| oven::filtered(isalpha)

| oven::transformed(toupper),

std::ostream_iterator<char>(std::cout) );

//outputs : ABCDEF

Range AdaptorRange Adaptor

Page 18: Read egg oven

Range Adaptor

● Iterator AdaptorのRange版● Rangeを横断しながら、値を変更したりスキッ

プしたりして、元のRangeから別のRangeを返す。

● 遅延評価によって、実際にRangeの値が参照されるときに、その処理の間に入って働くため、● 元のRangeは変更しない。● 返されるRangeはいちいち元のRangeを全部コピー

しているわけではない。● 計算量/空間量的にお得。

Page 19: Read egg oven

Range Adaptor

● Range Adaptorはパイプ演算子でつなげていくことが出来る。range_ | adaptor1 | adaptor2 | …

● 効果が順次適用されていく

Page 20: Read egg oven

Ovenの使用例namespace oven = pstade::oven;

std::string const x = "ab123cde5f";

oven::copy(

x

| oven::filtered(isalpha)

| oven::transformed(toupper),

std::ostream_iterator<char>(std::cout) );

//outputs : ABCDEF

Range Based Function

Page 21: Read egg oven

Range-Based Function

● STLのアルゴリズム(copy, sort, findなど)はイテレータのbeginとendを引数に取る。

● これはIterator-Based Functionと呼ばれる。● 使い勝手があんまりよくない。バグを埋めこん

でしまう可能性も高い。● Iteratorのbeginとendをまとめたもの(=Range)

を渡せるようにすればより使いやすい。

Page 22: Read egg oven

Range-Based Function

● ここら辺については、● Exceptional C++● プログラミングの魔導書vol.1

”オーブンレンジクッキング”● プログラミングの魔導少女

“RangeとPStade.Oven”● などなどに情報があります。

Page 23: Read egg oven

というわけで、これからOvenとEggのソースに

潜っていきます

Page 24: Read egg oven

Ovenの使用例namespace oven = pstade::oven;

std::string const x = "ab123cde5f";

oven::copy(

x

| oven::filtered(isalpha)

| oven::transformed(toupper),

std::ostream_iterator<char>(std::cout) );

//outputs : ABCDEF