6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Declares regular expression concepts.
19 #ifndef BOOST_REGEX_CONCEPTS_HPP_INCLUDED
20 #define BOOST_REGEX_CONCEPTS_HPP_INCLUDED
22 #include <boost/concept_archetype.hpp>
23 #include <boost/concept_check.hpp>
24 #include <boost/type_traits/is_enum.hpp>
25 #include <boost/type_traits/is_base_and_derived.hpp>
26 #include <boost/static_assert.hpp>
27 #ifndef BOOST_TEST_TR1_REGEX
28 #include <boost/regex.hpp>
38 // this can be either an integer type, an enum, or a std::bitset,
39 // we use the latter as the architype as it offers the "strictest"
40 // of the possible interfaces:
42 typedef std::bitset<512> bitmask_archetype;
45 // A strict model for the character type interface.
49 // default constructable:
51 // copy constructable / assignable:
52 char_architype(const char_architype&);
53 char_architype& operator=(const char_architype&);
54 // constructable from an integral value:
55 char_architype(unsigned long val);
57 bool operator==(const char_architype&)const;
58 bool operator!=(const char_architype&)const;
59 bool operator<(const char_architype&)const;
60 bool operator<=(const char_architype&)const;
61 bool operator>=(const char_architype&)const;
62 bool operator>(const char_architype&)const;
63 // conversion to integral type:
66 inline long hash_value(char_architype val)
69 // char_architype can not be used with basic_string:
73 template<> struct char_traits<boost::char_architype>
75 // The intent is that this template is not instantiated,
76 // but this typedef gives us a chance of compilation in
78 typedef boost::char_architype char_type;
82 // Allocator architype:
85 class allocator_architype
89 typedef const T* const_pointer;
91 typedef const T& const_reference;
93 typedef unsigned size_type;
94 typedef int difference_type;
99 typedef allocator_architype<U> other;
102 pointer address(reference r){ return &r; }
103 const_pointer address(const_reference r) { return &r; }
104 pointer allocate(size_type n) { return static_cast<pointer>(std::malloc(n)); }
105 pointer allocate(size_type n, pointer) { return static_cast<pointer>(std::malloc(n)); }
106 void deallocate(pointer p, size_type) { std::free(p); }
107 size_type max_size()const { return UINT_MAX; }
109 allocator_architype(){}
110 allocator_architype(const allocator_architype&){}
112 template <class Other>
113 allocator_architype(const allocator_architype<Other>&){}
115 void construct(pointer p, const_reference r) { new (p)T(r); }
116 void destroy(pointer p) { p->~T(); }
120 bool operator == (const allocator_architype<T>&, const allocator_architype<T>&) {return true; }
122 bool operator != (const allocator_architype<T>&, const allocator_architype<T>&) { return false; }
126 // regex_traits_architype:
127 // A strict interpretation of the regular expression traits class requirements.
129 template <class charT>
130 struct regex_traits_architype
133 regex_traits_architype(){}
134 typedef charT char_type;
135 // typedef std::size_t size_type;
136 typedef std::vector<char_type> string_type;
137 typedef copy_constructible_archetype<assignable_archetype<> > locale_type;
138 typedef bitmask_archetype char_class_type;
140 static std::size_t length(const char_type* ) { return 0; }
142 charT translate(charT ) const { return charT(); }
143 charT translate_nocase(charT ) const { return static_object<charT>::get(); }
145 template <class ForwardIterator>
146 string_type transform(ForwardIterator , ForwardIterator ) const
147 { return static_object<string_type>::get(); }
148 template <class ForwardIterator>
149 string_type transform_primary(ForwardIterator , ForwardIterator ) const
150 { return static_object<string_type>::get(); }
152 template <class ForwardIterator>
153 char_class_type lookup_classname(ForwardIterator , ForwardIterator ) const
154 { return static_object<char_class_type>::get(); }
155 template <class ForwardIterator>
156 string_type lookup_collatename(ForwardIterator , ForwardIterator ) const
157 { return static_object<string_type>::get(); }
159 bool isctype(charT, char_class_type) const
161 int value(charT, int) const
164 locale_type imbue(locale_type l)
166 locale_type getloc()const
167 { return static_object<locale_type>::get(); }
170 // this type is not copyable:
171 regex_traits_architype(const regex_traits_architype&){}
172 regex_traits_architype& operator=(const regex_traits_architype&){ return *this; }
176 // alter this to std::tr1, to test a std implementation:
178 #ifndef BOOST_TEST_TR1_REGEX
179 namespace global_regex_namespace = ::boost;
181 namespace global_regex_namespace = ::std::tr1;
184 template <class Bitmask>
185 struct BitmaskConcept
189 function_requires<CopyConstructibleConcept<Bitmask> >();
190 function_requires<AssignableConcept<Bitmask> >();
192 m_mask1 = m_mask2 | m_mask3;
193 m_mask1 = m_mask2 & m_mask3;
194 m_mask1 = m_mask2 ^ m_mask3;
202 Bitmask m_mask1, m_mask2, m_mask3;
205 template <class traits>
206 struct RegexTraitsConcept
208 RegexTraitsConcept();
209 // required typedefs:
210 typedef typename traits::char_type char_type;
211 // typedef typename traits::size_type size_type;
212 typedef typename traits::string_type string_type;
213 typedef typename traits::locale_type locale_type;
214 typedef typename traits::char_class_type char_class_type;
218 //function_requires<UnsignedIntegerConcept<size_type> >();
219 function_requires<RandomAccessContainerConcept<string_type> >();
220 function_requires<DefaultConstructibleConcept<locale_type> >();
221 function_requires<CopyConstructibleConcept<locale_type> >();
222 function_requires<AssignableConcept<locale_type> >();
223 function_requires<BitmaskConcept<char_class_type> >();
225 std::size_t n = traits::length(m_pointer);
226 ignore_unused_variable_warning(n);
228 char_type c = m_ctraits.translate(m_char);
229 ignore_unused_variable_warning(c);
230 c = m_ctraits.translate_nocase(m_char);
232 //string_type::foobar bar;
233 string_type s1 = m_ctraits.transform(m_pointer, m_pointer);
234 ignore_unused_variable_warning(s1);
236 string_type s2 = m_ctraits.transform_primary(m_pointer, m_pointer);
237 ignore_unused_variable_warning(s2);
239 char_class_type cc = m_ctraits.lookup_classname(m_pointer, m_pointer);
240 ignore_unused_variable_warning(cc);
242 string_type s3 = m_ctraits.lookup_collatename(m_pointer, m_pointer);
243 ignore_unused_variable_warning(s3);
245 bool b = m_ctraits.isctype(m_char, cc);
246 ignore_unused_variable_warning(b);
248 int v = m_ctraits.value(m_char, 16);
249 ignore_unused_variable_warning(v);
251 locale_type l(m_ctraits.getloc());
253 ignore_unused_variable_warning(l);
256 const traits m_ctraits;
257 const char_type* m_pointer;
260 RegexTraitsConcept& operator=(RegexTraitsConcept&);
264 // helper class to compute what traits class a regular expression type is using:
266 template <class Regex>
267 struct regex_traits_computer;
269 template <class charT, class traits>
270 struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
276 // BaseRegexConcept does not test anything dependent on basic_string,
277 // in case our charT does not have an associated char_traits:
279 template <class Regex>
280 struct BaseRegexConcept
282 typedef typename Regex::value_type value_type;
283 //typedef typename Regex::size_type size_type;
284 typedef typename Regex::flag_type flag_type;
285 typedef typename Regex::locale_type locale_type;
286 typedef input_iterator_archetype<value_type> input_iterator_type;
288 // derived test types:
289 typedef const value_type* pointer_type;
290 typedef bidirectional_iterator_archetype<value_type> BidiIterator;
291 typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
292 typedef global_regex_namespace::match_results<BidiIterator, allocator_architype<sub_match_type> > match_results_type;
293 typedef global_regex_namespace::match_results<BidiIterator> match_results_default_type;
294 typedef output_iterator_archetype<value_type> OutIterator;
295 typedef typename regex_traits_computer<Regex>::type traits_type;
296 typedef global_regex_namespace::regex_iterator<BidiIterator, value_type, traits_type> regex_iterator_type;
297 typedef global_regex_namespace::regex_token_iterator<BidiIterator, value_type, traits_type> regex_token_iterator_type;
299 void global_constraints()
302 // test non-template components:
304 function_requires<BitmaskConcept<global_regex_namespace::regex_constants::syntax_option_type> >();
305 global_regex_namespace::regex_constants::syntax_option_type opts
306 = global_regex_namespace::regex_constants::icase
307 | global_regex_namespace::regex_constants::nosubs
308 | global_regex_namespace::regex_constants::optimize
309 | global_regex_namespace::regex_constants::collate
310 | global_regex_namespace::regex_constants::ECMAScript
311 | global_regex_namespace::regex_constants::basic
312 | global_regex_namespace::regex_constants::extended
313 | global_regex_namespace::regex_constants::awk
314 | global_regex_namespace::regex_constants::grep
315 | global_regex_namespace::regex_constants::egrep;
316 ignore_unused_variable_warning(opts);
318 function_requires<BitmaskConcept<global_regex_namespace::regex_constants::match_flag_type> >();
319 global_regex_namespace::regex_constants::match_flag_type mopts
320 = global_regex_namespace::regex_constants::match_default
321 | global_regex_namespace::regex_constants::match_not_bol
322 | global_regex_namespace::regex_constants::match_not_eol
323 | global_regex_namespace::regex_constants::match_not_bow
324 | global_regex_namespace::regex_constants::match_not_eow
325 | global_regex_namespace::regex_constants::match_any
326 | global_regex_namespace::regex_constants::match_not_null
327 | global_regex_namespace::regex_constants::match_continuous
328 | global_regex_namespace::regex_constants::match_prev_avail
329 | global_regex_namespace::regex_constants::format_default
330 | global_regex_namespace::regex_constants::format_sed
331 | global_regex_namespace::regex_constants::format_no_copy
332 | global_regex_namespace::regex_constants::format_first_only;
333 ignore_unused_variable_warning(mopts);
335 BOOST_STATIC_ASSERT((::boost::is_enum<global_regex_namespace::regex_constants::error_type>::value));
336 global_regex_namespace::regex_constants::error_type e1 = global_regex_namespace::regex_constants::error_collate;
337 ignore_unused_variable_warning(e1);
338 e1 = global_regex_namespace::regex_constants::error_ctype;
339 ignore_unused_variable_warning(e1);
340 e1 = global_regex_namespace::regex_constants::error_escape;
341 ignore_unused_variable_warning(e1);
342 e1 = global_regex_namespace::regex_constants::error_backref;
343 ignore_unused_variable_warning(e1);
344 e1 = global_regex_namespace::regex_constants::error_brack;
345 ignore_unused_variable_warning(e1);
346 e1 = global_regex_namespace::regex_constants::error_paren;
347 ignore_unused_variable_warning(e1);
348 e1 = global_regex_namespace::regex_constants::error_brace;
349 ignore_unused_variable_warning(e1);
350 e1 = global_regex_namespace::regex_constants::error_badbrace;
351 ignore_unused_variable_warning(e1);
352 e1 = global_regex_namespace::regex_constants::error_range;
353 ignore_unused_variable_warning(e1);
354 e1 = global_regex_namespace::regex_constants::error_space;
355 ignore_unused_variable_warning(e1);
356 e1 = global_regex_namespace::regex_constants::error_badrepeat;
357 ignore_unused_variable_warning(e1);
358 e1 = global_regex_namespace::regex_constants::error_complexity;
359 ignore_unused_variable_warning(e1);
360 e1 = global_regex_namespace::regex_constants::error_stack;
361 ignore_unused_variable_warning(e1);
363 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::runtime_error, global_regex_namespace::regex_error>::value ));
364 const global_regex_namespace::regex_error except(e1);
367 typedef typename Regex::value_type regex_value_type;
368 function_requires< RegexTraitsConcept<global_regex_namespace::regex_traits<char> > >();
369 function_requires< BaseRegexConcept<global_regex_namespace::basic_regex<char> > >();
373 global_constraints();
375 BOOST_STATIC_ASSERT((::boost::is_same< flag_type, global_regex_namespace::regex_constants::syntax_option_type>::value));
387 ignore_unused_variable_warning(opts);
389 function_requires<DefaultConstructibleConcept<Regex> >();
390 function_requires<CopyConstructibleConcept<Regex> >();
392 // Regex constructors:
394 ignore_unused_variable_warning(e1);
395 Regex e2(m_pointer, m_flags);
396 ignore_unused_variable_warning(e2);
397 Regex e3(m_pointer, m_size, m_flags);
398 ignore_unused_variable_warning(e3);
400 ignore_unused_variable_warning(e4);
401 Regex e5(in1, in2, m_flags);
402 ignore_unused_variable_warning(e5);
410 e.assign(m_pointer, m_flags);
411 e.assign(m_pointer, m_size, m_flags);
413 e.assign(in1, in2, m_flags);
417 typename Regex::size_type i = ce.mark_count();
418 ignore_unused_variable_warning(i);
419 m_flags = ce.flags();
420 e.imbue(ce.getloc());
423 global_regex_namespace::swap(e, e1);
426 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::pair<BidiIterator, BidiIterator>, sub_match_type>::value));
427 typedef typename sub_match_type::value_type sub_value_type;
428 typedef typename sub_match_type::difference_type sub_diff_type;
429 typedef typename sub_match_type::iterator sub_iter_type;
430 BOOST_STATIC_ASSERT((::boost::is_same<sub_value_type, value_type>::value));
431 BOOST_STATIC_ASSERT((::boost::is_same<sub_iter_type, BidiIterator>::value));
432 bool b = m_sub.matched;
433 ignore_unused_variable_warning(b);
434 BidiIterator bi = m_sub.first;
435 ignore_unused_variable_warning(bi);
437 ignore_unused_variable_warning(bi);
438 sub_diff_type diff = m_sub.length();
439 ignore_unused_variable_warning(diff);
440 // match_results tests:
441 typedef typename match_results_type::value_type mr_value_type;
442 typedef typename match_results_type::const_reference mr_const_reference;
443 typedef typename match_results_type::reference mr_reference;
444 typedef typename match_results_type::const_iterator mr_const_iterator;
445 typedef typename match_results_type::iterator mr_iterator;
446 typedef typename match_results_type::difference_type mr_difference_type;
447 typedef typename match_results_type::size_type mr_size_type;
448 typedef typename match_results_type::allocator_type mr_allocator_type;
449 typedef typename match_results_type::char_type mr_char_type;
450 typedef typename match_results_type::string_type mr_string_type;
452 match_results_type m1;
453 mr_allocator_type at;
454 match_results_type m2(at);
455 match_results_type m3(m1);
460 mr_size_type mrs = m_cresults.size();
461 ignore_unused_variable_warning(mrs);
462 mrs = m_cresults.max_size();
463 ignore_unused_variable_warning(mrs);
464 b = m_cresults.empty();
465 ignore_unused_variable_warning(b);
466 mr_difference_type mrd = m_cresults.length();
467 ignore_unused_variable_warning(mrd);
468 mrd = m_cresults.length(ival);
469 ignore_unused_variable_warning(mrd);
470 mrd = m_cresults.position();
471 ignore_unused_variable_warning(mrd);
472 mrd = m_cresults.position(mrs);
473 ignore_unused_variable_warning(mrd);
475 mr_const_reference mrcr = m_cresults[ival];
476 ignore_unused_variable_warning(mrcr);
477 mr_const_reference mrcr2 = m_cresults.prefix();
478 ignore_unused_variable_warning(mrcr2);
479 mr_const_reference mrcr3 = m_cresults.suffix();
480 ignore_unused_variable_warning(mrcr3);
481 mr_const_iterator mrci = m_cresults.begin();
482 ignore_unused_variable_warning(mrci);
483 mrci = m_cresults.end();
484 ignore_unused_variable_warning(mrci);
486 mr_allocator_type at2 = m_cresults.get_allocator();
487 m_results.swap(m_results);
488 global_regex_namespace::swap(m_results, m_results);
491 b = global_regex_namespace::regex_match(m_in, m_in, m_results, e);
492 ignore_unused_variable_warning(b);
493 b = global_regex_namespace::regex_match(m_in, m_in, m_results, e, m_mft);
494 ignore_unused_variable_warning(b);
495 b = global_regex_namespace::regex_match(m_in, m_in, e);
496 ignore_unused_variable_warning(b);
497 b = global_regex_namespace::regex_match(m_in, m_in, e, m_mft);
498 ignore_unused_variable_warning(b);
499 b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e);
500 ignore_unused_variable_warning(b);
501 b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e, m_mft);
502 ignore_unused_variable_warning(b);
503 b = global_regex_namespace::regex_match(m_pointer, e);
504 ignore_unused_variable_warning(b);
505 b = global_regex_namespace::regex_match(m_pointer, e, m_mft);
506 ignore_unused_variable_warning(b);
508 b = global_regex_namespace::regex_search(m_in, m_in, m_results, e);
509 ignore_unused_variable_warning(b);
510 b = global_regex_namespace::regex_search(m_in, m_in, m_results, e, m_mft);
511 ignore_unused_variable_warning(b);
512 b = global_regex_namespace::regex_search(m_in, m_in, e);
513 ignore_unused_variable_warning(b);
514 b = global_regex_namespace::regex_search(m_in, m_in, e, m_mft);
515 ignore_unused_variable_warning(b);
516 b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e);
517 ignore_unused_variable_warning(b);
518 b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e, m_mft);
519 ignore_unused_variable_warning(b);
520 b = global_regex_namespace::regex_search(m_pointer, e);
521 ignore_unused_variable_warning(b);
522 b = global_regex_namespace::regex_search(m_pointer, e, m_mft);
523 ignore_unused_variable_warning(b);
526 typedef typename regex_iterator_type::regex_type rit_regex_type;
527 typedef typename regex_iterator_type::value_type rit_value_type;
528 typedef typename regex_iterator_type::difference_type rit_difference_type;
529 typedef typename regex_iterator_type::pointer rit_pointer;
530 typedef typename regex_iterator_type::reference rit_reference;
531 typedef typename regex_iterator_type::iterator_category rit_iterator_category;
532 BOOST_STATIC_ASSERT((::boost::is_same<rit_regex_type, Regex>::value));
533 BOOST_STATIC_ASSERT((::boost::is_same<rit_value_type, match_results_default_type>::value));
534 BOOST_STATIC_ASSERT((::boost::is_same<rit_difference_type, std::ptrdiff_t>::value));
535 BOOST_STATIC_ASSERT((::boost::is_same<rit_pointer, const match_results_default_type*>::value));
536 BOOST_STATIC_ASSERT((::boost::is_same<rit_reference, const match_results_default_type&>::value));
537 BOOST_STATIC_ASSERT((::boost::is_convertible<rit_iterator_category*, std::forward_iterator_tag*>::value));
538 // this takes care of most of the checks needed:
539 function_requires<ForwardIteratorConcept<regex_iterator_type> >();
540 regex_iterator_type iter1(m_in, m_in, e);
541 ignore_unused_variable_warning(iter1);
542 regex_iterator_type iter2(m_in, m_in, e, m_mft);
543 ignore_unused_variable_warning(iter2);
545 // regex_token_iterator:
546 typedef typename regex_token_iterator_type::regex_type rtit_regex_type;
547 typedef typename regex_token_iterator_type::value_type rtit_value_type;
548 typedef typename regex_token_iterator_type::difference_type rtit_difference_type;
549 typedef typename regex_token_iterator_type::pointer rtit_pointer;
550 typedef typename regex_token_iterator_type::reference rtit_reference;
551 typedef typename regex_token_iterator_type::iterator_category rtit_iterator_category;
552 BOOST_STATIC_ASSERT((::boost::is_same<rtit_regex_type, Regex>::value));
553 BOOST_STATIC_ASSERT((::boost::is_same<rtit_value_type, sub_match_type>::value));
554 BOOST_STATIC_ASSERT((::boost::is_same<rtit_difference_type, std::ptrdiff_t>::value));
555 BOOST_STATIC_ASSERT((::boost::is_same<rtit_pointer, const sub_match_type*>::value));
556 BOOST_STATIC_ASSERT((::boost::is_same<rtit_reference, const sub_match_type&>::value));
557 BOOST_STATIC_ASSERT((::boost::is_convertible<rtit_iterator_category*, std::forward_iterator_tag*>::value));
558 // this takes care of most of the checks needed:
559 function_requires<ForwardIteratorConcept<regex_token_iterator_type> >();
560 regex_token_iterator_type ti1(m_in, m_in, e);
561 ignore_unused_variable_warning(ti1);
562 regex_token_iterator_type ti2(m_in, m_in, e, 0);
563 ignore_unused_variable_warning(ti2);
564 regex_token_iterator_type ti3(m_in, m_in, e, 0, m_mft);
565 ignore_unused_variable_warning(ti3);
566 std::vector<int> subs;
567 regex_token_iterator_type ti4(m_in, m_in, e, subs);
568 ignore_unused_variable_warning(ti4);
569 regex_token_iterator_type ti5(m_in, m_in, e, subs, m_mft);
570 ignore_unused_variable_warning(ti5);
571 static const int i_array[3] = { 1, 2, 3, };
572 regex_token_iterator_type ti6(m_in, m_in, e, i_array);
573 ignore_unused_variable_warning(ti6);
574 regex_token_iterator_type ti7(m_in, m_in, e, i_array, m_mft);
575 ignore_unused_variable_warning(ti7);
578 pointer_type m_pointer;
581 input_iterator_type in1, in2;
582 const sub_match_type m_sub;
583 const value_type m_char;
584 match_results_type m_results;
585 const match_results_type m_cresults;
588 global_regex_namespace::regex_constants::match_flag_type m_mft;
589 global_regex_namespace::match_results<
591 allocator_architype<global_regex_namespace::sub_match<pointer_type> > >
595 BaseRegexConcept(const BaseRegexConcept&);
596 BaseRegexConcept& operator=(const BaseRegexConcept&);
601 // Test every interface in the std:
603 template <class Regex>
606 typedef typename Regex::value_type value_type;
607 //typedef typename Regex::size_type size_type;
608 typedef typename Regex::flag_type flag_type;
609 typedef typename Regex::locale_type locale_type;
611 // derived test types:
612 typedef const value_type* pointer_type;
613 typedef std::basic_string<value_type> string_type;
614 typedef boost::bidirectional_iterator_archetype<value_type> BidiIterator;
615 typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
616 typedef global_regex_namespace::match_results<BidiIterator, allocator_architype<sub_match_type> > match_results_type;
617 typedef output_iterator_archetype<value_type> OutIterator;
622 function_requires<BaseRegexConcept<Regex> >();
623 // string based construct:
625 ignore_unused_variable_warning(e1);
626 Regex e2(m_string, m_flags);
627 ignore_unused_variable_warning(e2);
633 e.assign(m_string, m_flags);
636 string_type s(m_sub);
637 ignore_unused_variable_warning(s);
639 ignore_unused_variable_warning(s);
640 int i = m_sub.compare(m_string);
641 ignore_unused_variable_warning(i);
643 int i2 = m_sub.compare(m_sub);
644 ignore_unused_variable_warning(i2);
645 i2 = m_sub.compare(m_pointer);
646 ignore_unused_variable_warning(i2);
648 bool b = m_sub == m_sub;
649 ignore_unused_variable_warning(b);
651 ignore_unused_variable_warning(b);
653 ignore_unused_variable_warning(b);
655 ignore_unused_variable_warning(b);
657 ignore_unused_variable_warning(b);
659 ignore_unused_variable_warning(b);
661 b = m_sub == m_pointer;
662 ignore_unused_variable_warning(b);
663 b = m_sub != m_pointer;
664 ignore_unused_variable_warning(b);
665 b = m_sub <= m_pointer;
666 ignore_unused_variable_warning(b);
667 b = m_sub <= m_pointer;
668 ignore_unused_variable_warning(b);
669 b = m_sub > m_pointer;
670 ignore_unused_variable_warning(b);
671 b = m_sub >= m_pointer;
672 ignore_unused_variable_warning(b);
674 b = m_pointer == m_sub;
675 ignore_unused_variable_warning(b);
676 b = m_pointer != m_sub;
677 ignore_unused_variable_warning(b);
678 b = m_pointer <= m_sub;
679 ignore_unused_variable_warning(b);
680 b = m_pointer <= m_sub;
681 ignore_unused_variable_warning(b);
682 b = m_pointer > m_sub;
683 ignore_unused_variable_warning(b);
684 b = m_pointer >= m_sub;
685 ignore_unused_variable_warning(b);
688 ignore_unused_variable_warning(b);
690 ignore_unused_variable_warning(b);
692 ignore_unused_variable_warning(b);
694 ignore_unused_variable_warning(b);
696 ignore_unused_variable_warning(b);
698 ignore_unused_variable_warning(b);
701 ignore_unused_variable_warning(b);
703 ignore_unused_variable_warning(b);
705 ignore_unused_variable_warning(b);
707 ignore_unused_variable_warning(b);
709 ignore_unused_variable_warning(b);
711 ignore_unused_variable_warning(b);
713 b = m_sub == m_string;
714 ignore_unused_variable_warning(b);
715 b = m_sub != m_string;
716 ignore_unused_variable_warning(b);
717 b = m_sub <= m_string;
718 ignore_unused_variable_warning(b);
719 b = m_sub <= m_string;
720 ignore_unused_variable_warning(b);
721 b = m_sub > m_string;
722 ignore_unused_variable_warning(b);
723 b = m_sub >= m_string;
724 ignore_unused_variable_warning(b);
726 b = m_string == m_sub;
727 ignore_unused_variable_warning(b);
728 b = m_string != m_sub;
729 ignore_unused_variable_warning(b);
730 b = m_string <= m_sub;
731 ignore_unused_variable_warning(b);
732 b = m_string <= m_sub;
733 ignore_unused_variable_warning(b);
734 b = m_string > m_sub;
735 ignore_unused_variable_warning(b);
736 b = m_string >= m_sub;
737 ignore_unused_variable_warning(b);
740 m_string = m_results.str();
741 ignore_unused_variable_warning(m_string);
742 m_string = m_results.str(0);
743 ignore_unused_variable_warning(m_string);
744 m_out = m_cresults.format(m_out, m_string);
745 m_out = m_cresults.format(m_out, m_string, m_mft);
746 m_string = m_cresults.format(m_string);
747 ignore_unused_variable_warning(m_string);
748 m_string = m_cresults.format(m_string, m_mft);
749 ignore_unused_variable_warning(m_string);
752 b = global_regex_namespace::regex_match(m_string, m_smatch, e);
753 ignore_unused_variable_warning(b);
754 b = global_regex_namespace::regex_match(m_string, m_smatch, e, m_mft);
755 ignore_unused_variable_warning(b);
756 b = global_regex_namespace::regex_match(m_string, e);
757 ignore_unused_variable_warning(b);
758 b = global_regex_namespace::regex_match(m_string, e, m_mft);
759 ignore_unused_variable_warning(b);
762 b = global_regex_namespace::regex_search(m_string, m_smatch, e);
763 ignore_unused_variable_warning(b);
764 b = global_regex_namespace::regex_search(m_string, m_smatch, e, m_mft);
765 ignore_unused_variable_warning(b);
766 b = global_regex_namespace::regex_search(m_string, e);
767 ignore_unused_variable_warning(b);
768 b = global_regex_namespace::regex_search(m_string, e, m_mft);
769 ignore_unused_variable_warning(b);
772 m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string, m_mft);
773 m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string);
774 m_string = global_regex_namespace::regex_replace(m_string, e, m_string, m_mft);
775 ignore_unused_variable_warning(m_string);
776 m_string = global_regex_namespace::regex_replace(m_string, e, m_string);
777 ignore_unused_variable_warning(m_string);
782 string_type m_string;
783 const sub_match_type m_sub;
784 match_results_type m_results;
785 pointer_type m_pointer;
787 const match_results_type m_cresults;
790 global_regex_namespace::regex_constants::match_flag_type m_mft;
791 global_regex_namespace::match_results<typename string_type::const_iterator, allocator_architype<global_regex_namespace::sub_match<typename string_type::const_iterator> > > m_smatch;
794 RegexConcept(const RegexConcept&);
795 RegexConcept& operator=(const RegexConcept&);
798 #ifndef BOOST_REGEX_TEST_STD
803 typedef typename M::char_type char_type;
804 const char_type* operator()(const M&)const
806 static const char_type c = static_cast<char_type>(0);
813 typedef typename M::char_type char_type;
814 std::vector<char_type> operator()(const M&)const
816 static const std::vector<char_type> c;
824 O operator()(const M& /*m*/, O i)const
833 O operator()(const M& /*m*/, O i, regex_constants::match_flag_type)const
840 // BoostRegexConcept:
841 // Test every interface in the Boost implementation:
843 template <class Regex>
844 struct BoostRegexConcept
846 typedef typename Regex::value_type value_type;
847 typedef typename Regex::size_type size_type;
848 typedef typename Regex::flag_type flag_type;
849 typedef typename Regex::locale_type locale_type;
851 // derived test types:
852 typedef const value_type* pointer_type;
853 typedef std::basic_string<value_type> string_type;
854 typedef typename Regex::const_iterator const_iterator;
855 typedef bidirectional_iterator_archetype<value_type> BidiIterator;
856 typedef output_iterator_archetype<value_type> OutputIterator;
857 typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
858 typedef global_regex_namespace::match_results<BidiIterator, allocator_architype<sub_match_type> > match_results_type;
859 typedef global_regex_namespace::match_results<BidiIterator> match_results_default_type;
863 global_regex_namespace::regex_constants::match_flag_type mopts
864 = global_regex_namespace::regex_constants::match_default
865 | global_regex_namespace::regex_constants::match_not_bol
866 | global_regex_namespace::regex_constants::match_not_eol
867 | global_regex_namespace::regex_constants::match_not_bow
868 | global_regex_namespace::regex_constants::match_not_eow
869 | global_regex_namespace::regex_constants::match_any
870 | global_regex_namespace::regex_constants::match_not_null
871 | global_regex_namespace::regex_constants::match_continuous
872 | global_regex_namespace::regex_constants::match_partial
873 | global_regex_namespace::regex_constants::match_prev_avail
874 | global_regex_namespace::regex_constants::format_default
875 | global_regex_namespace::regex_constants::format_sed
876 | global_regex_namespace::regex_constants::format_perl
877 | global_regex_namespace::regex_constants::format_no_copy
878 | global_regex_namespace::regex_constants::format_first_only;
882 function_requires<RegexConcept<Regex> >();
883 const global_regex_namespace::regex_error except(global_regex_namespace::regex_constants::error_collate);
884 std::ptrdiff_t pt = except.position();
885 ignore_unused_variable_warning(pt);
887 #ifndef BOOST_NO_STD_LOCALE
890 unsigned i = ce.error_code();
891 ignore_unused_variable_warning(i);
892 pointer_type p = ce.expression();
893 ignore_unused_variable_warning(p);
894 int i2 = ce.compare(ce2);
895 ignore_unused_variable_warning(i2);
897 ignore_unused_variable_warning(b);
899 ignore_unused_variable_warning(b);
901 ignore_unused_variable_warning(b);
903 ignore_unused_variable_warning(b);
905 ignore_unused_variable_warning(b);
907 ignore_unused_variable_warning(b);
909 ignore_unused_variable_warning(b);
911 ignore_unused_variable_warning(i);
912 size_type s = ce.max_size();
913 ignore_unused_variable_warning(s);
915 ignore_unused_variable_warning(s);
916 const_iterator pi = ce.begin();
917 ignore_unused_variable_warning(pi);
919 ignore_unused_variable_warning(pi);
920 string_type s2 = ce.str();
921 ignore_unused_variable_warning(s2);
923 m_string = m_sub + m_sub;
924 ignore_unused_variable_warning(m_string);
925 m_string = m_sub + m_pointer;
926 ignore_unused_variable_warning(m_string);
927 m_string = m_pointer + m_sub;
928 ignore_unused_variable_warning(m_string);
929 m_string = m_sub + m_string;
930 ignore_unused_variable_warning(m_string);
931 m_string = m_string + m_sub;
932 ignore_unused_variable_warning(m_string);
933 m_string = m_sub + m_char;
934 ignore_unused_variable_warning(m_string);
935 m_string = m_char + m_sub;
936 ignore_unused_variable_warning(m_string);
938 // Named sub-expressions:
939 m_sub = m_cresults[&m_char];
940 ignore_unused_variable_warning(m_sub);
941 m_sub = m_cresults[m_string];
942 ignore_unused_variable_warning(m_sub);
943 m_sub = m_cresults[""];
944 ignore_unused_variable_warning(m_sub);
945 m_sub = m_cresults[std::string("")];
946 ignore_unused_variable_warning(m_sub);
947 m_string = m_cresults.str(&m_char);
948 ignore_unused_variable_warning(m_string);
949 m_string = m_cresults.str(m_string);
950 ignore_unused_variable_warning(m_string);
951 m_string = m_cresults.str("");
952 ignore_unused_variable_warning(m_string);
953 m_string = m_cresults.str(std::string(""));
954 ignore_unused_variable_warning(m_string);
956 typename match_results_type::difference_type diff;
957 diff = m_cresults.length(&m_char);
958 ignore_unused_variable_warning(diff);
959 diff = m_cresults.length(m_string);
960 ignore_unused_variable_warning(diff);
961 diff = m_cresults.length("");
962 ignore_unused_variable_warning(diff);
963 diff = m_cresults.length(std::string(""));
964 ignore_unused_variable_warning(diff);
965 diff = m_cresults.position(&m_char);
966 ignore_unused_variable_warning(diff);
967 diff = m_cresults.position(m_string);
968 ignore_unused_variable_warning(diff);
969 diff = m_cresults.position("");
970 ignore_unused_variable_warning(diff);
971 diff = m_cresults.position(std::string(""));
972 ignore_unused_variable_warning(diff);
974 #ifndef BOOST_NO_STD_LOCALE
976 m_stream << m_cresults;
979 // Extended formatting with a functor:
981 regex_constants::match_flag_type f = regex_constants::match_default;
982 OutputIterator out = static_object<OutputIterator>::get();
984 functor3<match_results_default_type> func3;
985 functor2<match_results_default_type> func2;
986 functor1<match_results_default_type> func1;
988 functor3<match_results_type> func3b;
989 functor2<match_results_type> func2b;
990 functor1<match_results_type> func1b;
992 out = regex_format(out, m_cresults, func3b, f);
993 out = regex_format(out, m_cresults, func3b);
994 out = regex_format(out, m_cresults, func2b, f);
995 out = regex_format(out, m_cresults, func2b);
996 out = regex_format(out, m_cresults, func1b, f);
997 out = regex_format(out, m_cresults, func1b);
998 out = regex_format(out, m_cresults, boost::ref(func3b), f);
999 out = regex_format(out, m_cresults, boost::ref(func3b));
1000 out = regex_format(out, m_cresults, boost::ref(func2b), f);
1001 out = regex_format(out, m_cresults, boost::ref(func2b));
1002 out = regex_format(out, m_cresults, boost::ref(func1b), f);
1003 out = regex_format(out, m_cresults, boost::ref(func1b));
1004 out = regex_format(out, m_cresults, boost::cref(func3b), f);
1005 out = regex_format(out, m_cresults, boost::cref(func3b));
1006 out = regex_format(out, m_cresults, boost::cref(func2b), f);
1007 out = regex_format(out, m_cresults, boost::cref(func2b));
1008 out = regex_format(out, m_cresults, boost::cref(func1b), f);
1009 out = regex_format(out, m_cresults, boost::cref(func1b));
1011 m_string += regex_format(m_cresults, func3b, f);
1012 m_string += regex_format(m_cresults, func3b);
1013 m_string += regex_format(m_cresults, func2b, f);
1014 m_string += regex_format(m_cresults, func2b);
1015 m_string += regex_format(m_cresults, func1b, f);
1016 m_string += regex_format(m_cresults, func1b);
1017 m_string += regex_format(m_cresults, boost::ref(func3b), f);
1018 m_string += regex_format(m_cresults, boost::ref(func3b));
1019 m_string += regex_format(m_cresults, boost::ref(func2b), f);
1020 m_string += regex_format(m_cresults, boost::ref(func2b));
1021 m_string += regex_format(m_cresults, boost::ref(func1b), f);
1022 m_string += regex_format(m_cresults, boost::ref(func1b));
1023 m_string += regex_format(m_cresults, boost::cref(func3b), f);
1024 m_string += regex_format(m_cresults, boost::cref(func3b));
1025 m_string += regex_format(m_cresults, boost::cref(func2b), f);
1026 m_string += regex_format(m_cresults, boost::cref(func2b));
1027 m_string += regex_format(m_cresults, boost::cref(func1b), f);
1028 m_string += regex_format(m_cresults, boost::cref(func1b));
1030 out = m_cresults.format(out, func3b, f);
1031 out = m_cresults.format(out, func3b);
1032 out = m_cresults.format(out, func2b, f);
1033 out = m_cresults.format(out, func2b);
1034 out = m_cresults.format(out, func1b, f);
1035 out = m_cresults.format(out, func1b);
1036 out = m_cresults.format(out, boost::ref(func3b), f);
1037 out = m_cresults.format(out, boost::ref(func3b));
1038 out = m_cresults.format(out, boost::ref(func2b), f);
1039 out = m_cresults.format(out, boost::ref(func2b));
1040 out = m_cresults.format(out, boost::ref(func1b), f);
1041 out = m_cresults.format(out, boost::ref(func1b));
1042 out = m_cresults.format(out, boost::cref(func3b), f);
1043 out = m_cresults.format(out, boost::cref(func3b));
1044 out = m_cresults.format(out, boost::cref(func2b), f);
1045 out = m_cresults.format(out, boost::cref(func2b));
1046 out = m_cresults.format(out, boost::cref(func1b), f);
1047 out = m_cresults.format(out, boost::cref(func1b));
1049 m_string += m_cresults.format(func3b, f);
1050 m_string += m_cresults.format(func3b);
1051 m_string += m_cresults.format(func2b, f);
1052 m_string += m_cresults.format(func2b);
1053 m_string += m_cresults.format(func1b, f);
1054 m_string += m_cresults.format(func1b);
1055 m_string += m_cresults.format(boost::ref(func3b), f);
1056 m_string += m_cresults.format(boost::ref(func3b));
1057 m_string += m_cresults.format(boost::ref(func2b), f);
1058 m_string += m_cresults.format(boost::ref(func2b));
1059 m_string += m_cresults.format(boost::ref(func1b), f);
1060 m_string += m_cresults.format(boost::ref(func1b));
1061 m_string += m_cresults.format(boost::cref(func3b), f);
1062 m_string += m_cresults.format(boost::cref(func3b));
1063 m_string += m_cresults.format(boost::cref(func2b), f);
1064 m_string += m_cresults.format(boost::cref(func2b));
1065 m_string += m_cresults.format(boost::cref(func1b), f);
1066 m_string += m_cresults.format(boost::cref(func1b));
1068 out = regex_replace(out, m_in, m_in, ce, func3, f);
1069 out = regex_replace(out, m_in, m_in, ce, func3);
1070 out = regex_replace(out, m_in, m_in, ce, func2, f);
1071 out = regex_replace(out, m_in, m_in, ce, func2);
1072 out = regex_replace(out, m_in, m_in, ce, func1, f);
1073 out = regex_replace(out, m_in, m_in, ce, func1);
1074 out = regex_replace(out, m_in, m_in, ce, boost::ref(func3), f);
1075 out = regex_replace(out, m_in, m_in, ce, boost::ref(func3));
1076 out = regex_replace(out, m_in, m_in, ce, boost::ref(func2), f);
1077 out = regex_replace(out, m_in, m_in, ce, boost::ref(func2));
1078 out = regex_replace(out, m_in, m_in, ce, boost::ref(func1), f);
1079 out = regex_replace(out, m_in, m_in, ce, boost::ref(func1));
1080 out = regex_replace(out, m_in, m_in, ce, boost::cref(func3), f);
1081 out = regex_replace(out, m_in, m_in, ce, boost::cref(func3));
1082 out = regex_replace(out, m_in, m_in, ce, boost::cref(func2), f);
1083 out = regex_replace(out, m_in, m_in, ce, boost::cref(func2));
1084 out = regex_replace(out, m_in, m_in, ce, boost::cref(func1), f);
1085 out = regex_replace(out, m_in, m_in, ce, boost::cref(func1));
1087 functor3<match_results<typename string_type::const_iterator> > func3s;
1088 functor2<match_results<typename string_type::const_iterator> > func2s;
1089 functor1<match_results<typename string_type::const_iterator> > func1s;
1090 m_string += regex_replace(m_string, ce, func3s, f);
1091 m_string += regex_replace(m_string, ce, func3s);
1092 m_string += regex_replace(m_string, ce, func2s, f);
1093 m_string += regex_replace(m_string, ce, func2s);
1094 m_string += regex_replace(m_string, ce, func1s, f);
1095 m_string += regex_replace(m_string, ce, func1s);
1096 m_string += regex_replace(m_string, ce, boost::ref(func3s), f);
1097 m_string += regex_replace(m_string, ce, boost::ref(func3s));
1098 m_string += regex_replace(m_string, ce, boost::ref(func2s), f);
1099 m_string += regex_replace(m_string, ce, boost::ref(func2s));
1100 m_string += regex_replace(m_string, ce, boost::ref(func1s), f);
1101 m_string += regex_replace(m_string, ce, boost::ref(func1s));
1102 m_string += regex_replace(m_string, ce, boost::cref(func3s), f);
1103 m_string += regex_replace(m_string, ce, boost::cref(func3s));
1104 m_string += regex_replace(m_string, ce, boost::cref(func2s), f);
1105 m_string += regex_replace(m_string, ce, boost::cref(func2s));
1106 m_string += regex_replace(m_string, ce, boost::cref(func1s), f);
1107 m_string += regex_replace(m_string, ce, boost::cref(func1s));
1110 std::basic_ostream<value_type> m_stream;
1111 sub_match_type m_sub;
1112 pointer_type m_pointer;
1113 string_type m_string;
1114 const value_type m_char;
1115 match_results_type m_results;
1116 const match_results_type m_cresults;
1119 BoostRegexConcept();
1120 BoostRegexConcept(const BoostRegexConcept&);
1121 BoostRegexConcept& operator=(const BoostRegexConcept&);
1124 #endif // BOOST_REGEX_TEST_STD