1/*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE concepts.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Declares regular expression concepts.
17 */
18
19#ifndef BOOST_REGEX_CONCEPTS_HPP_INCLUDED
20#define BOOST_REGEX_CONCEPTS_HPP_INCLUDED
21
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>
29#endif
30#include <bitset>
31#include <vector>
32#include <iostream>
33
34namespace boost{
35
36//
37// bitmask_archetype:
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:
41//
42typedef std::bitset<512> bitmask_archetype;
43//
44// char_architype:
45// A strict model for the character type interface.
46//
47struct char_architype
48{
49 // default constructable:
50 char_architype();
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);
56 // comparable:
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:
64 operator long()const;
65};
66inline long hash_value(char_architype val)
67{ return val; }
68//
69// char_architype can not be used with basic_string:
70//
71} // namespace boost
72namespace std{
73 template<> struct char_traits<boost::char_architype>
74 {
75 // The intent is that this template is not instantiated,
76 // but this typedef gives us a chance of compilation in
77 // case it is:
78 typedef boost::char_architype char_type;
79 };
80}
81//
82// Allocator architype:
83//
84template <class T>
85class allocator_architype
86{
87public:
88 typedef T* pointer;
89 typedef const T* const_pointer;
90 typedef T& reference;
91 typedef const T& const_reference;
92 typedef T value_type;
93 typedef unsigned size_type;
94 typedef int difference_type;
95
96 template <class U>
97 struct rebind
98 {
99 typedef allocator_architype<U> other;
100 };
101
102 pointer address(reference r);
103 const_pointer address(const_reference r);
104 pointer allocate(size_type);
105 pointer allocate(size_type, pointer);
106 void deallocate(pointer, size_type);
107 size_type max_size()const;
108
109 allocator_architype();
110 allocator_architype(const allocator_architype&);
111
112 template <class Other>
113 allocator_architype(const allocator_architype<Other>&);
114
115 void construct(pointer, const_reference);
116 void destroy(pointer);
117};
118
119template <class T>
120bool operator == (const allocator_architype<T>&, const allocator_architype<T>&);
121template <class T>
122bool operator != (const allocator_architype<T>&, const allocator_architype<T>&);
123
124namespace boost{
125//
126// regex_traits_architype:
127// A strict interpretation of the regular expression traits class requirements.
128//
129template <class charT>
130struct regex_traits_architype
131{
132public:
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;
139
140 static std::size_t length(const char_type* ) { return 0; }
141
142 charT translate(charT ) const { return charT(); }
143 charT translate_nocase(charT ) const { return static_object<charT>::get(); }
144
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(); }
151
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(); }
158
159 bool isctype(charT, char_class_type) const
160 { return false; }
161 int value(charT, int) const
162 { return 0; }
163
164 locale_type imbue(locale_type l)
165 { return l; }
166 locale_type getloc()const
167 { return static_object<locale_type>::get(); }
168
169private:
170 // this type is not copyable:
171 regex_traits_architype(const regex_traits_architype&);
172 regex_traits_architype& operator=(const regex_traits_architype&);
173};
174
175//
176// alter this to std::tr1, to test a std implementation:
177//
178#ifndef BOOST_TEST_TR1_REGEX
179namespace global_regex_namespace = ::boost;
180#else
181namespace global_regex_namespace = ::std::tr1;
182#endif
183
184template <class Bitmask>
185struct BitmaskConcept
186{
187 void constraints()
188 {
189 function_requires<CopyConstructibleConcept<Bitmask> >();
190 function_requires<AssignableConcept<Bitmask> >();
191
192 m_mask1 = m_mask2 | m_mask3;
193 m_mask1 = m_mask2 & m_mask3;
194 m_mask1 = m_mask2 ^ m_mask3;
195
196 m_mask1 = ~m_mask2;
197
198 m_mask1 |= m_mask2;
199 m_mask1 &= m_mask2;
200 m_mask1 ^= m_mask2;
201 }
202 Bitmask m_mask1, m_mask2, m_mask3;
203};
204
205template <class traits>
206struct RegexTraitsConcept
207{
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;
215
216 void constraints()
217 {
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> >();
224
225 std::size_t n = traits::length(m_pointer);
226 ignore_unused_variable_warning(n);
227
228 char_type c = m_ctraits.translate(m_char);
229 ignore_unused_variable_warning(c);
230 c = m_ctraits.translate_nocase(m_char);
231
232 //string_type::foobar bar;
233 string_type s1 = m_ctraits.transform(m_pointer, m_pointer);
234 ignore_unused_variable_warning(s1);
235
236 string_type s2 = m_ctraits.transform_primary(m_pointer, m_pointer);
237 ignore_unused_variable_warning(s2);
238
239 char_class_type cc = m_ctraits.lookup_classname(m_pointer, m_pointer);
240 ignore_unused_variable_warning(cc);
241
242 string_type s3 = m_ctraits.lookup_collatename(m_pointer, m_pointer);
243 ignore_unused_variable_warning(s3);
244
245 bool b = m_ctraits.isctype(m_char, cc);
246 ignore_unused_variable_warning(b);
247
248 int v = m_ctraits.value(m_char, 16);
249 ignore_unused_variable_warning(v);
250
251 locale_type l(m_ctraits.getloc());
252 m_traits.imbue(l);
253 ignore_unused_variable_warning(l);
254 }
255 traits m_traits;
256 const traits m_ctraits;
257 const char_type* m_pointer;
258 char_type m_char;
259private:
260 RegexTraitsConcept& operator=(RegexTraitsConcept&);
261};
262
263//
264// helper class to compute what traits class a regular expression type is using:
265//
266template <class Regex>
267struct regex_traits_computer;
268
269template <class charT, class traits>
270struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
271{
272 typedef traits type;
273};
274
275//
276// BaseRegexConcept does not test anything dependent on basic_string,
277// in case our charT does not have an associated char_traits:
278//
279template <class Regex>
280struct BaseRegexConcept
281{
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;
287
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;
298
299 void global_constraints()
300 {
301 //
302 // test non-template components:
303 //
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);
317
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);
334
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);
362
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);
365 e1 = except.code();
366
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> > >();
370 }
371 void constraints()
372 {
373 global_constraints();
374
375 BOOST_STATIC_ASSERT((::boost::is_same< flag_type, global_regex_namespace::regex_constants::syntax_option_type>::value));
376 flag_type opts
377 = Regex::icase
378 | Regex::nosubs
379 | Regex::optimize
380 | Regex::collate
381 | Regex::ECMAScript
382 | Regex::basic
383 | Regex::extended
384 | Regex::awk
385 | Regex::grep
386 | Regex::egrep;
387 ignore_unused_variable_warning(opts);
388
389 function_requires<DefaultConstructibleConcept<Regex> >();
390 function_requires<CopyConstructibleConcept<Regex> >();
391
392 // Regex constructors:
393 Regex e1(m_pointer);
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);
399 Regex e4(in1, in2);
400 ignore_unused_variable_warning(e4);
401 Regex e5(in1, in2, m_flags);
402 ignore_unused_variable_warning(e5);
403
404 // assign etc:
405 Regex e;
406 e = m_pointer;
407 e = e1;
408 e.assign(e1);
409 e.assign(m_pointer);
410 e.assign(m_pointer, m_flags);
411 e.assign(m_pointer, m_size, m_flags);
412 e.assign(in1, in2);
413 e.assign(in1, in2, m_flags);
414
415 // access:
416 const Regex ce;
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());
421 e.swap(e1);
422
423 global_regex_namespace::swap(e, e1);
424
425 // sub_match:
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);
436 bi = m_sub.second;
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;
451
452 match_results_type m1;
453 mr_allocator_type at;
454 match_results_type m2(at);
455 match_results_type m3(m1);
456 m1 = m2;
457
458 int ival = 0;
459
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);
474
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);
485
486 mr_allocator_type at2 = m_cresults.get_allocator();
487 m_results.swap(m_results);
488 global_regex_namespace::swap(m_results, m_results);
489
490 // regex_match:
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);
507 // regex_search:
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);
524
525 // regex_iterator:
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);
544
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);
576 }
577
578 pointer_type m_pointer;
579 flag_type m_flags;
580 std::size_t m_size;
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;
586 OutIterator m_out;
587 BidiIterator m_in;
588 global_regex_namespace::regex_constants::match_flag_type m_mft;
589 global_regex_namespace::match_results<
590 pointer_type,
591 allocator_architype<global_regex_namespace::sub_match<pointer_type> > >
592 m_pmatch;
593
594 BaseRegexConcept();
595 BaseRegexConcept(const BaseRegexConcept&);
596 BaseRegexConcept& operator=(const BaseRegexConcept&);
597};
598
599//
600// RegexConcept:
601// Test every interface in the std:
602//
603template <class Regex>
604struct RegexConcept
605{
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;
610
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;
618
619
620 void constraints()
621 {
622 function_requires<BaseRegexConcept<Regex> >();
623 // string based construct:
624 Regex e1(m_string);
625 ignore_unused_variable_warning(e1);
626 Regex e2(m_string, m_flags);
627 ignore_unused_variable_warning(e2);
628
629 // assign etc:
630 Regex e;
631 e = m_string;
632 e.assign(m_string);
633 e.assign(m_string, m_flags);
634
635 // sub_match:
636 string_type s(m_sub);
637 ignore_unused_variable_warning(s);
638 s = m_sub.str();
639 ignore_unused_variable_warning(s);
640 int i = m_sub.compare(m_string);
641 ignore_unused_variable_warning(i);
642
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);
647
648 bool b = m_sub == m_sub;
649 ignore_unused_variable_warning(b);
650 b = m_sub != m_sub;
651 ignore_unused_variable_warning(b);
652 b = m_sub <= m_sub;
653 ignore_unused_variable_warning(b);
654 b = m_sub <= m_sub;
655 ignore_unused_variable_warning(b);
656 b = m_sub > m_sub;
657 ignore_unused_variable_warning(b);
658 b = m_sub >= m_sub;
659 ignore_unused_variable_warning(b);
660
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);
673
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);
686
687 b = m_sub == m_char;
688 ignore_unused_variable_warning(b);
689 b = m_sub != m_char;
690 ignore_unused_variable_warning(b);
691 b = m_sub <= m_char;
692 ignore_unused_variable_warning(b);
693 b = m_sub <= m_char;
694 ignore_unused_variable_warning(b);
695 b = m_sub > m_char;
696 ignore_unused_variable_warning(b);
697 b = m_sub >= m_char;
698 ignore_unused_variable_warning(b);
699
700 b = m_char == m_sub;
701 ignore_unused_variable_warning(b);
702 b = m_char != m_sub;
703 ignore_unused_variable_warning(b);
704 b = m_char <= m_sub;
705 ignore_unused_variable_warning(b);
706 b = m_char <= m_sub;
707 ignore_unused_variable_warning(b);
708 b = m_char > m_sub;
709 ignore_unused_variable_warning(b);
710 b = m_char >= m_sub;
711 ignore_unused_variable_warning(b);
712
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);
725
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);
738
739 // match results:
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);
750
751 // regex_match:
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);
760
761 // regex_search:
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);
770
771 // regex_replace:
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);
778
779 }
780
781 flag_type m_flags;
782 string_type m_string;
783 const sub_match_type m_sub;
784 match_results_type m_results;
785 pointer_type m_pointer;
786 value_type m_char;
787 const match_results_type m_cresults;
788 OutIterator m_out;
789 BidiIterator m_in;
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;
792
793 RegexConcept();
794 RegexConcept(const RegexConcept&);
795 RegexConcept& operator=(const RegexConcept&);
796};
797
798#ifndef BOOST_REGEX_TEST_STD
799
800template <class M>
801struct functor1
802{
803 typedef typename M::char_type char_type;
804 const char_type* operator()(const M&)const
805 {
806 static const char_type c = static_cast<char_type>(0);
807 return &c;
808 }
809};
810template <class M>
811struct functor1b
812{
813 typedef typename M::char_type char_type;
814 std::vector<char_type> operator()(const M&)const
815 {
816 static const std::vector<char_type> c;
817 return c;
818 }
819};
820template <class M>
821struct functor2
822{
823 template <class O>
824 O operator()(const M& /*m*/, O i)const
825 {
826 return i;
827 }
828};
829template <class M>
830struct functor3
831{
832 template <class O>
833 O operator()(const M& /*m*/, O i, regex_constants::match_flag_type)const
834 {
835 return i;
836 }
837};
838
839//
840// BoostRegexConcept:
841// Test every interface in the Boost implementation:
842//
843template <class Regex>
844struct BoostRegexConcept
845{
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;
850
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;
860
861 void constraints()
862 {
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;
879
880 (void)mopts;
881
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);
886 const Regex ce, ce2;
887#ifndef BOOST_NO_STD_LOCALE
888 m_stream << ce;
889#endif
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);
896 bool b = ce == ce2;
897 ignore_unused_variable_warning(b);
898 b = ce.empty();
899 ignore_unused_variable_warning(b);
900 b = ce != ce2;
901 ignore_unused_variable_warning(b);
902 b = ce < ce2;
903 ignore_unused_variable_warning(b);
904 b = ce > ce2;
905 ignore_unused_variable_warning(b);
906 b = ce <= ce2;
907 ignore_unused_variable_warning(b);
908 b = ce >= ce2;
909 ignore_unused_variable_warning(b);
910 i = ce.status();
911 ignore_unused_variable_warning(i);
912 size_type s = ce.max_size();
913 ignore_unused_variable_warning(s);
914 s = ce.size();
915 ignore_unused_variable_warning(s);
916 const_iterator pi = ce.begin();
917 ignore_unused_variable_warning(pi);
918 pi = ce.end();
919 ignore_unused_variable_warning(pi);
920 string_type s2 = ce.str();
921 ignore_unused_variable_warning(s2);
922
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);
937
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);
955
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);
973
974#ifndef BOOST_NO_STD_LOCALE
975 m_stream << m_sub;
976 m_stream << m_cresults;
977#endif
978 //
979 // Extended formatting with a functor:
980 //
981 regex_constants::match_flag_type f = regex_constants::match_default;
982 OutputIterator out = static_object<OutputIterator>::get();
983
984 functor3<match_results_default_type> func3;
985 functor2<match_results_default_type> func2;
986 functor1<match_results_default_type> func1;
987
988 functor3<match_results_type> func3b;
989 functor2<match_results_type> func2b;
990 functor1<match_results_type> func1b;
991
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));
1010
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));
1029
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));
1048
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));
1067
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));
1086
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));
1108 }
1109
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;
1117 BidiIterator m_in;
1118
1119 BoostRegexConcept();
1120 BoostRegexConcept(const BoostRegexConcept&);
1121 BoostRegexConcept& operator=(const BoostRegexConcept&);
1122};
1123
1124#endif // BOOST_REGEX_TEST_STD
1125
1126}
1127
1128#endif
1129

source code of boost/boost/regex/concepts.hpp