concepts.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE concepts.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares regular expression concepts.
  16. */
  17. #ifndef BOOST_REGEX_CONCEPTS_HPP_INCLUDED
  18. #define BOOST_REGEX_CONCEPTS_HPP_INCLUDED
  19. #include <boost/concept_archetype.hpp>
  20. #include <boost/concept_check.hpp>
  21. #include <boost/type_traits/is_enum.hpp>
  22. #include <boost/type_traits/is_base_and_derived.hpp>
  23. #include <boost/static_assert.hpp>
  24. #ifndef BOOST_TEST_TR1_REGEX
  25. #include <boost/regex.hpp>
  26. #endif
  27. #include <bitset>
  28. #include <vector>
  29. #include <iostream>
  30. namespace boost{
  31. //
  32. // bitmask_archetype:
  33. // this can be either an integer type, an enum, or a std::bitset,
  34. // we use the latter as the architype as it offers the "strictest"
  35. // of the possible interfaces:
  36. //
  37. typedef std::bitset<512> bitmask_archetype;
  38. //
  39. // char_architype:
  40. // A strict model for the character type interface.
  41. //
  42. struct char_architype
  43. {
  44. // default constructable:
  45. char_architype();
  46. // copy constructable / assignable:
  47. char_architype(const char_architype&);
  48. char_architype& operator=(const char_architype&);
  49. // constructable from an integral value:
  50. char_architype(unsigned long val);
  51. // comparable:
  52. bool operator==(const char_architype&)const;
  53. bool operator!=(const char_architype&)const;
  54. bool operator<(const char_architype&)const;
  55. bool operator<=(const char_architype&)const;
  56. bool operator>=(const char_architype&)const;
  57. bool operator>(const char_architype&)const;
  58. // conversion to integral type:
  59. operator long()const;
  60. };
  61. //
  62. // char_architype can not be used with basic_string:
  63. //
  64. } // namespace boost
  65. namespace std{
  66. template<> struct char_traits<boost::char_architype>
  67. {
  68. // The intent is that this template is not instantiated,
  69. // but this typedef gives us a chance of compilation in
  70. // case it is:
  71. typedef boost::char_architype char_type;
  72. };
  73. }
  74. namespace boost{
  75. //
  76. // regex_traits_architype:
  77. // A strict interpretation of the regular expression traits class requirements.
  78. //
  79. template <class charT>
  80. struct regex_traits_architype
  81. {
  82. public:
  83. regex_traits_architype();
  84. typedef charT char_type;
  85. // typedef std::size_t size_type;
  86. typedef std::vector<char_type> string_type;
  87. typedef copy_constructible_archetype<assignable_archetype<> > locale_type;
  88. typedef bitmask_archetype char_class_type;
  89. static std::size_t length(const char_type* ) { return 0; }
  90. charT translate(charT ) const { return charT(); }
  91. charT translate_nocase(charT ) const { return static_object<charT>::get(); }
  92. template <class ForwardIterator>
  93. string_type transform(ForwardIterator , ForwardIterator ) const
  94. { return static_object<string_type>::get(); }
  95. template <class ForwardIterator>
  96. string_type transform_primary(ForwardIterator , ForwardIterator ) const
  97. { return static_object<string_type>::get(); }
  98. template <class ForwardIterator>
  99. char_class_type lookup_classname(ForwardIterator , ForwardIterator ) const
  100. { return static_object<char_class_type>::get(); }
  101. template <class ForwardIterator>
  102. string_type lookup_collatename(ForwardIterator , ForwardIterator ) const
  103. { return static_object<string_type>::get(); }
  104. bool isctype(charT, char_class_type) const
  105. { return false; }
  106. int value(charT, int) const
  107. { return 0; }
  108. locale_type imbue(locale_type l)
  109. { return l; }
  110. locale_type getloc()const
  111. { return static_object<locale_type>::get(); }
  112. private:
  113. // this type is not copyable:
  114. regex_traits_architype(const regex_traits_architype&);
  115. regex_traits_architype& operator=(const regex_traits_architype&);
  116. };
  117. //
  118. // alter this to std::tr1, to test a std implementation:
  119. //
  120. #ifndef BOOST_TEST_TR1_REGEX
  121. namespace global_regex_namespace = ::boost;
  122. #else
  123. namespace global_regex_namespace = ::std::tr1;
  124. #endif
  125. template <class Bitmask>
  126. struct BitmaskConcept
  127. {
  128. void constraints()
  129. {
  130. function_requires<CopyConstructibleConcept<Bitmask> >();
  131. function_requires<AssignableConcept<Bitmask> >();
  132. m_mask1 = m_mask2 | m_mask3;
  133. m_mask1 = m_mask2 & m_mask3;
  134. m_mask1 = m_mask2 ^ m_mask3;
  135. m_mask1 = ~m_mask2;
  136. m_mask1 |= m_mask2;
  137. m_mask1 &= m_mask2;
  138. m_mask1 ^= m_mask2;
  139. }
  140. Bitmask m_mask1, m_mask2, m_mask3;
  141. };
  142. template <class traits>
  143. struct RegexTraitsConcept
  144. {
  145. RegexTraitsConcept();
  146. // required typedefs:
  147. typedef typename traits::char_type char_type;
  148. // typedef typename traits::size_type size_type;
  149. typedef typename traits::string_type string_type;
  150. typedef typename traits::locale_type locale_type;
  151. typedef typename traits::char_class_type char_class_type;
  152. void constraints()
  153. {
  154. //function_requires<UnsignedIntegerConcept<size_type> >();
  155. function_requires<RandomAccessContainerConcept<string_type> >();
  156. function_requires<DefaultConstructibleConcept<locale_type> >();
  157. function_requires<CopyConstructibleConcept<locale_type> >();
  158. function_requires<AssignableConcept<locale_type> >();
  159. function_requires<BitmaskConcept<char_class_type> >();
  160. std::size_t n = traits::length(m_pointer);
  161. ignore_unused_variable_warning(n);
  162. char_type c = m_ctraits.translate(m_char);
  163. ignore_unused_variable_warning(c);
  164. c = m_ctraits.translate_nocase(m_char);
  165. //string_type::foobar bar;
  166. string_type s1 = m_ctraits.transform(m_pointer, m_pointer);
  167. ignore_unused_variable_warning(s1);
  168. string_type s2 = m_ctraits.transform_primary(m_pointer, m_pointer);
  169. ignore_unused_variable_warning(s2);
  170. char_class_type cc = m_ctraits.lookup_classname(m_pointer, m_pointer);
  171. ignore_unused_variable_warning(cc);
  172. string_type s3 = m_ctraits.lookup_collatename(m_pointer, m_pointer);
  173. ignore_unused_variable_warning(s3);
  174. bool b = m_ctraits.isctype(m_char, cc);
  175. ignore_unused_variable_warning(b);
  176. int v = m_ctraits.value(m_char, 16);
  177. ignore_unused_variable_warning(v);
  178. locale_type l(m_ctraits.getloc());
  179. m_traits.imbue(l);
  180. ignore_unused_variable_warning(l);
  181. }
  182. traits m_traits;
  183. const traits m_ctraits;
  184. const char_type* m_pointer;
  185. char_type m_char;
  186. private:
  187. RegexTraitsConcept& operator=(RegexTraitsConcept&);
  188. };
  189. //
  190. // helper class to compute what traits class a regular expression type is using:
  191. //
  192. template <class Regex>
  193. struct regex_traits_computer;
  194. template <class charT, class traits>
  195. struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
  196. {
  197. typedef traits type;
  198. };
  199. //
  200. // BaseRegexConcept does not test anything dependent on basic_string,
  201. // in case our charT does not have an associated char_traits:
  202. //
  203. template <class Regex>
  204. struct BaseRegexConcept
  205. {
  206. typedef typename Regex::value_type value_type;
  207. //typedef typename Regex::size_type size_type;
  208. typedef typename Regex::flag_type flag_type;
  209. typedef typename Regex::locale_type locale_type;
  210. typedef input_iterator_archetype<value_type> input_iterator_type;
  211. // derived test types:
  212. typedef const value_type* pointer_type;
  213. typedef bidirectional_iterator_archetype<value_type> BidiIterator;
  214. typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
  215. typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
  216. typedef output_iterator_archetype<value_type> OutIterator;
  217. typedef typename regex_traits_computer<Regex>::type traits_type;
  218. typedef global_regex_namespace::regex_iterator<BidiIterator, value_type, traits_type> regex_iterator_type;
  219. typedef global_regex_namespace::regex_token_iterator<BidiIterator, value_type, traits_type> regex_token_iterator_type;
  220. void global_constraints()
  221. {
  222. //
  223. // test non-template components:
  224. //
  225. function_requires<BitmaskConcept<global_regex_namespace::regex_constants::syntax_option_type> >();
  226. global_regex_namespace::regex_constants::syntax_option_type opts
  227. = global_regex_namespace::regex_constants::icase
  228. | global_regex_namespace::regex_constants::nosubs
  229. | global_regex_namespace::regex_constants::optimize
  230. | global_regex_namespace::regex_constants::collate
  231. | global_regex_namespace::regex_constants::ECMAScript
  232. | global_regex_namespace::regex_constants::basic
  233. | global_regex_namespace::regex_constants::extended
  234. | global_regex_namespace::regex_constants::awk
  235. | global_regex_namespace::regex_constants::grep
  236. | global_regex_namespace::regex_constants::egrep;
  237. ignore_unused_variable_warning(opts);
  238. function_requires<BitmaskConcept<global_regex_namespace::regex_constants::match_flag_type> >();
  239. global_regex_namespace::regex_constants::match_flag_type mopts
  240. = global_regex_namespace::regex_constants::match_default
  241. | global_regex_namespace::regex_constants::match_not_bol
  242. | global_regex_namespace::regex_constants::match_not_eol
  243. | global_regex_namespace::regex_constants::match_not_bow
  244. | global_regex_namespace::regex_constants::match_not_eow
  245. | global_regex_namespace::regex_constants::match_any
  246. | global_regex_namespace::regex_constants::match_not_null
  247. | global_regex_namespace::regex_constants::match_continuous
  248. | global_regex_namespace::regex_constants::match_prev_avail
  249. | global_regex_namespace::regex_constants::format_default
  250. | global_regex_namespace::regex_constants::format_sed
  251. | global_regex_namespace::regex_constants::format_no_copy
  252. | global_regex_namespace::regex_constants::format_first_only;
  253. ignore_unused_variable_warning(mopts);
  254. BOOST_STATIC_ASSERT((::boost::is_enum<global_regex_namespace::regex_constants::error_type>::value));
  255. global_regex_namespace::regex_constants::error_type e1 = global_regex_namespace::regex_constants::error_collate;
  256. ignore_unused_variable_warning(e1);
  257. e1 = global_regex_namespace::regex_constants::error_ctype;
  258. ignore_unused_variable_warning(e1);
  259. e1 = global_regex_namespace::regex_constants::error_escape;
  260. ignore_unused_variable_warning(e1);
  261. e1 = global_regex_namespace::regex_constants::error_backref;
  262. ignore_unused_variable_warning(e1);
  263. e1 = global_regex_namespace::regex_constants::error_brack;
  264. ignore_unused_variable_warning(e1);
  265. e1 = global_regex_namespace::regex_constants::error_paren;
  266. ignore_unused_variable_warning(e1);
  267. e1 = global_regex_namespace::regex_constants::error_brace;
  268. ignore_unused_variable_warning(e1);
  269. e1 = global_regex_namespace::regex_constants::error_badbrace;
  270. ignore_unused_variable_warning(e1);
  271. e1 = global_regex_namespace::regex_constants::error_range;
  272. ignore_unused_variable_warning(e1);
  273. e1 = global_regex_namespace::regex_constants::error_space;
  274. ignore_unused_variable_warning(e1);
  275. e1 = global_regex_namespace::regex_constants::error_badrepeat;
  276. ignore_unused_variable_warning(e1);
  277. e1 = global_regex_namespace::regex_constants::error_complexity;
  278. ignore_unused_variable_warning(e1);
  279. e1 = global_regex_namespace::regex_constants::error_stack;
  280. ignore_unused_variable_warning(e1);
  281. BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::runtime_error, global_regex_namespace::regex_error>::value ));
  282. const global_regex_namespace::regex_error except(e1);
  283. e1 = except.code();
  284. typedef typename Regex::value_type value_type;
  285. function_requires< RegexTraitsConcept<global_regex_namespace::regex_traits<char> > >();
  286. function_requires< BaseRegexConcept<global_regex_namespace::basic_regex<char> > >();
  287. }
  288. void constraints()
  289. {
  290. global_constraints();
  291. BOOST_STATIC_ASSERT((::boost::is_same< flag_type, global_regex_namespace::regex_constants::syntax_option_type>::value));
  292. flag_type opts
  293. = Regex::icase
  294. | Regex::nosubs
  295. | Regex::optimize
  296. | Regex::collate
  297. | Regex::ECMAScript
  298. | Regex::basic
  299. | Regex::extended
  300. | Regex::awk
  301. | Regex::grep
  302. | Regex::egrep;
  303. ignore_unused_variable_warning(opts);
  304. function_requires<DefaultConstructibleConcept<Regex> >();
  305. function_requires<CopyConstructibleConcept<Regex> >();
  306. // Regex constructors:
  307. Regex e1(m_pointer);
  308. ignore_unused_variable_warning(e1);
  309. Regex e2(m_pointer, m_flags);
  310. ignore_unused_variable_warning(e2);
  311. Regex e3(m_pointer, m_size, m_flags);
  312. ignore_unused_variable_warning(e3);
  313. Regex e4(in1, in2);
  314. ignore_unused_variable_warning(e4);
  315. Regex e5(in1, in2, m_flags);
  316. ignore_unused_variable_warning(e5);
  317. // assign etc:
  318. Regex e;
  319. e = m_pointer;
  320. e = e1;
  321. e.assign(e1);
  322. e.assign(m_pointer);
  323. e.assign(m_pointer, m_flags);
  324. e.assign(m_pointer, m_size, m_flags);
  325. e.assign(in1, in2);
  326. e.assign(in1, in2, m_flags);
  327. // access:
  328. const Regex ce;
  329. unsigned i = ce.mark_count();
  330. ignore_unused_variable_warning(i);
  331. m_flags = ce.flags();
  332. e.imbue(ce.getloc());
  333. e.swap(e1);
  334. global_regex_namespace::swap(e, e1);
  335. // sub_match:
  336. BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::pair<BidiIterator, BidiIterator>, sub_match_type>::value));
  337. typedef typename sub_match_type::value_type sub_value_type;
  338. typedef typename sub_match_type::difference_type sub_diff_type;
  339. typedef typename sub_match_type::iterator sub_iter_type;
  340. BOOST_STATIC_ASSERT((::boost::is_same<sub_value_type, value_type>::value));
  341. BOOST_STATIC_ASSERT((::boost::is_same<sub_iter_type, BidiIterator>::value));
  342. bool b = m_sub.matched;
  343. ignore_unused_variable_warning(b);
  344. BidiIterator bi = m_sub.first;
  345. ignore_unused_variable_warning(bi);
  346. bi = m_sub.second;
  347. ignore_unused_variable_warning(bi);
  348. sub_diff_type diff = m_sub.length();
  349. ignore_unused_variable_warning(diff);
  350. // match_results tests:
  351. typedef typename match_results_type::value_type mr_value_type;
  352. typedef typename match_results_type::const_reference mr_const_reference;
  353. typedef typename match_results_type::reference mr_reference;
  354. typedef typename match_results_type::const_iterator mr_const_iterator;
  355. typedef typename match_results_type::iterator mr_iterator;
  356. typedef typename match_results_type::difference_type mr_difference_type;
  357. typedef typename match_results_type::size_type mr_size_type;
  358. typedef typename match_results_type::allocator_type mr_allocator_type;
  359. typedef typename match_results_type::char_type mr_char_type;
  360. typedef typename match_results_type::string_type mr_string_type;
  361. match_results_type m1;
  362. mr_allocator_type at;
  363. match_results_type m2(at);
  364. match_results_type m3(m1);
  365. m1 = m2;
  366. int ival = 0;
  367. mr_size_type mrs = m_cresults.size();
  368. ignore_unused_variable_warning(mrs);
  369. mrs = m_cresults.max_size();
  370. ignore_unused_variable_warning(mrs);
  371. b = m_cresults.empty();
  372. ignore_unused_variable_warning(b);
  373. mr_difference_type mrd = m_cresults.length();
  374. ignore_unused_variable_warning(mrd);
  375. mrd = m_cresults.length(ival);
  376. ignore_unused_variable_warning(mrd);
  377. mrd = m_cresults.position();
  378. ignore_unused_variable_warning(mrd);
  379. mrd = m_cresults.position(mrs);
  380. ignore_unused_variable_warning(mrd);
  381. mr_const_reference mrcr = m_cresults[ival];
  382. ignore_unused_variable_warning(mrcr);
  383. mr_const_reference mrcr2 = m_cresults.prefix();
  384. ignore_unused_variable_warning(mrcr2);
  385. mr_const_reference mrcr3 = m_cresults.suffix();
  386. ignore_unused_variable_warning(mrcr3);
  387. mr_const_iterator mrci = m_cresults.begin();
  388. ignore_unused_variable_warning(mrci);
  389. mrci = m_cresults.end();
  390. ignore_unused_variable_warning(mrci);
  391. mr_allocator_type at2 = m_cresults.get_allocator();
  392. m_results.swap(m_results);
  393. global_regex_namespace::swap(m_results, m_results);
  394. // regex_match:
  395. b = global_regex_namespace::regex_match(m_in, m_in, m_results, e);
  396. ignore_unused_variable_warning(b);
  397. b = global_regex_namespace::regex_match(m_in, m_in, m_results, e, m_mft);
  398. ignore_unused_variable_warning(b);
  399. b = global_regex_namespace::regex_match(m_in, m_in, e);
  400. ignore_unused_variable_warning(b);
  401. b = global_regex_namespace::regex_match(m_in, m_in, e, m_mft);
  402. ignore_unused_variable_warning(b);
  403. b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e);
  404. ignore_unused_variable_warning(b);
  405. b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e, m_mft);
  406. ignore_unused_variable_warning(b);
  407. b = global_regex_namespace::regex_match(m_pointer, e);
  408. ignore_unused_variable_warning(b);
  409. b = global_regex_namespace::regex_match(m_pointer, e, m_mft);
  410. ignore_unused_variable_warning(b);
  411. // regex_search:
  412. b = global_regex_namespace::regex_search(m_in, m_in, m_results, e);
  413. ignore_unused_variable_warning(b);
  414. b = global_regex_namespace::regex_search(m_in, m_in, m_results, e, m_mft);
  415. ignore_unused_variable_warning(b);
  416. b = global_regex_namespace::regex_search(m_in, m_in, e);
  417. ignore_unused_variable_warning(b);
  418. b = global_regex_namespace::regex_search(m_in, m_in, e, m_mft);
  419. ignore_unused_variable_warning(b);
  420. b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e);
  421. ignore_unused_variable_warning(b);
  422. b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e, m_mft);
  423. ignore_unused_variable_warning(b);
  424. b = global_regex_namespace::regex_search(m_pointer, e);
  425. ignore_unused_variable_warning(b);
  426. b = global_regex_namespace::regex_search(m_pointer, e, m_mft);
  427. ignore_unused_variable_warning(b);
  428. // regex_iterator:
  429. typedef typename regex_iterator_type::regex_type rit_regex_type;
  430. typedef typename regex_iterator_type::value_type rit_value_type;
  431. typedef typename regex_iterator_type::difference_type rit_difference_type;
  432. typedef typename regex_iterator_type::pointer rit_pointer;
  433. typedef typename regex_iterator_type::reference rit_reference;
  434. typedef typename regex_iterator_type::iterator_category rit_iterator_category;
  435. BOOST_STATIC_ASSERT((::boost::is_same<rit_regex_type, Regex>::value));
  436. BOOST_STATIC_ASSERT((::boost::is_same<rit_value_type, match_results_type>::value));
  437. BOOST_STATIC_ASSERT((::boost::is_same<rit_difference_type, std::ptrdiff_t>::value));
  438. BOOST_STATIC_ASSERT((::boost::is_same<rit_pointer, const match_results_type*>::value));
  439. BOOST_STATIC_ASSERT((::boost::is_same<rit_reference, const match_results_type&>::value));
  440. BOOST_STATIC_ASSERT((::boost::is_convertible<rit_iterator_category*, std::forward_iterator_tag*>::value));
  441. // this takes care of most of the checks needed:
  442. function_requires<ForwardIteratorConcept<regex_iterator_type> >();
  443. regex_iterator_type iter1(m_in, m_in, e);
  444. ignore_unused_variable_warning(iter1);
  445. regex_iterator_type iter2(m_in, m_in, e, m_mft);
  446. ignore_unused_variable_warning(iter2);
  447. // regex_token_iterator:
  448. typedef typename regex_token_iterator_type::regex_type rtit_regex_type;
  449. typedef typename regex_token_iterator_type::value_type rtit_value_type;
  450. typedef typename regex_token_iterator_type::difference_type rtit_difference_type;
  451. typedef typename regex_token_iterator_type::pointer rtit_pointer;
  452. typedef typename regex_token_iterator_type::reference rtit_reference;
  453. typedef typename regex_token_iterator_type::iterator_category rtit_iterator_category;
  454. BOOST_STATIC_ASSERT((::boost::is_same<rtit_regex_type, Regex>::value));
  455. BOOST_STATIC_ASSERT((::boost::is_same<rtit_value_type, sub_match_type>::value));
  456. BOOST_STATIC_ASSERT((::boost::is_same<rtit_difference_type, std::ptrdiff_t>::value));
  457. BOOST_STATIC_ASSERT((::boost::is_same<rtit_pointer, const sub_match_type*>::value));
  458. BOOST_STATIC_ASSERT((::boost::is_same<rtit_reference, const sub_match_type&>::value));
  459. BOOST_STATIC_ASSERT((::boost::is_convertible<rtit_iterator_category*, std::forward_iterator_tag*>::value));
  460. // this takes care of most of the checks needed:
  461. function_requires<ForwardIteratorConcept<regex_token_iterator_type> >();
  462. regex_token_iterator_type ti1(m_in, m_in, e);
  463. ignore_unused_variable_warning(ti1);
  464. regex_token_iterator_type ti2(m_in, m_in, e, 0);
  465. ignore_unused_variable_warning(ti2);
  466. regex_token_iterator_type ti3(m_in, m_in, e, 0, m_mft);
  467. ignore_unused_variable_warning(ti3);
  468. std::vector<int> subs;
  469. regex_token_iterator_type ti4(m_in, m_in, e, subs);
  470. ignore_unused_variable_warning(ti4);
  471. regex_token_iterator_type ti5(m_in, m_in, e, subs, m_mft);
  472. ignore_unused_variable_warning(ti5);
  473. static const int i_array[3] = { 1, 2, 3, };
  474. regex_token_iterator_type ti6(m_in, m_in, e, i_array);
  475. ignore_unused_variable_warning(ti6);
  476. regex_token_iterator_type ti7(m_in, m_in, e, i_array, m_mft);
  477. ignore_unused_variable_warning(ti7);
  478. }
  479. pointer_type m_pointer;
  480. flag_type m_flags;
  481. std::size_t m_size;
  482. input_iterator_type in1, in2;
  483. const sub_match_type m_sub;
  484. const value_type m_char;
  485. match_results_type m_results;
  486. const match_results_type m_cresults;
  487. OutIterator m_out;
  488. BidiIterator m_in;
  489. global_regex_namespace::regex_constants::match_flag_type m_mft;
  490. global_regex_namespace::match_results<pointer_type> m_pmatch;
  491. BaseRegexConcept();
  492. BaseRegexConcept(const BaseRegexConcept&);
  493. BaseRegexConcept& operator=(const BaseRegexConcept&);
  494. };
  495. //
  496. // RegexConcept:
  497. // Test every interface in the std:
  498. //
  499. template <class Regex>
  500. struct RegexConcept
  501. {
  502. typedef typename Regex::value_type value_type;
  503. //typedef typename Regex::size_type size_type;
  504. typedef typename Regex::flag_type flag_type;
  505. typedef typename Regex::locale_type locale_type;
  506. // derived test types:
  507. typedef const value_type* pointer_type;
  508. typedef std::basic_string<value_type> string_type;
  509. typedef boost::bidirectional_iterator_archetype<value_type> BidiIterator;
  510. typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
  511. typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
  512. typedef output_iterator_archetype<value_type> OutIterator;
  513. void constraints()
  514. {
  515. function_requires<BaseRegexConcept<Regex> >();
  516. // string based construct:
  517. Regex e1(m_string);
  518. ignore_unused_variable_warning(e1);
  519. Regex e2(m_string, m_flags);
  520. ignore_unused_variable_warning(e2);
  521. // assign etc:
  522. Regex e;
  523. e = m_string;
  524. e.assign(m_string);
  525. e.assign(m_string, m_flags);
  526. // sub_match:
  527. string_type s(m_sub);
  528. ignore_unused_variable_warning(s);
  529. s = m_sub.str();
  530. ignore_unused_variable_warning(s);
  531. int i = m_sub.compare(m_string);
  532. ignore_unused_variable_warning(i);
  533. int i2 = m_sub.compare(m_sub);
  534. ignore_unused_variable_warning(i2);
  535. i2 = m_sub.compare(m_pointer);
  536. ignore_unused_variable_warning(i2);
  537. bool b = m_sub == m_sub;
  538. ignore_unused_variable_warning(b);
  539. b = m_sub != m_sub;
  540. ignore_unused_variable_warning(b);
  541. b = m_sub <= m_sub;
  542. ignore_unused_variable_warning(b);
  543. b = m_sub <= m_sub;
  544. ignore_unused_variable_warning(b);
  545. b = m_sub > m_sub;
  546. ignore_unused_variable_warning(b);
  547. b = m_sub >= m_sub;
  548. ignore_unused_variable_warning(b);
  549. b = m_sub == m_pointer;
  550. ignore_unused_variable_warning(b);
  551. b = m_sub != m_pointer;
  552. ignore_unused_variable_warning(b);
  553. b = m_sub <= m_pointer;
  554. ignore_unused_variable_warning(b);
  555. b = m_sub <= m_pointer;
  556. ignore_unused_variable_warning(b);
  557. b = m_sub > m_pointer;
  558. ignore_unused_variable_warning(b);
  559. b = m_sub >= m_pointer;
  560. ignore_unused_variable_warning(b);
  561. b = m_pointer == m_sub;
  562. ignore_unused_variable_warning(b);
  563. b = m_pointer != m_sub;
  564. ignore_unused_variable_warning(b);
  565. b = m_pointer <= m_sub;
  566. ignore_unused_variable_warning(b);
  567. b = m_pointer <= m_sub;
  568. ignore_unused_variable_warning(b);
  569. b = m_pointer > m_sub;
  570. ignore_unused_variable_warning(b);
  571. b = m_pointer >= m_sub;
  572. ignore_unused_variable_warning(b);
  573. b = m_sub == m_char;
  574. ignore_unused_variable_warning(b);
  575. b = m_sub != m_char;
  576. ignore_unused_variable_warning(b);
  577. b = m_sub <= m_char;
  578. ignore_unused_variable_warning(b);
  579. b = m_sub <= m_char;
  580. ignore_unused_variable_warning(b);
  581. b = m_sub > m_char;
  582. ignore_unused_variable_warning(b);
  583. b = m_sub >= m_char;
  584. ignore_unused_variable_warning(b);
  585. b = m_char == m_sub;
  586. ignore_unused_variable_warning(b);
  587. b = m_char != m_sub;
  588. ignore_unused_variable_warning(b);
  589. b = m_char <= m_sub;
  590. ignore_unused_variable_warning(b);
  591. b = m_char <= m_sub;
  592. ignore_unused_variable_warning(b);
  593. b = m_char > m_sub;
  594. ignore_unused_variable_warning(b);
  595. b = m_char >= m_sub;
  596. ignore_unused_variable_warning(b);
  597. b = m_sub == m_string;
  598. ignore_unused_variable_warning(b);
  599. b = m_sub != m_string;
  600. ignore_unused_variable_warning(b);
  601. b = m_sub <= m_string;
  602. ignore_unused_variable_warning(b);
  603. b = m_sub <= m_string;
  604. ignore_unused_variable_warning(b);
  605. b = m_sub > m_string;
  606. ignore_unused_variable_warning(b);
  607. b = m_sub >= m_string;
  608. ignore_unused_variable_warning(b);
  609. b = m_string == m_sub;
  610. ignore_unused_variable_warning(b);
  611. b = m_string != m_sub;
  612. ignore_unused_variable_warning(b);
  613. b = m_string <= m_sub;
  614. ignore_unused_variable_warning(b);
  615. b = m_string <= m_sub;
  616. ignore_unused_variable_warning(b);
  617. b = m_string > m_sub;
  618. ignore_unused_variable_warning(b);
  619. b = m_string >= m_sub;
  620. ignore_unused_variable_warning(b);
  621. // match results:
  622. m_string = m_results.str();
  623. ignore_unused_variable_warning(m_string);
  624. m_string = m_results.str(0);
  625. ignore_unused_variable_warning(m_string);
  626. m_out = m_cresults.format(m_out, m_string);
  627. m_out = m_cresults.format(m_out, m_string, m_mft);
  628. m_string = m_cresults.format(m_string);
  629. ignore_unused_variable_warning(m_string);
  630. m_string = m_cresults.format(m_string, m_mft);
  631. ignore_unused_variable_warning(m_string);
  632. // regex_match:
  633. b = global_regex_namespace::regex_match(m_string, m_smatch, e);
  634. ignore_unused_variable_warning(b);
  635. b = global_regex_namespace::regex_match(m_string, m_smatch, e, m_mft);
  636. ignore_unused_variable_warning(b);
  637. b = global_regex_namespace::regex_match(m_string, e);
  638. ignore_unused_variable_warning(b);
  639. b = global_regex_namespace::regex_match(m_string, e, m_mft);
  640. ignore_unused_variable_warning(b);
  641. // regex_search:
  642. b = global_regex_namespace::regex_search(m_string, m_smatch, e);
  643. ignore_unused_variable_warning(b);
  644. b = global_regex_namespace::regex_search(m_string, m_smatch, e, m_mft);
  645. ignore_unused_variable_warning(b);
  646. b = global_regex_namespace::regex_search(m_string, e);
  647. ignore_unused_variable_warning(b);
  648. b = global_regex_namespace::regex_search(m_string, e, m_mft);
  649. ignore_unused_variable_warning(b);
  650. // regex_replace:
  651. m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string, m_mft);
  652. m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string);
  653. m_string = global_regex_namespace::regex_replace(m_string, e, m_string, m_mft);
  654. ignore_unused_variable_warning(m_string);
  655. m_string = global_regex_namespace::regex_replace(m_string, e, m_string);
  656. ignore_unused_variable_warning(m_string);
  657. }
  658. flag_type m_flags;
  659. string_type m_string;
  660. const sub_match_type m_sub;
  661. match_results_type m_results;
  662. pointer_type m_pointer;
  663. value_type m_char;
  664. const match_results_type m_cresults;
  665. OutIterator m_out;
  666. BidiIterator m_in;
  667. global_regex_namespace::regex_constants::match_flag_type m_mft;
  668. global_regex_namespace::match_results<typename string_type::const_iterator> m_smatch;
  669. RegexConcept();
  670. RegexConcept(const RegexConcept&);
  671. RegexConcept& operator=(const RegexConcept&);
  672. };
  673. #ifndef BOOST_REGEX_TEST_STD
  674. //
  675. // BoostRegexConcept:
  676. // Test every interface in the Boost implementation:
  677. //
  678. template <class Regex>
  679. struct BoostRegexConcept
  680. {
  681. typedef typename Regex::value_type value_type;
  682. typedef typename Regex::size_type size_type;
  683. typedef typename Regex::flag_type flag_type;
  684. typedef typename Regex::locale_type locale_type;
  685. // derived test types:
  686. typedef const value_type* pointer_type;
  687. typedef std::basic_string<value_type> string_type;
  688. typedef typename Regex::const_iterator const_iterator;
  689. typedef bidirectional_iterator_archetype<value_type> BidiIterator;
  690. typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
  691. typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
  692. void constraints()
  693. {
  694. global_regex_namespace::regex_constants::match_flag_type mopts
  695. = global_regex_namespace::regex_constants::match_default
  696. | global_regex_namespace::regex_constants::match_not_bol
  697. | global_regex_namespace::regex_constants::match_not_eol
  698. | global_regex_namespace::regex_constants::match_not_bow
  699. | global_regex_namespace::regex_constants::match_not_eow
  700. | global_regex_namespace::regex_constants::match_any
  701. | global_regex_namespace::regex_constants::match_not_null
  702. | global_regex_namespace::regex_constants::match_continuous
  703. | global_regex_namespace::regex_constants::match_partial
  704. | global_regex_namespace::regex_constants::match_prev_avail
  705. | global_regex_namespace::regex_constants::format_default
  706. | global_regex_namespace::regex_constants::format_sed
  707. | global_regex_namespace::regex_constants::format_perl
  708. | global_regex_namespace::regex_constants::format_no_copy
  709. | global_regex_namespace::regex_constants::format_first_only;
  710. (void)mopts;
  711. function_requires<RegexConcept<Regex> >();
  712. const global_regex_namespace::regex_error except(global_regex_namespace::regex_constants::error_collate);
  713. std::ptrdiff_t pt = except.position();
  714. ignore_unused_variable_warning(pt);
  715. const Regex ce, ce2;
  716. #ifndef BOOST_NO_STD_LOCALE
  717. m_stream << ce;
  718. #endif
  719. unsigned i = ce.error_code();
  720. ignore_unused_variable_warning(i);
  721. pointer_type p = ce.expression();
  722. ignore_unused_variable_warning(p);
  723. int i2 = ce.compare(ce2);
  724. ignore_unused_variable_warning(i2);
  725. bool b = ce == ce2;
  726. ignore_unused_variable_warning(b);
  727. b = ce.empty();
  728. ignore_unused_variable_warning(b);
  729. b = ce != ce2;
  730. ignore_unused_variable_warning(b);
  731. b = ce < ce2;
  732. ignore_unused_variable_warning(b);
  733. b = ce > ce2;
  734. ignore_unused_variable_warning(b);
  735. b = ce <= ce2;
  736. ignore_unused_variable_warning(b);
  737. b = ce >= ce2;
  738. ignore_unused_variable_warning(b);
  739. i = ce.status();
  740. ignore_unused_variable_warning(i);
  741. size_type s = ce.max_size();
  742. ignore_unused_variable_warning(s);
  743. s = ce.size();
  744. ignore_unused_variable_warning(s);
  745. const_iterator pi = ce.begin();
  746. ignore_unused_variable_warning(pi);
  747. pi = ce.end();
  748. ignore_unused_variable_warning(pi);
  749. string_type s2 = ce.str();
  750. ignore_unused_variable_warning(s2);
  751. m_string = m_sub + m_sub;
  752. ignore_unused_variable_warning(m_string);
  753. m_string = m_sub + m_pointer;
  754. ignore_unused_variable_warning(m_string);
  755. m_string = m_pointer + m_sub;
  756. ignore_unused_variable_warning(m_string);
  757. m_string = m_sub + m_string;
  758. ignore_unused_variable_warning(m_string);
  759. m_string = m_string + m_sub;
  760. ignore_unused_variable_warning(m_string);
  761. m_string = m_sub + m_char;
  762. ignore_unused_variable_warning(m_string);
  763. m_string = m_char + m_sub;
  764. ignore_unused_variable_warning(m_string);
  765. // Named sub-expressions:
  766. m_sub = m_cresults[&m_char];
  767. ignore_unused_variable_warning(m_sub);
  768. m_sub = m_cresults[m_string];
  769. ignore_unused_variable_warning(m_sub);
  770. m_sub = m_cresults[""];
  771. ignore_unused_variable_warning(m_sub);
  772. m_sub = m_cresults[std::string("")];
  773. ignore_unused_variable_warning(m_sub);
  774. m_string = m_cresults.str(&m_char);
  775. ignore_unused_variable_warning(m_string);
  776. m_string = m_cresults.str(m_string);
  777. ignore_unused_variable_warning(m_string);
  778. m_string = m_cresults.str("");
  779. ignore_unused_variable_warning(m_string);
  780. m_string = m_cresults.str(std::string(""));
  781. ignore_unused_variable_warning(m_string);
  782. typename match_results_type::difference_type diff;
  783. diff = m_cresults.length(&m_char);
  784. ignore_unused_variable_warning(diff);
  785. diff = m_cresults.length(m_string);
  786. ignore_unused_variable_warning(diff);
  787. diff = m_cresults.length("");
  788. ignore_unused_variable_warning(diff);
  789. diff = m_cresults.length(std::string(""));
  790. ignore_unused_variable_warning(diff);
  791. diff = m_cresults.position(&m_char);
  792. ignore_unused_variable_warning(diff);
  793. diff = m_cresults.position(m_string);
  794. ignore_unused_variable_warning(diff);
  795. diff = m_cresults.position("");
  796. ignore_unused_variable_warning(diff);
  797. diff = m_cresults.position(std::string(""));
  798. ignore_unused_variable_warning(diff);
  799. #ifndef BOOST_NO_STD_LOCALE
  800. m_stream << m_sub;
  801. m_stream << m_cresults;
  802. #endif
  803. }
  804. std::basic_ostream<value_type> m_stream;
  805. sub_match_type m_sub;
  806. pointer_type m_pointer;
  807. string_type m_string;
  808. const value_type m_char;
  809. match_results_type m_results;
  810. const match_results_type m_cresults;
  811. BoostRegexConcept();
  812. BoostRegexConcept(const BoostRegexConcept&);
  813. BoostRegexConcept& operator=(const BoostRegexConcept&);
  814. };
  815. #endif // BOOST_REGEX_TEST_STD
  816. }
  817. #endif