summaryrefslogtreecommitdiff
path: root/boost/xpressive/regex_actions.hpp
blob: 1f9617ba316c2bececd0c680e1aad6bdf24d2e65 (plain)
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
///////////////////////////////////////////////////////////////////////////////
/// \file regex_actions.hpp
/// Defines the syntax elements of xpressive's action expressions.
//
//  Copyright 2008 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)

#ifndef BOOST_XPRESSIVE_ACTIONS_HPP_EAN_03_22_2007
#define BOOST_XPRESSIVE_ACTIONS_HPP_EAN_03_22_2007

// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#include <boost/config.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/ref.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/noncopyable.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/throw_exception.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/state.hpp>
#include <boost/xpressive/detail/core/matcher/attr_matcher.hpp>
#include <boost/xpressive/detail/core/matcher/attr_end_matcher.hpp>
#include <boost/xpressive/detail/core/matcher/attr_begin_matcher.hpp>
#include <boost/xpressive/detail/core/matcher/predicate_matcher.hpp>
#include <boost/xpressive/detail/utility/ignore_unused.hpp>
#include <boost/xpressive/detail/static/type_traits.hpp>

// These are very often needed by client code.
#include <boost/typeof/std/map.hpp>
#include <boost/typeof/std/string.hpp>

// Doxygen can't handle proto :-(
#ifndef BOOST_XPRESSIVE_DOXYGEN_INVOKED
# include <boost/proto/core.hpp>
# include <boost/proto/transform.hpp>
# include <boost/xpressive/detail/core/matcher/action_matcher.hpp>
#endif

/// INTERNAL ONLY
///
#define UNREF(x)    typename remove_reference<x>::type

/// INTERNAL ONLY
///
#define UNCVREF(x)  typename remove_cv<typename remove_reference<x>::type>::type

#if BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4510) // default constructor could not be generated
#pragma warning(disable : 4512) // assignment operator could not be generated
#pragma warning(disable : 4610) // can never be instantiated - user defined constructor required
#endif

namespace boost { namespace xpressive
{

    namespace detail
    {
        template<typename T, typename U>
        struct action_arg
        {
            typedef T type;
            typedef typename add_reference<T>::type reference;

            reference cast(void *pv) const
            {
                return *static_cast<UNREF(T) *>(pv);
            }
        };

        template<typename T>
        struct value_wrapper
          : private noncopyable
        {
            value_wrapper()
              : value()
            {}

            value_wrapper(T const &t)
              : value(t)
            {}

            T value;
        };

        struct check_tag
        {};

        struct BindArg
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result;

            template<typename This, typename MatchResults, typename Expr>
            struct result<This(MatchResults, Expr)>
            {
                typedef Expr type;
            };

            template<typename MatchResults, typename Expr>
            Expr const & operator ()(MatchResults &what, Expr const &expr) const
            {
                what.let(expr);
                return expr;
            }
        };

        struct let_tag
        {};

        // let(_a = b, _c = d)
        struct BindArgs
          : proto::function<
                proto::terminal<let_tag>
              , proto::vararg<
                    proto::when<
                        proto::assign<proto::_, proto::_>
                      , proto::call<BindArg(proto::_data, proto::_)>
                    >
                >
            >
        {};

        struct let_domain
          : boost::proto::domain<boost::proto::pod_generator<let_> >
        {};

        template<typename Expr>
        struct let_
        {
            BOOST_PROTO_BASIC_EXTENDS(Expr, let_<Expr>, let_domain)
            BOOST_PROTO_EXTENDS_FUNCTION()
        };

        template<typename Args, typename BidiIter>
        void bind_args(let_<Args> const &args, match_results<BidiIter> &what)
        {
            BindArgs()(args, 0, what);
        }

        typedef boost::proto::functional::make_expr<proto::tag::function, proto::default_domain> make_function;
    }

    namespace op
    {
        struct at
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result;

            template<typename This, typename Cont, typename Idx>
            struct result<This(Cont, Idx)>
              : result<This(Cont const &, Idx)>
            {
            };

            template<typename This, typename Cont, typename Idx>
            struct result<This(Cont &, Idx)>
            {
                typedef typename Cont::reference type;
            };

            template<typename This, typename Cont, typename Idx>
            struct result<This(Cont const &, Idx)>
            {
                typedef typename Cont::const_reference type;
            };

            template<typename Cont, typename Idx>
            typename Cont::reference operator()(Cont &c, Idx idx BOOST_PROTO_DISABLE_IF_IS_CONST(Cont)) const
            {
                return c[idx];
            }

            template<typename Cont, typename Idx>
            typename Cont::const_reference operator()(Cont const &c, Idx idx) const
            {
                return c[idx];
            }
        };

        struct push
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence, typename Value>
            void operator()(Sequence &seq, Value const &val) const
            {
                seq.push(val);
            }
        };

        struct push_back
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence, typename Value>
            void operator()(Sequence &seq, Value const &val) const
            {
                seq.push_back(val);
            }
        };

        struct push_front
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence, typename Value>
            void operator()(Sequence &seq, Value const &val) const
            {
                seq.push_front(val);
            }
        };

        struct pop
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence>
            void operator()(Sequence &seq) const
            {
                seq.pop();
            }
        };

        struct pop_back
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence>
            void operator()(Sequence &seq) const
            {
                seq.pop_back();
            }
        };

        struct pop_front
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            template<typename Sequence>
            void operator()(Sequence &seq) const
            {
                seq.pop_front();
            }
        };

        struct front
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Sequence>
            struct result<This(Sequence)>
            {
                typedef UNREF(Sequence) sequence_type;
                typedef
                    typename mpl::if_c<
                        is_const<sequence_type>::value
                      , typename sequence_type::const_reference
                      , typename sequence_type::reference
                    >::type
                type;
            };

            template<typename Sequence>
            typename result<front(Sequence &)>::type operator()(Sequence &seq) const
            {
                return seq.front();
            }
        };

        struct back
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Sequence>
            struct result<This(Sequence)>
            {
                typedef UNREF(Sequence) sequence_type;
                typedef
                    typename mpl::if_c<
                        is_const<sequence_type>::value
                      , typename sequence_type::const_reference
                      , typename sequence_type::reference
                    >::type
                type;
            };

            template<typename Sequence>
            typename result<back(Sequence &)>::type operator()(Sequence &seq) const
            {
                return seq.back();
            }
        };

        struct top
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Sequence>
            struct result<This(Sequence)>
            {
                typedef UNREF(Sequence) sequence_type;
                typedef
                    typename mpl::if_c<
                        is_const<sequence_type>::value
                      , typename sequence_type::value_type const &
                      , typename sequence_type::value_type &
                    >::type
                type;
            };

            template<typename Sequence>
            typename result<top(Sequence &)>::type operator()(Sequence &seq) const
            {
                return seq.top();
            }
        };

        struct first
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Pair>
            struct result<This(Pair)>
            {
                typedef UNREF(Pair)::first_type type;
            };

            template<typename Pair>
            typename Pair::first_type operator()(Pair const &p) const
            {
                return p.first;
            }
        };

        struct second
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Pair>
            struct result<This(Pair)>
            {
                typedef UNREF(Pair)::second_type type;
            };

            template<typename Pair>
            typename Pair::second_type operator()(Pair const &p) const
            {
                return p.second;
            }
        };

        struct matched
        {
            BOOST_PROTO_CALLABLE()
            typedef bool result_type;

            template<typename Sub>
            bool operator()(Sub const &sub) const
            {
                return sub.matched;
            }
        };

        struct length
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Sub>
            struct result<This(Sub)>
            {
                typedef UNREF(Sub)::difference_type type;
            };

            template<typename Sub>
            typename Sub::difference_type operator()(Sub const &sub) const
            {
                return sub.length();
            }
        };

        struct str
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename Sub>
            struct result<This(Sub)>
            {
                typedef UNREF(Sub)::string_type type;
            };

            template<typename Sub>
            typename Sub::string_type operator()(Sub const &sub) const
            {
                return sub.str();
            }
        };

        // This codifies the return types of the various insert member
        // functions found in sequence containers, the 2 flavors of
        // associative containers, and strings.
        struct insert
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig, typename EnableIf = void>
            struct result
            {};

            // assoc containers
            template<typename This, typename Cont, typename Value>
            struct result<This(Cont, Value), void>
            {
                typedef UNREF(Cont) cont_type;
                typedef UNREF(Value) value_type;
                static cont_type &scont_;
                static value_type &svalue_;
                typedef char yes_type;
                typedef char (&no_type)[2];
                static yes_type check_insert_return(typename cont_type::iterator);
                static no_type check_insert_return(std::pair<typename cont_type::iterator, bool>);
                BOOST_STATIC_CONSTANT(bool, is_iterator = (sizeof(yes_type) == sizeof(check_insert_return(scont_.insert(svalue_)))));
                typedef
                    typename mpl::if_c<
                        is_iterator
                      , typename cont_type::iterator
                      , std::pair<typename cont_type::iterator, bool>
                    >::type
                type;
            };

            // sequence containers, assoc containers, strings
            template<typename This, typename Cont, typename It, typename Value>
            struct result<This(Cont, It, Value),
                typename disable_if<mpl::or_<is_integral<UNCVREF(It)>, is_same<UNCVREF(It), UNCVREF(Value)> > >::type>
            {
                typedef UNREF(Cont)::iterator type;
            };

            // strings
            template<typename This, typename Cont, typename Size, typename T>
            struct result<This(Cont, Size, T),
                typename enable_if<is_integral<UNCVREF(Size)> >::type>
            {
                typedef UNREF(Cont) &type;
            };

            // assoc containers
            template<typename This, typename Cont, typename It>
            struct result<This(Cont, It, It), void>
            {
                typedef void type;
            };

            // sequence containers, strings
            template<typename This, typename Cont, typename It, typename Size, typename Value>
            struct result<This(Cont, It, Size, Value),
                typename disable_if<is_integral<UNCVREF(It)> >::type>
            {
                typedef void type;
            };

            // strings
            template<typename This, typename Cont, typename Size, typename A0, typename A1>
            struct result<This(Cont, Size, A0, A1),
                typename enable_if<is_integral<UNCVREF(Size)> >::type>
            {
                typedef UNREF(Cont) &type;
            };

            /// operator()
            ///
            template<typename Cont, typename A0>
            typename result<insert(Cont &, A0 const &)>::type
            operator()(Cont &cont, A0 const &a0) const
            {
                return cont.insert(a0);
            }

            /// \overload
            ///
            template<typename Cont, typename A0, typename A1>
            typename result<insert(Cont &, A0 const &, A1 const &)>::type
            operator()(Cont &cont, A0 const &a0, A1 const &a1) const
            {
                return cont.insert(a0, a1);
            }

            /// \overload
            ///
            template<typename Cont, typename A0, typename A1, typename A2>
            typename result<insert(Cont &, A0 const &, A1 const &, A2 const &)>::type
            operator()(Cont &cont, A0 const &a0, A1 const &a1, A2 const &a2) const
            {
                return cont.insert(a0, a1, a2);
            }
        };

        struct make_pair
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result {};

            template<typename This, typename First, typename Second>
            struct result<This(First, Second)>
            {
                typedef std::pair<UNCVREF(First), UNCVREF(Second)> type;
            };

            template<typename First, typename Second>
            std::pair<First, Second> operator()(First const &first, Second const &second) const
            {
                return std::make_pair(first, second);
            }
        };

        template<typename T>
        struct as
        {
            BOOST_PROTO_CALLABLE()
            typedef T result_type;

            template<typename Value>
            T operator()(Value const &val) const
            {
                return boost::lexical_cast<T>(val);
            }

            // Hack around some limitations in boost::lexical_cast
            T operator()(csub_match const &val) const
            {
                return val.matched
                  ? boost::lexical_cast<T>(boost::make_iterator_range(val.first, val.second))
                  : boost::lexical_cast<T>("");
            }

            #ifndef BOOST_XPRESSIVE_NO_WREGEX
            T operator()(wcsub_match const &val) const
            {
                return val.matched
                  ? boost::lexical_cast<T>(boost::make_iterator_range(val.first, val.second))
                  : boost::lexical_cast<T>("");
            }
            #endif

            template<typename BidiIter>
            T operator()(sub_match<BidiIter> const &val) const
            {
                // If this assert fires, you're trying to coerce a sequences of non-characters
                // to some other type. Xpressive doesn't know how to do that.
                typedef typename iterator_value<BidiIter>::type char_type;
                BOOST_MPL_ASSERT_MSG(
                    (xpressive::detail::is_char<char_type>::value)
                  , CAN_ONLY_CONVERT_FROM_CHARACTER_SEQUENCES
                  , (char_type)
                );
                return this->impl(val, xpressive::detail::is_string_iterator<BidiIter>());
            }

        private:
            template<typename RandIter>
            T impl(sub_match<RandIter> const &val, mpl::true_) const
            {
                return val.matched
                  ? boost::lexical_cast<T>(boost::make_iterator_range(&*val.first, &*val.first + (val.second - val.first)))
                  : boost::lexical_cast<T>("");
            }

            template<typename BidiIter>
            T impl(sub_match<BidiIter> const &val, mpl::false_) const
            {
                return boost::lexical_cast<T>(val.str());
            }
        };

        template<typename T>
        struct static_cast_
        {
            BOOST_PROTO_CALLABLE()
            typedef T result_type;

            template<typename Value>
            T operator()(Value const &val) const
            {
                return static_cast<T>(val);
            }
        };

        template<typename T>
        struct dynamic_cast_
        {
            BOOST_PROTO_CALLABLE()
            typedef T result_type;

            template<typename Value>
            T operator()(Value const &val) const
            {
                return dynamic_cast<T>(val);
            }
        };

        template<typename T>
        struct const_cast_
        {
            BOOST_PROTO_CALLABLE()
            typedef T result_type;

            template<typename Value>
            T operator()(Value const &val) const
            {
                return const_cast<T>(val);
            }
        };

        template<typename T>
        struct construct
        {
            BOOST_PROTO_CALLABLE()
            typedef T result_type;

            T operator()() const
            {
                return T();
            }

            template<typename A0>
            T operator()(A0 const &a0) const
            {
                return T(a0);
            }

            template<typename A0, typename A1>
            T operator()(A0 const &a0, A1 const &a1) const
            {
                return T(a0, a1);
            }

            template<typename A0, typename A1, typename A2>
            T operator()(A0 const &a0, A1 const &a1, A2 const &a2) const
            {
                return T(a0, a1, a2);
            }
        };

        template<typename Except>
        struct throw_
        {
            BOOST_PROTO_CALLABLE()
            typedef void result_type;

            void operator()() const
            {
                BOOST_THROW_EXCEPTION(Except());
            }

            template<typename A0>
            void operator()(A0 const &a0) const
            {
                BOOST_THROW_EXCEPTION(Except(a0));
            }

            template<typename A0, typename A1>
            void operator()(A0 const &a0, A1 const &a1) const
            {
                BOOST_THROW_EXCEPTION(Except(a0, a1));
            }

            template<typename A0, typename A1, typename A2>
            void operator()(A0 const &a0, A1 const &a1, A2 const &a2) const
            {
                BOOST_THROW_EXCEPTION(Except(a0, a1, a2));
            }
        };

        struct unwrap_reference
        {
            BOOST_PROTO_CALLABLE()
            template<typename Sig>
            struct result;

            template<typename This, typename Ref>
            struct result<This(Ref)>
            {
                typedef typename boost::unwrap_reference<Ref>::type &type;
            };

            template<typename This, typename Ref>
            struct result<This(Ref &)>
            {
                typedef typename boost::unwrap_reference<Ref>::type &type;
            };

            template<typename T>
            T &operator()(boost::reference_wrapper<T> r) const
            {
                return static_cast<T &>(r);
            }
        };
    }

    template<typename Fun>
    struct function
    {
        typedef typename proto::terminal<Fun>::type type;
    };

    function<op::at>::type const at = {{}};
    function<op::push>::type const push = {{}};
    function<op::push_back>::type const push_back = {{}};
    function<op::push_front>::type const push_front = {{}};
    function<op::pop>::type const pop = {{}};
    function<op::pop_back>::type const pop_back = {{}};
    function<op::pop_front>::type const pop_front = {{}};
    function<op::top>::type const top = {{}};
    function<op::back>::type const back = {{}};
    function<op::front>::type const front = {{}};
    function<op::first>::type const first = {{}};
    function<op::second>::type const second = {{}};
    function<op::matched>::type const matched = {{}};
    function<op::length>::type const length = {{}};
    function<op::str>::type const str = {{}};
    function<op::insert>::type const insert = {{}};
    function<op::make_pair>::type const make_pair = {{}};
    function<op::unwrap_reference>::type const unwrap_reference = {{}};

    template<typename T>
    struct value
      : proto::extends<typename proto::terminal<T>::type, value<T> >
    {
        typedef proto::extends<typename proto::terminal<T>::type, value<T> > base_type;

        value()
          : base_type()
        {}

        explicit value(T const &t)
          : base_type(base_type::proto_base_expr::make(t))
        {}

        using base_type::operator =;

        T &get()
        {
            return proto::value(*this);
        }

        T const &get() const
        {
            return proto::value(*this);
        }
    };

    template<typename T>
    struct reference
      : proto::extends<typename proto::terminal<reference_wrapper<T> >::type, reference<T> >
    {
        typedef proto::extends<typename proto::terminal<reference_wrapper<T> >::type, reference<T> > base_type;

        explicit reference(T &t)
          : base_type(base_type::proto_base_expr::make(boost::ref(t)))
        {}

        using base_type::operator =;

        T &get() const
        {
            return proto::value(*this).get();
        }
    };

    template<typename T>
    struct local
      : detail::value_wrapper<T>
      , proto::terminal<reference_wrapper<T> >::type
    {
        typedef typename proto::terminal<reference_wrapper<T> >::type base_type;

        local()
          : detail::value_wrapper<T>()
          , base_type(base_type::make(boost::ref(detail::value_wrapper<T>::value)))
        {}

        explicit local(T const &t)
          : detail::value_wrapper<T>(t)
          , base_type(base_type::make(boost::ref(detail::value_wrapper<T>::value)))
        {}

        using base_type::operator =;

        T &get()
        {
            return proto::value(*this);
        }

        T const &get() const
        {
            return proto::value(*this);
        }
    };

    /// as (a.k.a., lexical_cast)
    ///
    template<typename X2_0, typename A0>
    typename detail::make_function::impl<op::as<X2_0> const, A0 const &>::result_type const
    as(A0 const &a0)
    {
        return detail::make_function::impl<op::as<X2_0> const, A0 const &>()((op::as<X2_0>()), a0);
    }

    /// static_cast_
    ///
    template<typename X2_0, typename A0>
    typename detail::make_function::impl<op::static_cast_<X2_0> const, A0 const &>::result_type const
    static_cast_(A0 const &a0)
    {
        return detail::make_function::impl<op::static_cast_<X2_0> const, A0 const &>()((op::static_cast_<X2_0>()), a0);
    }

    /// dynamic_cast_
    ///
    template<typename X2_0, typename A0>
    typename detail::make_function::impl<op::dynamic_cast_<X2_0> const, A0 const &>::result_type const
    dynamic_cast_(A0 const &a0)
    {
        return detail::make_function::impl<op::dynamic_cast_<X2_0> const, A0 const &>()((op::dynamic_cast_<X2_0>()), a0);
    }

    /// const_cast_
    ///
    template<typename X2_0, typename A0>
    typename detail::make_function::impl<op::const_cast_<X2_0> const, A0 const &>::result_type const
    const_cast_(A0 const &a0)
    {
        return detail::make_function::impl<op::const_cast_<X2_0> const, A0 const &>()((op::const_cast_<X2_0>()), a0);
    }

    /// val()
    ///
    template<typename T>
    value<T> const val(T const &t)
    {
        return value<T>(t);
    }

    /// ref()
    ///
    template<typename T>
    reference<T> const ref(T &t)
    {
        return reference<T>(t);
    }

    /// cref()
    ///
    template<typename T>
    reference<T const> const cref(T const &t)
    {
        return reference<T const>(t);
    }

    /// check(), for testing custom assertions
    ///
    proto::terminal<detail::check_tag>::type const check = {{}};

    /// let(), for binding references to non-local variables
    ///
    detail::let_<proto::terminal<detail::let_tag>::type> const let = {{{}}};

    /// placeholder<T>, for defining a placeholder to stand in fo
    /// a variable of type T in a semantic action.
    ///
    template<typename T, int I, typename Dummy>
    struct placeholder
    {
        typedef placeholder<T, I, Dummy> this_type;
        typedef typename proto::terminal<detail::action_arg<T, mpl::int_<I> > >::type action_arg_type;

        BOOST_PROTO_EXTENDS(action_arg_type, this_type, proto::default_domain)
    };

    /// Usage: construct\<Type\>(arg1, arg2)
    ///
    /// Usage: throw_\<Exception\>(arg1, arg2)
    ///
    #define BOOST_PROTO_LOCAL_MACRO(N, typename_A, A_const_ref, A_const_ref_a, a)\
    \
    template<typename X2_0 BOOST_PP_COMMA_IF(N) typename_A(N)>\
    typename detail::make_function::impl<op::construct<X2_0> const BOOST_PP_COMMA_IF(N) A_const_ref(N)>::result_type const\
    construct(A_const_ref_a(N))\
    {\
        return detail::make_function::impl<op::construct<X2_0> const BOOST_PP_COMMA_IF(N) A_const_ref(N)>()((op::construct<X2_0>()) BOOST_PP_COMMA_IF(N) a(N));\
    }\
    \
    template<typename X2_0 BOOST_PP_COMMA_IF(N) typename_A(N)>\
    typename detail::make_function::impl<op::throw_<X2_0> const BOOST_PP_COMMA_IF(N) A_const_ref(N)>::result_type const\
    throw_(A_const_ref_a(N))\
    {\
        return detail::make_function::impl<op::throw_<X2_0> const BOOST_PP_COMMA_IF(N) A_const_ref(N)>()((op::throw_<X2_0>()) BOOST_PP_COMMA_IF(N) a(N));\
    }\
    /**/

    #define BOOST_PROTO_LOCAL_a       BOOST_PROTO_a
    #define BOOST_PROTO_LOCAL_LIMITS  (0, BOOST_PP_DEC(BOOST_PROTO_MAX_ARITY))
    #include BOOST_PROTO_LOCAL_ITERATE()

    namespace detail
    {
        inline void ignore_unused_regex_actions()
        {
            detail::ignore_unused(xpressive::at);
            detail::ignore_unused(xpressive::push);
            detail::ignore_unused(xpressive::push_back);
            detail::ignore_unused(xpressive::push_front);
            detail::ignore_unused(xpressive::pop);
            detail::ignore_unused(xpressive::pop_back);
            detail::ignore_unused(xpressive::pop_front);
            detail::ignore_unused(xpressive::top);
            detail::ignore_unused(xpressive::back);
            detail::ignore_unused(xpressive::front);
            detail::ignore_unused(xpressive::first);
            detail::ignore_unused(xpressive::second);
            detail::ignore_unused(xpressive::matched);
            detail::ignore_unused(xpressive::length);
            detail::ignore_unused(xpressive::str);
            detail::ignore_unused(xpressive::insert);
            detail::ignore_unused(xpressive::make_pair);
            detail::ignore_unused(xpressive::unwrap_reference);
            detail::ignore_unused(xpressive::check);
            detail::ignore_unused(xpressive::let);
        }

        struct mark_nbr
        {
            BOOST_PROTO_CALLABLE()
            typedef int result_type;

            int operator()(mark_placeholder m) const
            {
                return m.mark_number_;
            }
        };

        struct ReplaceAlgo
          : proto::or_<
                proto::when<
                    proto::terminal<mark_placeholder>
                  , op::at(proto::_data, proto::call<mark_nbr(proto::_value)>)
                >
              , proto::when<
                    proto::terminal<any_matcher>
                  , op::at(proto::_data, proto::size_t<0>)
                >
              , proto::when<
                    proto::terminal<reference_wrapper<proto::_> >
                  , op::unwrap_reference(proto::_value)
                >
              , proto::_default<ReplaceAlgo>
            >
        {};
    }
}}

#undef UNREF
#undef UNCVREF

#if BOOST_MSVC
#pragma warning(pop)
#endif

#endif // BOOST_XPRESSIVE_ACTIONS_HPP_EAN_03_22_2007