examples.qbk 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. [/
  2. / Copyright (c) 2008 Eric Niebler
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [import ../example/hello.cpp]
  8. [import ../example/calc1.cpp]
  9. [import ../example/calc2.cpp]
  10. [import ../example/calc3.cpp]
  11. [import ../example/lazy_vector.cpp]
  12. [import ../example/mixed.cpp]
  13. [import ../example/rgb.cpp]
  14. [import ../example/tarray.cpp]
  15. [import ../example/vec3.cpp]
  16. [import ../example/vector.cpp]
  17. [import ../example/map_assign.cpp]
  18. [import ../example/futures.cpp]
  19. [import ../example/mini_lambda.cpp]
  20. [import ../example/external_transforms.cpp]
  21. [/===============]
  22. [section Examples]
  23. [/===============]
  24. A code example is worth a thousand words ...
  25. [/================================================================================]
  26. [section:hello_world Hello World:
  27. Building an Expression Template and Evaluating It]
  28. [/================================================================================]
  29. A trivial example which builds and expression template and evaluates it.
  30. [HelloWorld]
  31. [endsect]
  32. [/==================================================]
  33. [section:calc1 Calc1: Defining an Evaluation Context]
  34. [/==================================================]
  35. A simple example that builds a miniature embedded domain-specific language for lazy arithmetic expressions, with TR1 bind-style argument placeholders.
  36. [Calc1]
  37. [endsect]
  38. [/============================================================]
  39. [section:calc2 Calc2: Adding Members Using [^proto::extends<>]]
  40. [/============================================================]
  41. An extension of the Calc1 example that uses _extends_ to make calculator expressions valid function objects that can be used with STL algorithms.
  42. [Calc2]
  43. [endsect]
  44. [/===============================================]
  45. [section:calc3 Calc3: Defining a Simple Transform]
  46. [/===============================================]
  47. An extension of the Calc2 example that uses a Proto transform to calculate the arity of a calculator expression and statically assert that the correct number of arguments are passed.
  48. [Calc3]
  49. [endsect]
  50. [/==============================================================]
  51. [section:lazy_vector Lazy Vector: Controlling Operator Overloads]
  52. [/==============================================================]
  53. This example constructs a mini-library for linear algebra, using expression templates to eliminate the need for temporaries when adding vectors of numbers.
  54. This example uses a domain with a grammar to prune the set of overloaded operators. Only those operators that produce valid lazy vector expressions are allowed.
  55. [LazyVector]
  56. [endsect]
  57. [/========================================================]
  58. [section:rgb RGB: Type Manipulations with Proto Transforms]
  59. [/========================================================]
  60. This is a simple example of doing arbitrary type manipulations with Proto transforms. It takes some expression involving primary colors and combines the colors according to arbitrary rules. It is a port of the RGB example from _PETE_.
  61. [RGB]
  62. [endsect]
  63. [/=====================================================]
  64. [section:tarray TArray: A Simple Linear Algebra Library]
  65. [/=====================================================]
  66. This example constructs a mini-library for linear algebra, using expression templates to eliminate the need for temporaries when adding arrays of numbers. It duplicates the TArray example from _PETE_.
  67. [TArray]
  68. [endsect]
  69. [/========================================================]
  70. [section:vec3 Vec3: Computing With Transforms and Contexts]
  71. [/========================================================]
  72. This is a simple example using `proto::extends<>` to extend a terminal type with additional behaviors, and using custom contexts and `proto::eval()` for evaluating expressions. It is a port of the Vec3 example from _PETE_.
  73. [Vec3]
  74. [endsect]
  75. [/========================================================]
  76. [section:vector Vector: Adapting a Non-Proto Terminal Type]
  77. [/========================================================]
  78. This is an example of using `BOOST_PROTO_DEFINE_OPERATORS()` to Protofy expressions using `std::vector<>`, a non-Proto type. It is a port of the Vector example from _PETE_.
  79. [Vector]
  80. [endsect]
  81. [/=============================================================]
  82. [section:mixed Mixed: Adapting Several Non-Proto Terminal Types]
  83. [/=============================================================]
  84. This is an example of using `BOOST_PROTO_DEFINE_OPERATORS()` to Protofy expressions using `std::vector<>` and `std::list<>`, non-Proto types. It is a port of the Mixed example from _PETE_.
  85. [Mixed]
  86. [endsect]
  87. [/=======================================================]
  88. [section:map_assign Map Assign: An Intermediate Transform]
  89. [/=======================================================]
  90. A demonstration of how to implement `map_list_of()` from the Boost.Assign library using Proto. `map_list_assign()` is used to conveniently initialize a `std::map<>`. By using Proto, we can avoid any dynamic allocation while building the intermediate representation.
  91. [MapAssign]
  92. [endsect]
  93. [/===========================================================]
  94. [section:future_group Future Group: A More Advanced Transform]
  95. [/===========================================================]
  96. An advanced example of a Proto transform that implements Howard Hinnant's design for /future groups/ that block for all or some asynchronous operations to complete and returns their results in a tuple of the appropriate type.
  97. [FutureGroup]
  98. [endsect]
  99. [/========================================================]
  100. [section:lambda Lambda: A Simple Lambda Library with Proto]
  101. [/========================================================]
  102. This is an advanced example that shows how to implement a simple lambda EDSL with Proto, like the Boost.Lambda_library. It uses contexts, transforms and expression extension.
  103. [Lambda]
  104. [endsect]
  105. [/===============================================================================]
  106. [section:checked_calc Checked Calculator: A Simple Example of External Transforms]
  107. [/===============================================================================]
  108. This is an advanced example that shows how to externally parameterize a grammar's transforms. It defines a calculator EDSL with a grammar that can perform either checked or unchecked arithmetic.
  109. [CheckedCalc]
  110. [endsect]
  111. [endsect]