1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
|
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2012 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)
-->
<header name="boost/proto/matches.hpp">
<para>
Contains definition of the
<computeroutput>
<classname alt="boost::proto::matches">proto::matches<></classname>
</computeroutput>
metafunction for determining if a given expression matches a given pattern.
</para>
<namespace name="boost">
<namespace name="proto">
<struct name="_">
<inherit><type><classname>proto::transform</classname><_></type></inherit>
<purpose>A wildcard grammar element that matches any expression, and a transform that returns
the current expression unchanged.</purpose>
<description>
<para>
The wildcard type, <computeroutput>proto::_</computeroutput>, is a grammar element such
that <computeroutput><classname>proto::matches</classname><E, proto::_>::value</computeroutput>
is <computeroutput>true</computeroutput> for any expression type <computeroutput>E</computeroutput>.
</para>
<para>
The wildcard can also be used as a stand-in for a template argument when matching terminals.
For instance, the following is a grammar that will match any
<computeroutput>std::complex<></computeroutput> terminal:<programlisting>BOOST_MPL_ASSERT((
<classname>proto::matches</classname><
<classname>proto::terminal</classname><std::complex<double> >::type,
<emphasis role="bold"><classname>proto::terminal</classname><std::complex< proto::_ > ></emphasis>
>
));</programlisting>
</para>
<para>
When used as a transform, <computeroutput>proto::_</computeroutput> returns the current expression
unchanged. For instance, in the following, <computeroutput>proto::_</computeroutput> is used with
the <computeroutput><classname alt="proto::fold">proto::fold<></classname></computeroutput>
transform to fold the children of a node:<programlisting>struct CountChildren :
<classname>proto::or_</classname><
// Terminals have no children
<classname>proto::when</classname><<classname>proto::terminal</classname><proto::_>, mpl::int_<0>()>,
// Use proto::fold<> to count the children of non-terminals
<classname>proto::otherwise</classname><
<classname>proto::fold</classname><
proto::_, // <-- fold the current expression
mpl::int_<0>(),
mpl::plus<<classname>proto::_state</classname>, mpl::int_<1> >()
>
>
>
{};</programlisting>
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type><classname>proto::transform_impl</classname><Expr, State, Data></type></inherit>
<typedef name="result_type">
<type>Expr</type>
</typedef>
<method-group name="public member functions">
<method name="operator()" cv="const">
<type>Expr</type>
<parameter name="expr">
<paramtype>typename impl::expr_param</paramtype>
<description>
<para>An expression </para>
</description>
</parameter>
<parameter name="">
<paramtype>typename impl::state_param</paramtype>
</parameter>
<parameter name="">
<paramtype>typename impl::data_param</paramtype>
</parameter>
<returns>
<para>
<computeroutput>expr</computeroutput>
</para>
</returns>
</method>
</method-group>
</struct>
<typedef name="proto_grammar">
<type>_</type>
</typedef>
</struct>
<!-- proto::not_ -->
<struct name="not_">
<template>
<template-type-parameter name="Grammar"/>
</template>
<inherit><type><classname>proto::transform</classname><not_<Grammar> ></type></inherit>
<purpose>Inverts the set of expressions matched by a grammar. When used as a transform,
<computeroutput>proto::not_<></computeroutput> returns the current expression unchanged.
</purpose>
<description>
<para>
If an expression type <computeroutput>E</computeroutput> does not match a grammar
<computeroutput>G</computeroutput>, then <computeroutput>E</computeroutput> <emphasis>does</emphasis>
match <computeroutput>proto::not_<G></computeroutput>. For example,
<computeroutput><classname>proto::not_</classname><<classname>proto::terminal</classname><<classname>proto::_</classname>> ></computeroutput>
will match any non-terminal.
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type><classname>proto::transform_impl</classname><Expr, State, Data></type></inherit>
<typedef name="result_type">
<type>Expr</type>
</typedef>
<method-group name="public member functions">
<method name="operator()" cv="const">
<type>Expr</type>
<parameter name="expr">
<paramtype>typename impl::expr_param</paramtype>
<description>
<para>An expression </para>
</description>
</parameter>
<parameter name="">
<paramtype>typename impl::state_param</paramtype>
</parameter>
<parameter name="">
<paramtype>typename impl::data_param</paramtype>
</parameter>
<requires>
<para>
<computeroutput><classname>proto::matches</classname><Expr, proto::not_>::value</computeroutput>
is <computeroutput>true</computeroutput>.
</para>
</requires>
<returns>
<para>
<computeroutput>expr</computeroutput>
</para>
</returns>
</method>
</method-group>
</struct>
<typedef name="proto_grammar">
<type>not_</type>
</typedef>
</struct>
<!-- proto::if_ -->
<struct name="if_">
<template>
<template-type-parameter name="If"/>
<template-type-parameter name="Then">
<default><type><classname>proto::_</classname></type></default>
</template-type-parameter>
<template-type-parameter name="Else">
<default><type><classname>proto::not_</classname><<classname>proto::_</classname>></type></default>
</template-type-parameter>
</template>
<inherit><classname>proto::transform</classname><if_<If, Then, Else> ></inherit>
<purpose>Used to select one grammar or another based on the result of a compile-time Boolean.
When used as a transform, <computeroutput>proto::if_<></computeroutput> selects between two
transforms based on a compile-time Boolean.</purpose>
<description>
<para>
When <computeroutput>proto::if_<If, Then, Else></computeroutput> is used as a grammar,
<computeroutput>If</computeroutput> must be a Proto transform and
<computeroutput>Then</computeroutput> and <computeroutput>Else</computeroutput> must be grammars.
An expression type <computeroutput>E</computeroutput> matches
<computeroutput>proto::if_<If, Then, Else></computeroutput> if
<computeroutput>boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, If>(E)>::type::value</computeroutput>
is <computeroutput>true</computeroutput> and
<computeroutput>E</computeroutput> matches <computeroutput>Then</computeroutput>; or, if
<computeroutput>boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, If>(E)>::type::value</computeroutput>
is <computeroutput>false</computeroutput> and <computeroutput>E</computeroutput> matches <computeroutput>Else</computeroutput>.
</para>
<para>
The template parameter <computeroutput>Then</computeroutput> defaults to <computeroutput><classname>proto::_</classname></computeroutput>
and <computeroutput>Else</computeroutput> defaults to
<computeroutput><classname>proto::not_</classname><<classname>proto::_</classname>></computeroutput>,
so an expression type <computeroutput>E</computeroutput> will match
<computeroutput>proto::if_<If></computeroutput> if and only if
<computeroutput>boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, If>(E)>::type::value</computeroutput>
is <computeroutput>true</computeroutput>.
</para>
<para>
<programlisting>// A grammar that only matches integral terminals,
// using is_integral<> from Boost.Type_traits.
struct IsIntegral :
<classname>proto::and_</classname><
<classname>proto::terminal</classname><<classname>proto::_</classname>>,
<classname>proto::if_</classname>< boost::is_integral<<classname>proto::_value</classname>>()>
>
{};</programlisting>
</para>
<para>
When <computeroutput>proto::if_<If, Then, Else></computeroutput> is used as a transform,
<computeroutput>If</computeroutput>, <computeroutput>Then</computeroutput> and
<computeroutput>Else</computeroutput> must be Proto transforms. When applying the transform to
an expression <computeroutput>E</computeroutput>, state <computeroutput>S</computeroutput> and
data <computeroutput>V</computeroutput>, if
<computeroutput>boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, If>(E,S,V)>::type::value</computeroutput>
is <computeroutput>true</computeroutput> then the <computeroutput>Then</computeroutput> transform
is applied; otherwise the <computeroutput>Else</computeroutput> transform is applied.
<programlisting>// Match a terminal. If the terminal is integral, return
// mpl::true_; otherwise, return mpl::false_.
struct IsIntegral2 :
<classname>proto::when</classname><
<classname>proto::terminal</classname><_>,
proto::if_<
boost::is_integral<<classname>proto::_value</classname>>(),
mpl::true_(),
mpl::false_()
>
>
{};</programlisting>
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type><classname>proto::transform_impl</classname>< Expr, State, Data ></type></inherit>
<typedef name="result_type">
<type>typename mpl::if_<
typename boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, If>(Expr, State, Data)>::type,
typename boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, Then>(Expr, State, Data)>::type,
typename boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>, Else>(Expr, State, Data)>::type
>::type</type>
</typedef>
<method-group name="public member functions">
<method name="operator()" cv="const">
<type>result_type</type>
<parameter name="expr">
<paramtype>typename impl::expr_param</paramtype>
<description>
<para>An expression </para>
</description>
</parameter>
<parameter name="state">
<paramtype>typename impl::state_param</paramtype>
<description>
<para>The current state </para>
</description>
</parameter>
<parameter name="data">
<paramtype>typename impl::data_param</paramtype>
<description>
<para>A data of arbitrary type </para>
</description>
</parameter>
<returns>
<para>
<computeroutput><classname>proto::when</classname><<classname>proto::_</classname>, <replaceable>Then-or-Else</replaceable>>()(expr, state, data)</computeroutput>
</para>
</returns>
</method>
</method-group>
</struct>
<typedef name="proto_grammar">
<type>if_</type>
</typedef>
</struct>
<!-- proto::or_ -->
<struct name="or_">
<template>
<template-type-parameter name="G" pack="1"/>
</template>
<inherit><type><classname>proto::transform</classname><or_<G...> ></type></inherit>
<purpose>For matching one of a set of alternate grammars. Alternates are tried in order to avoid ambiguity.
When used as a transform, <computeroutput>proto::or_<></computeroutput> applies the transform
associated with the first grammar that matches the expression.</purpose>
<description>
<para>
An expression type <computeroutput>E</computeroutput> matches
<computeroutput>proto::or_<G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>></computeroutput>
if <computeroutput>E</computeroutput> matches any <computeroutput>G<subscript>x</subscript></computeroutput> for
<computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
</para>
<para>
When applying
<computeroutput>proto::or_<G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>></computeroutput>
as a transform with an expression <computeroutput>e</computeroutput> of type <computeroutput>E</computeroutput>,
state <computeroutput>s</computeroutput> and data <computeroutput>d</computeroutput>, it is equivalent to
<computeroutput>G<subscript>x</subscript>()(e, s, d)</computeroutput>, where
<computeroutput>x</computeroutput> is the lowest number such that
<computeroutput><classname>proto::matches</classname><E, G<subscript>x</subscript>>::value</computeroutput>
is <computeroutput>true</computeroutput>.
</para>
<para>
The maximun number of template arguments <computeroutput>proto::or_<></computeroutput> accepts
is controlled by the <computeroutput><macroname>BOOST_PROTO_MAX_LOGICAL_ARITY</macroname></computeroutput>
macro.
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type><classname>proto::transform_impl</classname>< Expr, State, Data ></type></inherit>
<typedef name="result_type">
<type><replaceable>unspecified</replaceable></type>
</typedef>
<method-group name="public member functions">
<method name="operator()" cv="const">
<type>result_type</type>
<parameter name="expr">
<paramtype>typename impl::expr_param</paramtype>
<description>
<para>An expression </para>
</description>
</parameter>
<parameter name="state">
<paramtype>typename impl::state_param</paramtype>
<description>
<para>The current state </para>
</description>
</parameter>
<parameter name="data">
<paramtype>typename impl::data_param</paramtype>
<description>
<para>A data of arbitrary type </para>
</description>
</parameter>
<returns>
<para>
<computeroutput>
G<subscript>x</subscript>()(expr, state, data)
</computeroutput>, where
<computeroutput>x</computeroutput> is the lowest number such that
<computeroutput>
<classname>proto::matches</classname><Expr, G<subscript>x</subscript>>::value
</computeroutput>
is <computeroutput>true</computeroutput>.
</para>
</returns>
</method>
</method-group>
</struct>
<typedef name="proto_grammar">
<type>or_</type>
</typedef>
</struct>
<!-- proto::and_ -->
<struct name="and_">
<template>
<template-type-parameter name="G" pack="1"/>
</template>
<inherit><type><classname>proto::transform</classname><and_<G...> ></type></inherit>
<purpose>For matching all of a set of grammars. When used as a transform,
<computeroutput>proto::and_<></computeroutput> applies the transform associated
with each grammar in the set and returns the result of the last.</purpose>
<description>
<para>
An expression type <computeroutput>E</computeroutput> matches
<computeroutput>proto::and_<G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>></computeroutput>
if <computeroutput>E</computeroutput> matches all <computeroutput>G<subscript>x</subscript></computeroutput>
for <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
</para>
<para>
When applying
<computeroutput>proto::and_<G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>></computeroutput>
as a transform with an expression <computeroutput>e</computeroutput>, state
<computeroutput>s</computeroutput> and data <computeroutput>d</computeroutput>, it is equivalent
to <computeroutput>(G<subscript>0</subscript>()(e, s, d),G<subscript>1</subscript>()(e, s, d),...G<subscript>n</subscript>()(e, s, d))</computeroutput>.
</para>
<para>
The maximun number of template arguments <computeroutput>proto::and_<></computeroutput> accepts
is controlled by the <computeroutput><macroname>BOOST_PROTO_MAX_LOGICAL_ARITY</macroname></computeroutput>
macro.
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type><classname>proto::transform_impl</classname>< Expr, State, Data ></type></inherit>
<typedef name="result_type">
<type>typename boost::result_of<G<subscript>n</subscript>(Expr, State, Data)>::type</type>
</typedef>
<method-group name="public member functions">
<method name="operator()" cv="const">
<type>result_type</type>
<parameter name="expr">
<paramtype>typename impl::expr_param</paramtype>
<description>
<para>An expression </para>
</description>
</parameter>
<parameter name="state">
<paramtype>typename impl::state_param</paramtype>
<description>
<para>The current state </para>
</description>
</parameter>
<parameter name="data">
<paramtype>typename impl::data_param</paramtype>
<description>
<para>A data of arbitrary type </para>
</description>
</parameter>
<returns>
<para>
<computeroutput>(G<subscript>0</subscript>()(expr, state, data),G<subscript>1</subscript>()(expr, state, data),...G<subscript>n</subscript>()(expr, state, data))</computeroutput>
</para>
</returns>
</method>
</method-group>
</struct>
<typedef name="proto_grammar">
<type>and_</type>
</typedef>
</struct>
<!-- proto::switch_ -->
<struct name="switch_">
<template>
<template-type-parameter name="Cases"/>
<template-type-parameter name="Transform"/>
</template>
<inherit><classname>proto::transform</classname><switch_<Cases, Transform> ></inherit>
<purpose>For matching one of a set of alternate grammars, which are looked up based on
the result type of the transform passed in second template parameter.
If no transform is passed, the default one is <computeroutput><classname>proto::tag_of</classname><<classname>proto::_</classname>>()</computeroutput>
so the default matching is based on the expression's tag type. When used as a transform,
<computeroutput>proto::switch_<></computeroutput> applies the transform associated
with the sub-grammar that matches the expression.</purpose>
<description>
<para>
An expression type <computeroutput>E</computeroutput> matches
<computeroutput>proto::switch_<C,T></computeroutput> if
<computeroutput>E</computeroutput> matches
<computeroutput>C::case_<boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>,T>(E)>::type></computeroutput>.
</para>
<para>
When applying <computeroutput>proto::switch_<C,T></computeroutput> as a
transform with an expression <computeroutput>e</computeroutput> of type
<computeroutput>E</computeroutput>, state <computeroutput>s</computeroutput> of
type <computeroutput>S</computeroutput> and data <computeroutput>d</computeroutput>
of type <computeroutput>D</computeroutput>, it is equivalent to
<computeroutput>C::case_<boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>,T>(E,S,D)>::type>()(e, s, d)</computeroutput>.
</para>
</description>
<struct name="impl">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="State"/>
<template-type-parameter name="Data"/>
</template>
<inherit><type>
Cases::template case_<
typename <classname>when</classname><_, Transform>::template impl<Expr, State, Data>::result_type
>::template impl<Expr, State, Data></type>
</inherit>
</struct>
<typedef name="proto_grammar">
<type>switch_</type>
</typedef>
</struct>
<!-- proto::exact -->
<struct name="exact">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>For forcing exact matches of terminal types.</purpose>
<description>
<para>By default, matching terminals ignores references and cv-qualifiers. For instance,
a terminal expression of type
<computeroutput><classname>proto::terminal</classname><int const &>::type</computeroutput>
will match the grammar <computeroutput><classname>proto::terminal</classname><int></computeroutput>.
If that is not desired, you can force an exact match with
<computeroutput><classname>proto::terminal</classname><proto::exact<int> ></computeroutput>.
This will only match integer terminals where the terminal is held by value.</para>
</description>
</struct>
<!-- proto::convertible_to -->
<struct name="convertible_to">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>For matching terminals that are convertible to a type.</purpose>
<description>
<para>
Use <computeroutput>proto::convertible_to<></computeroutput> to match a terminal that is
convertible to some type. For example, the grammar
<computeroutput><classname>proto::terminal</classname><proto::convertible_to<int> ></computeroutput>
will match any terminal whose argument is convertible to an integer.
</para>
</description>
</struct>
<!-- proto::vararg -->
<struct name="vararg">
<template>
<template-type-parameter name="Grammar"/>
</template>
<purpose>For matching a Grammar to a variable number of sub-expressions.</purpose>
<description>
<para>
An expression type <computeroutput><classname>proto::basic_expr</classname><AT,
<classname alt="proto::listN">proto::list<replaceable>N</replaceable></classname><A<subscript>0</subscript>,...A<subscript>n</subscript>,U<subscript>0</subscript>,...U<subscript>m</subscript>> ></computeroutput>
matches a grammar <computeroutput><classname>proto::basic_expr</classname><BT,
<classname alt="proto::listN">proto::list<replaceable>M</replaceable></classname><B<subscript>0</subscript>,...B<subscript>n</subscript>,proto::vararg<V> > ></computeroutput>
if <computeroutput>BT</computeroutput> is <computeroutput><classname>proto::_</classname></computeroutput>
or <computeroutput>AT</computeroutput>, and if
<computeroutput>A<subscript>x</subscript></computeroutput> matches
<computeroutput>B<subscript>x</subscript></computeroutput>
for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>
and if <computeroutput>U<subscript>x</subscript></computeroutput> matches
<computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,m]</computeroutput>.
</para>
<para>For example:</para>
<para>
<programlisting>// Match any function call expression, regardless
// of the number of function arguments:
struct Function :
<classname>proto::function</classname>< proto::vararg<proto::_> >
{};</programlisting>
</para>
<para>
When used as a transform, <computeroutput>proto::vararg<G></computeroutput>
applies <computeroutput>G</computeroutput>'s transform.
</para>
</description>
</struct>
<!-- proto::matches -->
<struct name="matches">
<template>
<template-type-parameter name="Expr"/>
<template-type-parameter name="Grammar"/>
</template>
<purpose>A Boolean metafunction that evaluates whether a given expression type matches a grammar.</purpose>
<description>
<para>
<computeroutput>proto::matches<Expr, Grammar></computeroutput> inherits from
<computeroutput>mpl::true_</computeroutput> if
<computeroutput>Expr::proto_grammar</computeroutput> matches
<computeroutput>Grammar::proto_grammar</computeroutput>, and from
<computeroutput>mpl::false_</computeroutput> otherwise.
</para>
<para>
Non-terminal expressions are matched against a grammar according to the following rules:
<itemizedlist>
<listitem>
<para>
The wildcard pattern, <computeroutput>
<classname>proto::_</classname>
</computeroutput>, matches any expression.
</para>
</listitem>
<listitem>
<para>
An expression
<computeroutput>
<classname>proto::basic_expr</classname><AT,
<classname alt="proto::listN">
proto::list<replaceable>N</replaceable>
</classname><A<subscript>0</subscript>,...A<subscript>n</subscript>>
>
</computeroutput>
matches a grammar
<computeroutput>
<classname>proto::basic_expr</classname><BT,
<classname alt="proto::listN">
proto::list<replaceable>N</replaceable>
</classname><B<subscript>0</subscript>,...B<subscript>n</subscript>>
>
</computeroutput> if
<computeroutput>BT</computeroutput> is <computeroutput>
<classname>proto::_</classname>
</computeroutput> or
<computeroutput>AT</computeroutput>, and if <computeroutput>
A<subscript>x</subscript>
</computeroutput> matches
<computeroutput>
B<subscript>x</subscript>
</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression
<computeroutput>
<classname>proto::basic_expr</classname><AT,
<classname alt="proto::listN">
proto::list<replaceable>N</replaceable>
</classname><A<subscript>0</subscript>,...A<subscript>n</subscript>,U<subscript>0</subscript>,...U<subscript>m</subscript>>
>
</computeroutput> matches a grammar
<computeroutput>
<classname>proto::basic_expr</classname><BT,
<classname alt="proto::listN">
proto::list<replaceable>M</replaceable>
</classname><B<subscript>0</subscript>,...B<subscript>n</subscript>,<classname>proto::vararg</classname><V>
> >
</computeroutput> if
<computeroutput>BT</computeroutput> is <computeroutput>
<classname>proto::_</classname>
</computeroutput> or
<computeroutput>AT</computeroutput>, and if
<computeroutput>
A<subscript>x</subscript>
</computeroutput> matches
<computeroutput>
B<subscript>x</subscript>
</computeroutput> for each
<computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput> and if
<computeroutput>
U<subscript>x</subscript>
</computeroutput> matches
<computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in
<computeroutput>[0,m]</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression <computeroutput>E</computeroutput> matches
<computeroutput>
<classname>proto::or_</classname><B<subscript>0</subscript>,...B<subscript>n</subscript>>
</computeroutput> if
<computeroutput>E</computeroutput> matches some
<computeroutput>
B<subscript>x</subscript>
</computeroutput> for
<computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression <computeroutput>E</computeroutput> matches
<computeroutput>
<classname>proto::and_</classname><B<subscript>0</subscript>,...B<subscript>n</subscript>>
</computeroutput> if
<computeroutput>E</computeroutput> matches all
<computeroutput>
B<subscript>x</subscript>
</computeroutput> for
<computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression <computeroutput>E</computeroutput> matches
<computeroutput>
<classname>proto::if_</classname><T,U,V>
</computeroutput> if:
<itemizedlist>
<listitem>
<computeroutput>
boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>,T>(E)>::type::value
</computeroutput>
is <computeroutput>true</computeroutput> and
<computeroutput>E</computeroutput> matches
<computeroutput>U</computeroutput>, <emphasis>or</emphasis>
</listitem>
<listitem>
<computeroutput>
boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>,T>(E)>::type::value
</computeroutput>
is <computeroutput>false</computeroutput> and <computeroutput>E</computeroutput> matches
<computeroutput>V</computeroutput>.
</listitem>
</itemizedlist>
Note: <computeroutput>U</computeroutput> defaults to <computeroutput>
<classname>proto::_</classname>
</computeroutput>
and <computeroutput>V</computeroutput> defaults to
<computeroutput>
<classname>proto::not_</classname><<classname>proto::_</classname>>
</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression <computeroutput>E</computeroutput> matches
<computeroutput>
<classname>proto::not_</classname><T>
</computeroutput> if
<computeroutput>E</computeroutput> does <emphasis>not</emphasis> match <computeroutput>T</computeroutput>.
</para>
</listitem>
<listitem>
<para>
An expression <computeroutput>E</computeroutput> matches
<computeroutput>
<classname>proto::switch_</classname><C, T>
</computeroutput> if
<computeroutput>E</computeroutput> matches <computeroutput>C::case_<boost::result_of<<classname>proto::when</classname><<classname>proto::_</classname>,T>(E)>::type></computeroutput>.
Note: <computeroutput>T</computeroutput> defaults to <computeroutput><classname>proto::tag_of</classname><<classname>proto::_</classname>>()</computeroutput>
</para>
</listitem>
</itemizedlist>
</para>
<para>
A terminal expression can trivially match the grammar <classname>proto::_</classname>. In addition,
a terminal expression
<computeroutput>
<classname>proto::basic_expr</classname><AT,
<classname>proto::term</classname><A> >
</computeroutput> matches a grammar
<computeroutput>
<classname>proto::basic_expr</classname><BT, <classname>proto::term</classname><B> >
</computeroutput>
if <computeroutput>BT</computeroutput> is <computeroutput><classname>proto::_</classname></computeroutput>
or <computeroutput>AT</computeroutput> and one of the following is true:
<itemizedlist>
<listitem>
<para>
<computeroutput>B</computeroutput> is the wildcard pattern,
<computeroutput>
<classname>proto::_</classname>
</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>B</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>B &</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>B const &</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>B</computeroutput> is <computeroutput>
<classname>proto::exact</classname><A>
</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>B</computeroutput> is
<computeroutput>
<classname>proto::convertible_to</classname><X>
</computeroutput>
and <computeroutput>boost::is_convertible<A,X>::value</computeroutput> is
<computeroutput>true</computeroutput>.
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or
<computeroutput>X(&)[M]</computeroutput> and
<computeroutput>B</computeroutput> is <computeroutput>
X[<globalname>proto::N</globalname>]
</computeroutput>.
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>X(&)[M]</computeroutput>
and <computeroutput>B</computeroutput> is <computeroutput>
X(&)[<globalname>proto::N</globalname>]
</computeroutput>.
</para>
</listitem>
<listitem>
<para>
<computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or
<computeroutput>X(&)[M]</computeroutput> and <computeroutput>B</computeroutput> is
<computeroutput>X*</computeroutput>.
</para>
</listitem>
<listitem>
<para>
<computeroutput>B</computeroutput> <replaceable>lambda-matches</replaceable>
<computeroutput>A</computeroutput> (see below).
</para>
</listitem>
</itemizedlist>
</para>
<para>
A type <computeroutput>B</computeroutput> <replaceable>lambda-matches</replaceable>
<computeroutput>A</computeroutput> if one of the following is true:
<itemizedlist>
<listitem>
<para>
<computeroutput>B</computeroutput> is <computeroutput>A</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>B</computeroutput> is the wildcard pattern, <computeroutput>
<classname>proto::_</classname>
</computeroutput>
</para>
</listitem>
<listitem>
<para>
<computeroutput>B</computeroutput> is <computeroutput>
T<B<subscript>0</subscript>,...B<subscript>n</subscript>>
</computeroutput> and <computeroutput>A</computeroutput> is <computeroutput>
T<A<subscript>0</subscript>,...A<subscript>n</subscript>>
</computeroutput> and for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>,
<computeroutput>A<subscript>x</subscript></computeroutput> and
<computeroutput>B<subscript>x</subscript></computeroutput> are types such that
<computeroutput>A<subscript>x</subscript></computeroutput> <replaceable>lambda-matches</replaceable>
<computeroutput>B<subscript>x</subscript></computeroutput>
</para>
</listitem>
</itemizedlist>
</para>
</description>
<inherit>
<type>mpl::bool_<<replaceable>true-or-false</replaceable>></type></inherit>
</struct>
</namespace>
</namespace>
</header>
|