2013-07-31 Tim Shen <timshen91@gmail.com>
[official-gcc.git] / libstdc++-v3 / testsuite / 28_regex / algorithms / regex_match / extended / string_dispatch_01.cc
blob86fab85a434a475659de5860f89cd65275621727
1 // { dg-options "-std=gnu++11" }
3 //
4 // 2013-07-29 Tim Shen <timshen91@gmail.com>
5 //
6 // Copyright (C) 2013 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
23 // 28.11.2 regex_match
24 // Tests Extended automatic matcher dispatching against a std::string target.
26 #include <regex>
27 #include <testsuite_hooks.h>
29 using namespace std;
31 template<typename _Bi_iter, typename _Alloc,
32 typename _Ch_type, typename _Rx_traits>
33 void
34 fake_match(_Bi_iter __s,
35 _Bi_iter __e,
36 match_results<_Bi_iter, _Alloc>& __m,
37 const basic_regex<_Ch_type, _Rx_traits>& __re,
38 regex_constants::match_flag_type __flags
39 = regex_constants::match_default)
41 __detail::_AutomatonPtr __a = __re._M_get_automaton();
42 __detail::_Automaton::_SizeT __sz = __a->_M_sub_count();
43 __detail::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
44 __detail::_SpecializedResults<_Bi_iter, _Alloc> __r(__sz, __cs, __m);
45 VERIFY( dynamic_cast<__detail::_DFSMatcher *>(
46 &*__a->_M_get_matcher(__cs, __r, __a, __flags)) != nullptr );
49 void
50 test01()
52 bool test __attribute__((unused)) = true;
54 regex re("()(one(.*))abc\\1"); // backref cause DFS
55 const string target("onetwoabc");
56 smatch m;
57 fake_match(target.begin(), target.end(), m, re);
59 regex_match(target, m, re);
60 VERIFY( m[2].matched );
61 VERIFY( m[3].matched );
62 VERIFY( std::string(m[2].first, m[2].second) == "onetwo" );
63 VERIFY( std::string(m[3].first, m[3].second) == "two" );
66 int
67 main()
69 test01();
70 return 0;