domain.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Copyright 2012 Eric Niebler
  4. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <header name="boost/proto/domain.hpp">
  9. <para>
  10. Contains definition of the <computeroutput><classname alt="boost::proto::domain">proto::domain&lt;&gt;</classname>
  11. </computeroutput> class template and helpers for defining domains with a generator for customizing expression
  12. construction and a grammar for controlling operator overloading.
  13. </para>
  14. <namespace name="boost">
  15. <namespace name="proto">
  16. <!-- proto::domain<> -->
  17. <struct name="domain">
  18. <template>
  19. <template-type-parameter name="Generator">
  20. <default><classname>proto::default_generator</classname></default>
  21. </template-type-parameter>
  22. <template-type-parameter name="Grammar">
  23. <default><classname>proto::_</classname></default>
  24. </template-type-parameter>
  25. <template-type-parameter name="Super">
  26. <default><replaceable>unspecified</replaceable></default>
  27. </template-type-parameter>
  28. </template>
  29. <inherit><type>Generator</type></inherit>
  30. <purpose>For use in defining domain tags to be used with <computeroutput>
  31. <classname alt="proto::extends">proto::extends&lt;&gt;</classname></computeroutput>,
  32. <computeroutput><macroname>BOOST_PROTO_EXTENDS</macroname>()</computeroutput> and
  33. <computeroutput><macroname>BOOST_PROTO_DEFINE_OPERATORS</macroname>()</computeroutput>.
  34. A <emphasis>domain</emphasis> associates an expression type with a <emphasis>generator</emphasis>,
  35. and optionally a <emphasis>grammar</emphasis>. It may also have a super-domain. Expressions
  36. in a sub-domain are interoperable (i.e. can be combined freely with) expressions in a
  37. super-domain. Finally, domains control how non-Proto objects are turned into Proto
  38. expressions and how they are combined to form larger Proto expressions.
  39. </purpose>
  40. <description>
  41. <para>
  42. The Generator parameter determines how new expressions in the domain are post-processed. Typically, a generator
  43. wraps all new expressions in a wrapper that imparts domain-specific behaviors to expressions within
  44. its domain. (See <computeroutput><classname alt="proto::extends">proto::extends&lt;&gt;</classname></computeroutput>.)
  45. </para>
  46. <para>
  47. The Grammar parameter determines whether a given expression is valid within the domain, and automatically
  48. disables any operator overloads which would cause an invalid expression to be created. By default,
  49. the Grammar parameter defaults to the wildcard, <computeroutput><classname>proto::_</classname>
  50. </computeroutput>, which makes all expressions valid within the domain.
  51. </para>
  52. <para>
  53. The Super parameter declares the domain currently being defined to be a sub-domain of Super. An expression in
  54. a sub-domain can be freely combined with expressions in its super-domain (and <emphasis>its</emphasis>
  55. super-domain, etc.).
  56. </para>
  57. <para>
  58. Example: <programlisting> template&lt;typename Expr&gt;
  59. struct MyExpr;
  60. struct MyGrammar
  61. : <classname>proto::or_</classname>&lt; <classname>proto::terminal</classname>&lt;_&gt;, <classname>proto::plus</classname>&lt;MyGrammar, MyGrammar&gt; &gt;
  62. {};
  63. // Define MyDomain, in which all expressions are
  64. // wrapped in MyExpr&lt;&gt; and only expressions that
  65. // conform to MyGrammar are allowed.
  66. struct MyDomain
  67. : <classname>proto::domain</classname>&lt;<classname>proto::generator</classname>&lt;MyExpr&gt;, MyGrammar&gt;
  68. {};
  69. // Use MyDomain to define MyExpr
  70. template&lt;typename Expr&gt;
  71. struct MyExpr
  72. : <classname>proto::extends</classname>&lt;Expr, MyExpr&lt;Expr&gt;, MyDomain&gt;
  73. {
  74. // ...
  75. };
  76. </programlisting>
  77. </para>
  78. <para>
  79. The <computeroutput><classname>domain::as_expr</classname>&lt;&gt;</computeroutput> and
  80. <computeroutput><classname>domain::as_child</classname>&lt;&gt;</computeroutput> member
  81. templates define how non-Proto objects are turned into Proto terminals and how Proto
  82. expressions should be processed before they are combined to form larger expressions.
  83. They can be overridden in a derived domain for customization. See their descriptions to
  84. understand how Proto uses these two templates and what their default behavior is.
  85. </para>
  86. </description>
  87. <typedef name="proto_grammar">
  88. <type>Grammar</type>
  89. </typedef>
  90. <typedef name="proto_generator">
  91. <type>Generator</type>
  92. </typedef>
  93. <typedef name="proto_super_domain">
  94. <type>Super</type>
  95. </typedef>
  96. <struct name="as_expr">
  97. <template>
  98. <template-type-parameter name="T"/>
  99. </template>
  100. <inherit><type><classname>proto::callable</classname></type></inherit>
  101. <purpose>
  102. A callable unary MonomorphicFunctionObject that specifies how objects are turned into
  103. Proto expressions in this domain. The resulting expression object is suitable for storage
  104. in a local variable.
  105. </purpose>
  106. <description>
  107. <para>
  108. A unary MonomorphicFunctionObject that specifies how objects are turned into Proto
  109. expressions in this domain. The resulting expression object is suitable for storage
  110. in a local variable. In that scenario, it is usually preferable to return
  111. expressions by value; and, in the case of objects that are not yet Proto expressions,
  112. to wrap them by value (if possible) in a new Proto terminal expression. (Contrast
  113. this description with the description for
  114. <computeroutput><classname>proto::domain::as_child</classname></computeroutput>.)
  115. </para>
  116. <para>
  117. The <computeroutput>as_expr</computeroutput> function object turns objects into
  118. Proto expressions, if they are not already, by making them Proto terminals held by
  119. value if possible. Objects that are already Proto expressions are simply returned
  120. by value. If
  121. <computeroutput>wants_basic_expr&lt;Generator&gt;::value</computeroutput> is true,
  122. then let <emphasis>E</emphasis> be
  123. <computeroutput><classname>proto::basic_expr</classname></computeroutput>;
  124. otherwise, let <emphasis>E</emphasis> be
  125. <computeroutput><classname>proto::expr</classname></computeroutput>.
  126. Given an lvalue <computeroutput>t</computeroutput> of type
  127. <computeroutput>T</computeroutput>:
  128. <itemizedlist>
  129. <listitem>
  130. If <computeroutput>T</computeroutput> is not a Proto expression type, the resulting
  131. terminal is calculated as follows:
  132. <itemizedlist>
  133. <listitem>
  134. If <computeroutput>T</computeroutput> is a function type, an abstract type, or
  135. a type derived from <computeroutput>std::ios_base</computeroutput>, let
  136. <replaceable>A</replaceable> be <computeroutput>T &amp;</computeroutput>.
  137. </listitem>
  138. <listitem>
  139. Otherwise, let <replaceable>A</replaceable> be the type
  140. <computeroutput>T</computeroutput> stripped of cv-qualifiers.
  141. </listitem>
  142. </itemizedlist>
  143. Then, the result of <computeroutput>as_expr&lt;T&gt;()(t)</computeroutput> is
  144. <computeroutput>Generator()(<replaceable>E</replaceable>&lt;tag::terminal,
  145. term&lt; <replaceable>A</replaceable> &gt; &gt;::make(t))</computeroutput>.
  146. </listitem>
  147. <listitem>
  148. Otherwise, the result is <computeroutput>t</computeroutput> converted to an
  149. (un-const) rvalue.
  150. </listitem>
  151. </itemizedlist>
  152. </para>
  153. </description>
  154. <typedef name="result_type">
  155. <type><replaceable>see-below</replaceable></type>
  156. </typedef>
  157. <method-group name="public member functions">
  158. <method name="operator()" cv="const">
  159. <type>result_type</type>
  160. <parameter name="t">
  161. <paramtype>T &amp;</paramtype>
  162. <description>
  163. <para>The object to wrap.</para>
  164. </description>
  165. </parameter>
  166. </method>
  167. </method-group>
  168. </struct>
  169. <struct name="as_child">
  170. <template>
  171. <template-type-parameter name="T"/>
  172. </template>
  173. <inherit><type><classname>proto::callable</classname></type></inherit>
  174. <purpose>
  175. A callable unary MonomorphicFunctionObject that specifies how objects are turned into
  176. Proto expressions in this domain, for use in scenarios where the resulting expression is
  177. intended to be made a child of another expression.
  178. </purpose>
  179. <description>
  180. <para>
  181. A unary MonomorphicFunctionObject that specifies how objects are turned into Proto
  182. expressions in this domain. The resulting expression object is suitable for storage
  183. as a child of another expression. In that scenario, it is usually
  184. preferable to store child expressions by reference; or, in the case of objects that
  185. are not yet Proto expressions, to wrap them by reference in a new Proto terminal
  186. expression. (Contrast this description with the description for
  187. <computeroutput><classname>proto::domain::as_expr</classname></computeroutput>.)
  188. </para>
  189. <para>
  190. The <computeroutput>as_child</computeroutput> function object turns objects into
  191. Proto expressions, if they are not already, by making them Proto terminals held by
  192. reference. Objects that are already Proto expressions are simply returned by
  193. reference. If
  194. <computeroutput>wants_basic_expr&lt;Generator&gt;::value</computeroutput> is true,
  195. then let <emphasis>E</emphasis> be
  196. <computeroutput><classname>proto::basic_expr</classname></computeroutput>;
  197. otherwise, let <emphasis>E</emphasis> be
  198. <computeroutput><classname>proto::expr</classname></computeroutput>.
  199. Given an lvalue <computeroutput>t</computeroutput> of type
  200. <computeroutput>T</computeroutput>:
  201. <itemizedlist>
  202. <listitem>
  203. If <computeroutput>T</computeroutput> is not a Proto expression type, the resulting
  204. terminal is
  205. <computeroutput>Generator()(<replaceable>E</replaceable>&lt;tag::terminal,
  206. term&lt; <computeroutput>T &amp;</computeroutput> &gt; &gt;::make(t))</computeroutput>.
  207. </listitem>
  208. <listitem>
  209. Otherwise, the result is the lvalue <computeroutput>t</computeroutput>.
  210. </listitem>
  211. </itemizedlist>
  212. </para>
  213. </description>
  214. <typedef name="result_type">
  215. <type><replaceable>see-below</replaceable></type>
  216. </typedef>
  217. <method-group name="public member functions">
  218. <method name="operator()" cv="const">
  219. <type>result_type</type>
  220. <parameter name="t">
  221. <paramtype>T &amp;</paramtype>
  222. <description>
  223. <para>The object to wrap.</para>
  224. </description>
  225. </parameter>
  226. </method>
  227. </method-group>
  228. </struct>
  229. </struct>
  230. <!-- proto::default_domain -->
  231. <struct name="default_domain">
  232. <inherit><classname>proto::domain</classname>&lt;&gt;</inherit>
  233. <purpose>The domain expressions have by default, if <computeroutput>
  234. <classname alt="proto::extends">proto::extends&lt;&gt;</classname></computeroutput> has not been used
  235. to associate a domain with an expression.</purpose>
  236. </struct>
  237. <!-- proto::basic_default_domain -->
  238. <struct name="basic_default_domain">
  239. <inherit><classname>proto::domain</classname>&lt; <classname>proto::basic_default_generator</classname> &gt;</inherit>
  240. <purpose>A domain similiar in purpose to <classname>proto::default_domain</classname>, except stating
  241. a preference for <classname>proto::basic_expr</classname>&lt;&gt; over <classname>proto::expr</classname>&lt;&gt;.</purpose>
  242. </struct>
  243. <!-- proto::deduce_domain -->
  244. <struct name="deduce_domain">
  245. <purpose>A pseudo-domain for use in functions and metafunctions that require a domain parameter.
  246. It indicates that the domain of the parent node should be inferred from the domains of the child nodes.</purpose>
  247. <description>
  248. <para>
  249. When <computeroutput>proto::deduce_domain</computeroutput> is used as a domain &#x2014; either
  250. explicitly or implicitly by
  251. <computeroutput><functionname>proto::make_expr</functionname>()</computeroutput>,
  252. <computeroutput><functionname>proto::unpack_expr</functionname>()</computeroutput>,
  253. or Proto's operator overloads &#x2014; Proto will use the domains of the child expressions to
  254. compute the domain of the parent. It is done in such a way that (A) expressions in domains
  255. that share a common super-domain are interoperable, and (B) expressions that are in
  256. the default domain (or a sub-domain thereof) are interoperable with <emphasis>all</emphasis>
  257. expressions. The rules are as follows:
  258. <itemizedlist>
  259. <listitem>
  260. A sub-domain is <emphasis>stronger</emphasis> than its super-domain.
  261. </listitem>
  262. <listitem>
  263. <computeroutput><classname>proto::default_domain</classname></computeroutput>,
  264. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>
  265. and all their sub-domains are <emphasis>weaker</emphasis> than all other domains.
  266. </listitem>
  267. <listitem>
  268. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>
  269. is weaker than
  270. <computeroutput><classname>proto::default_domain</classname></computeroutput>.
  271. </listitem>
  272. <listitem>
  273. For each child, define a set of domains <emphasis>S<subscript>N</subscript></emphasis>
  274. that includes the child's domain and all its super-domains.
  275. </listitem>
  276. <listitem>
  277. Define a set <emphasis>I<subscript>S</subscript></emphasis> that is the intersection of
  278. all the individual sets <emphasis>S<subscript>N</subscript></emphasis> that don't contain
  279. <computeroutput><classname>proto::default_domain</classname></computeroutput> or
  280. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>.
  281. </listitem>
  282. <listitem>
  283. Define a set <emphasis>I<subscript>W</subscript></emphasis> that is the intersection of
  284. all the individual sets <emphasis>S<subscript>N</subscript></emphasis> that contain
  285. <computeroutput><classname>proto::default_domain</classname></computeroutput> or
  286. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>.
  287. </listitem>
  288. <listitem>
  289. Define a set <emphasis>P</emphasis> that is the union of
  290. <emphasis>I<subscript>S</subscript></emphasis> and
  291. <emphasis>I<subscript>W</subscript></emphasis>.
  292. </listitem>
  293. <listitem>
  294. The common domain is the strongest domain in set <emphasis>P</emphasis>, with the
  295. following caveats.
  296. </listitem>
  297. <listitem>
  298. Let <emphasis>U</emphasis> be the union of all sets
  299. <emphasis>S<subscript>N</subscript></emphasis>. If the result is
  300. <computeroutput><classname>proto::default_domain</classname></computeroutput> or
  301. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>
  302. and <emphasis>U</emphasis> contains an element that is <emphasis>not </emphasis>
  303. <computeroutput><classname>proto::default_domain</classname></computeroutput> or
  304. <computeroutput><classname>proto::basic_default_domain</classname></computeroutput>,
  305. it is an error.
  306. </listitem>
  307. </itemizedlist>
  308. </para>
  309. <para>
  310. Note: the above description sounds like it would be expensive to compute at compile time.
  311. In fact, it can all be done using C++ function overloading.
  312. </para>
  313. </description>
  314. </struct>
  315. <!-- proto::is_domain -->
  316. <struct name="is_domain">
  317. <template>
  318. <template-type-parameter name="T"/>
  319. </template>
  320. <inherit>
  321. <type>mpl::bool_&lt; <replaceable>true-or-false</replaceable> &gt;</type>
  322. </inherit>
  323. <description>
  324. <para>
  325. A metafunction that returns <computeroutput>mpl::true_</computeroutput> if the type
  326. <computeroutput>T</computeroutput> is the type of a Proto domain;
  327. <computeroutput>mpl::false_</computeroutput> otherwise. If <computeroutput>T</computeroutput>
  328. inherits from <computeroutput><classname alt="proto::domain">proto::domain&lt;&gt;</classname></computeroutput>,
  329. <computeroutput>is_domain&lt;T&gt;</computeroutput> is <computeroutput>mpl::true_</computeroutput>.
  330. </para>
  331. </description>
  332. </struct>
  333. <!-- proto::domain_of -->
  334. <struct name="domain_of">
  335. <template>
  336. <template-type-parameter name="T"/>
  337. </template>
  338. <description>
  339. <para>
  340. A metafunction that returns the domain of a given type. If <computeroutput>T</computeroutput> is a Proto
  341. expression type, it returns that expression's associated domain. If not, it returns
  342. <computeroutput><classname>proto::default_domain</classname></computeroutput>.
  343. </para>
  344. </description>
  345. <typedef name="type">
  346. <type><replaceable>domain-of-T</replaceable></type>
  347. </typedef>
  348. </struct>
  349. <!-- proto::base_expr --><!--
  350. <struct name="base_expr">
  351. <template>
  352. <template-type-parameter name="Domain"/>
  353. <template-type-parameter name="Tag"/>
  354. <template-type-parameter name="Args"/>
  355. </template>
  356. <description>
  357. <para>
  358. Given a domain, a tag type and an argument list,
  359. compute the type of the expression to generate. This is
  360. either an instance of
  361. <computeroutput><classname>proto::basic_expr</classname>&lt;&gt;</computeroutput> or
  362. <computeroutput><classname>proto::expr</classname>&lt;&gt;</computeroutput>.
  363. </para>
  364. </description>
  365. <typedef name="A">
  366. <purpose>For exposition only</purpose>
  367. <type><classname>proto::basic_expr</classname>&lt; Tag, Args &gt;</type>
  368. </typedef>
  369. <typedef name="B">
  370. <purpose>For exposition only</purpose>
  371. <type><classname>proto::expr</classname>&lt; Tag, Args &gt;</type>
  372. </typedef>
  373. <typedef name="type">
  374. <type>typename mpl::if_&lt;<classname>proto::wants_basic_expr</classname>&lt; Domain &gt;, A, B&gt;::type</type>
  375. </typedef>
  376. </struct>-->
  377. </namespace>
  378. </namespace>
  379. </header>