Boost Phoenix 入門 (2)

來源:互聯網
上載者:User

Phoenix 庫有著優雅的設計,它的11個模組分為4層,模組的功能之間完全正交,沒有循環相依性。低層模組不依賴高層模組,同一層的模組之間也不互相依賴。這意味著使用者可以自由選用自己需要的模組,而不需要把其餘部分包含進來。

 

Core

位於 Phoenix 庫最底層(第一層)的是 Actor 模組,它是對於 Phoenix functor 的原型定義,做了一個 functor 最基本的工作:重載 operator()。
Actor 分為兩種:Primitives 和 Composites,這兩個模組構成 Phoenix 庫的第二層。第一層和第二層稱為 Phoenix 的 Core。

Primitives 提供了 Phoenix 庫的功能“磚頭”,而 Composites 則是“水泥”,把磚頭粘接起來形成更大的功能塊。

 

功能模組

Primitives 包括3種:Function,Operator 和 Statement。
Function --- 用來支援 Lazy functions (例如 add)
Operator --- 用來支援 Lazy operators (例如 +)
Statement --- 用來支援 Lazy statements (例如 if_, while_)
Composites 也包括3種:Object,Scope 和 Bind。
Object --- 支援 Lazy cast(例如 static_cast_)以及對象的建立和銷毀(new_ 和 delete_)
Scope --- 支援範圍,本地變數和 lambda-lambda
Bind --- 有點類似 boost::bind,用來把普通函數,成員函數和成員變數封裝成 lazy functions

以上的6個模組位於 Phoenix 的第三層

 

"Lazy" STL

在 Phoenix 的最高層(第四層),是兩個模仿 STL 的模組:Container(也稱為 Intrinsic)和 Algorithm。

Container 提供的不是容器,而是容器的方法的 lazy 版本,例如 push_back
Algorithm 就是 STL 演算法的 lazy 版本

 

包含檔案

Core   #include <boost/spirit/home/phoenix/core.hpp>
Function   #include <boost/spirit/home/phoenix/function.hpp>
Operator   #include <boost/spirit/home/phoenix/operator.hpp>
Statement   #include <boost/spirit/home/phoenix/statement.hpp>

Object   #include <boost/spirit/home/phoenix/object.hpp>
Scope   #include <boost/spirit/home/phoenix/scope.hpp>
Bind   #include <boost/spirit/home/phoenix/bind.hpp>
Container   #include <boost/spirit/home/phoenix/container.hpp>
Algorithm   #include <boost/spirit/home/phoenix/algorithm.hpp>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.