Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Chapter 14. Boost.Proto

Eric Niebler

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)

Table of Contents 目錄

Preface 前言
Users' Guide 用戶指南
Getting Started 入門
Fronts Ends: Defining Terminals and Non-Terminals of Your DSEL 前端:為你的DSEL定義終結符和非終結符
Intermediate Form: Understanding and Introspecting Expressions 中間格式:理解和窺探表達式
Back Ends: Making Expression Templates Do Useful Work 後端:讓表達式模板做有用的事
Examples 示例
Background and Resources 背景及資源
Glossary 術語
Reference 參考手冊
Concepts 概念
Header <boost/proto/args.hpp>
Header <boost/proto/core.hpp>
Header <boost/proto/debug.hpp>
Header <boost/proto/deep_copy.hpp>
Header <boost/proto/domain.hpp>
Header <boost/proto/eval.hpp>
Header <boost/proto/expr.hpp>
Header <boost/proto/extends.hpp>
Header <boost/proto/fusion.hpp>
Header <boost/proto/generate.hpp>
Header <boost/proto/literal.hpp>
Header <boost/proto/make_expr.hpp>
Header <boost/proto/matches.hpp>
Header <boost/proto/operators.hpp>
Header <boost/proto/proto.hpp>
Header <boost/proto/proto_fwd.hpp>
Header <boost/proto/tags.hpp>
Header <boost/proto/traits.hpp>
Header <boost/proto/transform/arg.hpp>
Header <boost/proto/transform/call.hpp>
Header <boost/proto/transform/default.hpp>
Header <boost/proto/transform/fold.hpp>
Header <boost/proto/transform/fold_tree.hpp>
Header <boost/proto/transform/impl.hpp>
Header <boost/proto/transform/lazy.hpp>
Header <boost/proto/transform/make.hpp>
Header <boost/proto/transform/pass_through.hpp>
Header <boost/proto/transform/when.hpp>
Header <boost/proto/context/callable.hpp>
Header <boost/proto/context/default.hpp>
Header <boost/proto/context/null.hpp>
Appendices 附錄
Appendix A: History 附錄A:歷史
Appendix B: Rationale 附錄B:基本原理
Appendix C: Implementation Notes 附錄C:實現說明
Appendix D: Acknowledgements 附錄D:鳴謝

There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy.

-- William Shakespeare

Description 概述

Proto is a framework for building Domain Specific Embedded Languages in C++. It provides tools for constructing, type-checking, transforming and executing expression templates [2] . More specifically, Proto provides:
Proto 是一個在C++中構建專用領域嵌入式語言的框架。它提供了構造、類型檢查、轉化和執行 表達式模板[2] 的工具。具體地說,Proto 提供了:

  • An expression tree data structure.
    一個表達式樹的數據結構。
  • A mechanism for giving expressions additional behaviors and members.
    一個為給定的表達式添加行為和成員的機制。
  • Operator overloads for building the tree from an expression.
    從一個表達式構建表達式樹所需的操作符重載。
  • Utilities for defining the grammar to which an expression must conform.
    對表達式必須遵守的語法進行定義的工具。
  • An extensible mechanism for immediately executing an expression template.
    一個可擴展的機制,用於立即執行一個表達式模板。
  • An extensible set of tree transformations to apply to expression trees.
    一個應用於表達式樹的,可擴展的樹轉化操作集。

Motivation 動機

Expression Templates are an advanced technique that C++ library developers use to define embedded mini-languages that target specific problem domains. The technique has been used to create efficient and easy-to-use libraries for linear algebra as well as to define C++ parser generators with a readable syntax. But developing such a library involves writing an inordinate amount of unreadable and unmaintainable template mumbo-jumbo. Boost.Proto eases the development of domain-specific embedded languages (DSELs). Use Proto to define the primitives of your mini-language and let Proto handle the operator overloading and the construction of the expression parse tree. Immediately evaluate the expression tree by passing it a function object. Or transform the expression tree by defining the grammar of your mini-language, decorated with an assortment of tree transforms provided by Proto or defined by you. Then use the grammar to give your users short and readable syntax errors for invalid expressions! No more mumbo-jumbo -- an expression template library developed with Proto is declarative and readable.
表 達式模板是一種高級技術,C++庫開發者所使用它來定義以某個特定問題域為目標的嵌入式小型語言。該技術已被用於創建高效且易用的線性代數庫,還被用於以 可讀的語法來定義 C++ 分析器的生成器。但是,開發這樣一個庫需要編寫大量難以閱讀且難以維護的模板。Boost.Proto 使得 專用領域嵌入式語言(DSELs) 的開發變得容易。使用 Proto 來定義你的小型語言的基本組件,並讓 Proto 處理操作符的重載和表達式分析樹的構造。通過將表達式樹傳遞給一個函數對象,可以立即對它進行求值。或者通過定義定義你的小型語言的語法,再以由 Proto 所提供的或由你定義的各種各樣的樹變換操作來對表達式樹進行變換。然後,使用該語法給你的用戶帶來對無效表達式的簡短易讀的語法錯誤提示!沒有更多的繁文 縟節了 -- 用 Proto 開發出來的表達式模板庫是具有宣示性和可讀性的。

In short, Proto is a DSEL for defining DSELs.
簡而言之,Proto 是一個用於定義 DSELs 的 DSEL。

How to Use This Documentation 如何使用本文檔

This documentation makes use of the following naming and formatting conventions.
本文檔使用了以下命名約定和格式約定。

  • Code is in fixed width font and is syntax-highlighted.
    代碼採用 fixed width font 並具有語法高亮。
  • Replaceable text that you will need to supply is in italics .
    要由你提供的可替換文本採用 italics 
  • If a name refers to a free function, it is specified like this: free_function(); that is, it is in code font and its name is followed by () to indicate that it is a free function.
    如果某個名字代表一個普通函數,則寫為:free_function(); 即採用代碼的字體並在名字後跟 () 以表示它是一個普通函數。
  • If a name refers to a class template, it is specified like this: class_template<>; that is, it is in code font and its name is followed by <> to indicate that it is a class template.
    如果某個名字代表一個類模板,則寫為:class_template<>; 即採用代碼的字體並在名字後跟 <> 以表示它是一個類模板。
  • If a name refers to a function-like macro, it is specified like this: MACRO(); that is, it is uppercase in code font and its name is followed by () to indicate that it is a function-like macro. Object-like macros appear without the trailing ().
    如果某個名字代表一個類似於函數的宏,則寫為:MACRO(); 即採用代碼字體的大寫並在名字後跟 () 以表示它是一個類似於函數的宏。類似於對象的宏則沒有後面的 ()
  • Names that refer to concepts in the generic programming sense are specified in CamelCase.
    代表泛型編程意義上的 概念 的名字則以 CamelCase 表示。
[Note] Note 備註

In addition, notes such as this one specify non-essential information that provides additional background or rationale.

此外,像這樣的備註則用於指定非必要的信息,以提供額外的背景或原理的說明。

Finally, you can mentally add the following to any code fragments in this document:
最後,在本文檔中的所有代碼片斷中,你都可以認為已經增加了以下代碼:

// Include all of Proto
#include <boost/proto/proto.hpp> // Create some namespace aliases
namespace mpl = boost::mpl; namespace fusion = boost::fusion; namespace proto = boost::proto; // Allow unqualified use of Proto's wildcard pattern
using proto::_;


Last revised: November 02, 2008 at 13:06:54 GMT


PrevUpHomeNext