Compare commits

..
Author SHA1 Message Date
Thomas Witt 6589266894 MSVC fixes.
[SVN r1408]
2003-07-07 09:02:58 +00:00
Thomas Witt 9ee9f64087 Fixed crt issue. Make transform_iterator work with function pointers.
[SVN r1404]
2003-07-02 21:46:51 +00:00
Thomas Witt 2d4965d72b Added traversal category checking to core interface implementation.
[SVN r1399]
2003-07-02 20:04:26 +00:00
Thomas Witt 21141ef401 Simplyfied make_transform_iterator.
[SVN r1398]
2003-07-01 21:30:03 +00:00
Thomas Witt 3c0c2b8513 Improved portability.
[SVN r1397]
2003-07-01 18:47:43 +00:00
Thomas Witt 405e6ba468 Added function ptr support to make_transform_iterator.
[SVN r1396]
2003-06-30 22:08:20 +00:00
Hartmut Kaiser 4258cac90d Added new file to iterator adaptors library.
[SVN r1361]
2003-06-13 19:42:53 +00:00
Roland Richter fd37912e30 Rewrite to work with new iterator_adaptors.
[SVN r1360]
2003-06-13 08:15:30 +00:00
Dave Abrahams b49d0fe184 We no longer inherit from boost::iterator (thus, std::iterator) on
platforms where it's not neccessary as a workaround, thus enabling the
EBO for a large class of cases

renamed iterator_facade_base -> iterator_facade_types

fixed indentation of PP directives

worked around an MSVC6 bug which shows up with STLPort debug iterators.


[SVN r1297]
2003-06-01 15:23:27 +00:00
Dave Abrahams 65fe9a13e5 iterator_archetypes.hpp, iterator_concepts.hpp -
incrementable_iterator_tag -> incrementable_traversal_tag
   single_pass_iterator_tag -> single_pass_traversal_tag

iterator_categories.hpp -

   added writability stripping to new_category_to_access for iterator

   adaptors based on iterators with new-style tags

   ReturnTag->AccessTag / returns->access

   Fixed a bug which would rule out user-defined access/traversal tags
   - we weren't accounting for tag convertibility without public
   inheritance.

iterator_facade.hpp -

   Workaround for a Borland const-dropping bug.

detail/categories.hpp -

   fixed is_tag so it doesn't rely on inheritance for detection

concept_tests.cpp -

   added new tests, use static_assert_same for better feedback on failure

iterator_adaptor_test.cpp

   workarounds for CWPro7, use static_assert_same for better feedback on failure
   wiped out #if 0 section

unit_tests.cpp -

   factored static_assert_same into a separate file


[SVN r1296]
2003-05-31 02:44:39 +00:00
Thomas Witt e2b58d1eea Added test for constant iterator idiom.
[SVN r1295]
2003-05-30 14:57:41 +00:00
Dave Abrahams 021e048e06 Add more tests
[SVN r1294]
2003-05-30 03:08:22 +00:00
Dave Abrahams 1a58125e62 Apply Howard's inheritance fixes
[SVN r1293]
2003-05-30 03:07:39 +00:00
Dave Abrahams 2e18357672 Improved comments.
[SVN r1292]
2003-05-29 22:33:23 +00:00
Dave Abrahams 1236797033 Fixed a bug in reference type and category computation.
Improved comments.


[SVN r1291]
2003-05-29 22:33:10 +00:00
Dave Abrahams 5076d782af Removed needless diagnostic
[SVN r1290]
2003-05-29 22:31:56 +00:00
Thomas Witt 9ba316e3aa Added test to detect category problem.
[SVN r1289]
2003-05-29 17:43:16 +00:00
Thomas Witt 0bada0a914 Made filter_iterator bidirectional.
[SVN r1288]
2003-05-29 17:11:11 +00:00
Thomas Witt 8da33f502f Readded use_default support.
[SVN r1287]
2003-05-29 17:10:33 +00:00
Jeremy Siek 438334584c read/write to read/swap as per Dave's suggestion
[SVN r1258]
2003-05-12 02:01:59 +00:00
Jeremy Siek 67950e82fb updated with Howard's improvements
[SVN r1257]
2003-05-12 01:47:48 +00:00
Jeremy Siek e30ea3ad7e added a comment about indirect iterator and smart pointers
[SVN r1251]
2003-04-28 21:18:57 +00:00
Dave Abrahams a529a82a66 kill redundancy; final edits
[SVN r1250]
2003-04-28 15:02:42 +00:00
Dave Abrahams e2b3a260d5 All workarounds complete! Also some cleanups
[SVN r1249]
2003-04-28 13:54:59 +00:00
Jeremy Siek 70e2b4f922 removed super_t
improvements to counting_iterator
other small edits


[SVN r1248]
2003-04-28 13:40:53 +00:00
Dave Abrahams 3c4a6c429c Some workarounds; more to do.
[SVN r1247]
2003-04-28 11:36:22 +00:00
Thomas Witt a44a4e6b0c Changed iterator_facade to new interface.
Added new semantics for iterator_adaptor
iterator_category.


[SVN r1246]
2003-04-28 09:42:42 +00:00
Jeremy Siek 19b62f22a9 wrote up the spec for transform_iterator
spell checked
removed Pointer


[SVN r1238]
2003-04-28 05:56:22 +00:00
Dave Abrahams 357f2c5c23 Some workarounds; more to do.
[SVN r1237]
2003-04-28 05:22:04 +00:00
Jeremy Siek 62c2eb051a added specs for core interface functions of the iterator_adaptor, and
updated to match recent changes in the code
some minor edits to new iter concepts, including defualt constructor
  in forward trav. iter.


[SVN r1236]
2003-04-28 04:56:27 +00:00
Dave Abrahams a57faf5a6e small tweaks
[SVN r1235]
2003-04-28 03:17:36 +00:00
Thomas Witt d4d3f1d448 Removed Pointer template argument.
Made facade work with new categories only.
Added old->new category conversion logic to adaptor.


[SVN r1234]
2003-04-28 02:50:46 +00:00
Thomas Witt b2ec28ec7d Relaxed test, was to strict.
[SVN r1233]
2003-04-28 02:49:09 +00:00
Thomas Witt 2ffbd73c02 Added first archetype test.
[SVN r1232]
2003-04-28 02:48:16 +00:00
Thomas Witt a27bef1b9f New archetypes
[SVN r1231]
2003-04-28 02:46:11 +00:00
Thomas Witt fc11987746 Fixed base type of iterator_tag to be corresponding std tag.
[SVN r1230]
2003-04-28 02:45:45 +00:00
Thomas Witt 3f5ac1b1a1 Fixed typo.
[SVN r1229]
2003-04-28 02:44:37 +00:00
Jeremy Siek 9189d5bd60 checking in what I've got so far
[SVN r1228]
2003-04-28 01:44:05 +00:00
Jeremy Siek 39342de58c made some progress on the special iterator adaptors
[SVN r1227]
2003-04-27 22:07:47 +00:00
Dave Abrahams c72ce2ae74 Many edits
[SVN r1226]
2003-04-27 19:31:56 +00:00
Dave Abrahams a83891fb94 Add link to issue 96
Add appropriate keys for the tables.
Kill meaningless "set of value types"
Fix random traversal interaction with a[n]


[SVN r1225]
2003-04-27 16:52:54 +00:00
Dave Abrahams 408bb7125f More updates
[SVN r1222]
2003-04-27 14:58:45 +00:00
Dave Abrahams a4c3f95501 more privacy
[SVN r1219]
2003-04-27 10:42:47 +00:00
Jeremy Siek 6e038bca05 removed counting_iterator paragraph
added a reply to a comment


[SVN r1216]
2003-04-27 02:52:33 +00:00
Jeremy Siek bc3d6b7c40 couple edits
[SVN r1215]
2003-04-27 00:42:55 +00:00
Jeremy Siek 2bb60050ac added some more specs
[SVN r1214]
2003-04-27 00:40:58 +00:00
Dave Abrahams af92b555d3 more edits
[SVN r1213]
2003-04-27 00:20:50 +00:00
Thomas Witt 73030b3ac8 Adjusted to new category names.
[SVN r1210]
2003-04-26 19:06:12 +00:00
Thomas Witt 849f351a27 Updated to current proposal.
[SVN r1209]
2003-04-26 19:04:09 +00:00
Thomas Witt 2f75219ca3 Adapted to iterator categories proposal.
[SVN r1208]
2003-04-26 19:02:12 +00:00
Dave Abrahams b15439a2a4 edits
[SVN r1206]
2003-04-26 17:59:56 +00:00
Dave Abrahams ee71d493b6 Made core interface private in iterator_adaptor, added base_reference() for Derived classes.
[SVN r1200]
2003-04-26 15:32:50 +00:00
Thomas Witt c9dac5c7fb Added projection support.
[SVN r1199]
2003-04-26 13:35:34 +00:00
Thomas Witt de057da47e Added projection support.
[SVN r1198]
2003-04-25 23:40:15 +00:00
Thomas Witt a56326e65c Removed obsolete defaults.
Fixed typo in comment.


[SVN r1197]
2003-04-25 23:39:44 +00:00
Jeremy Siek c2b5896879 a little more progress
[SVN r1196]
2003-04-25 23:03:25 +00:00
Jeremy Siek 3a034f6fe8 not really done, just using cvs to transfer files to my laptop
[SVN r1195]
2003-04-25 21:09:43 +00:00
Jeremy Siek 20eeff2372 blah
[SVN r1187]
2003-04-25 17:10:22 +00:00
Thomas Witt 46daf8053b More rationale.
[SVN r1186]
2003-04-25 15:41:34 +00:00
Dave Abrahams 1ab474b853 Bug fix and associated unit tests
[SVN r1185]
2003-04-25 15:18:49 +00:00
Dave Abrahams 3c78ef32c3 edits and commentary
[SVN r1184]
2003-04-25 15:17:59 +00:00
Dave Abrahams 4bc2915135 edits and commentary
[SVN r1183]
2003-04-25 14:39:47 +00:00
Jeremy Siek 4126ea29ed fixed lib.iterator.synopsis
[SVN r1182]
2003-04-25 13:35:32 +00:00
Jeremy Siek 1397e144c1 added a bunch for the specialized adaptors,
also filled out the facade and adaptor sections


[SVN r1181]
2003-04-25 04:51:32 +00:00
Jeremy Siek 80b70a675d some minor edits
[SVN r1180]
2003-04-25 02:29:28 +00:00
Dave Abrahams aca64eb5b4 Started on standard text
[SVN r1179]
2003-04-24 21:03:15 +00:00
Jeremy Siek d233fbef27 added paper number
[SVN r1172]
2003-04-23 18:32:11 +00:00
Dave Abrahams c08669e6e4 cleaned up language a bit
[SVN r1171]
2003-04-23 00:35:43 +00:00
Thomas Witt c47566a424 Added design rationale for interoperability and iterator_core_access
[SVN r1170]
2003-04-22 20:32:51 +00:00
Dave Abrahams cc8157a4e6 Some Updates
[SVN r1167]
2003-04-20 10:26:35 +00:00
Dave Abrahams 0f4cbb126b Some Updates
[SVN r1166]
2003-04-20 02:45:23 +00:00
Dave Abrahams 9a02b10067 rationalize config
[SVN r1165]
2003-04-20 02:40:43 +00:00
Jeremy Siek 725bef482b made a little progress, rewrote a bunch
[SVN r1164]
2003-04-19 23:47:51 +00:00
Dave Abrahams c3d067d4c1 *** empty log message ***
[SVN r1157]
2003-04-17 16:14:16 +00:00
Jeremy Siek a42fd350ff some progress
[SVN r1146]
2003-04-13 15:34:51 +00:00
Jeremy Siek 444a2a1e86 added pointer to old paper
[SVN r1145]
2003-04-10 15:05:00 +00:00
Jeremy Siek 163e5fbc30 small change
[SVN r1144]
2003-04-10 14:27:56 +00:00
Dave Abrahams f17e61f0ca initial commit
[SVN r1143]
2003-04-10 14:19:15 +00:00
Dave Abrahams b00ea4eeef BUG FIX
[SVN r1142]
2003-04-10 14:04:20 +00:00
Dave Abrahams aa0a32aa33 fixes and cleanups
[SVN r1141]
2003-04-10 13:40:42 +00:00
Jeremy Siek c1e5d7e331 new files
[SVN r1140]
2003-04-10 12:44:20 +00:00
Dave Abrahams be0b65c447 More fun with iterator adaptors
[SVN r1139]
2003-04-09 16:14:07 +00:00
Dave Abrahams a846fe50d2 Many changes from Oxford
[SVN r1137]
2003-04-09 11:51:08 +00:00
Dave Abrahams 02c16f50a2 fixes for CWPro7
[SVN r1080]
2003-03-04 00:55:40 +00:00
Dave Abrahams 0d20b5fa94 snip #if 0'd code
[SVN r1065]
2003-02-28 16:47:19 +00:00
Dave Abrahams 7706a8fffb cleanups, including endline-layout
[SVN r1064]
2003-02-28 16:45:20 +00:00
Dave Abrahams 060f554fd9 Remove nasty bool cast
[SVN r1063]
2003-02-28 16:25:16 +00:00
Dave Abrahams 4ebfc5b0a2 cleanups
[SVN r1061]
2003-02-28 05:44:22 +00:00
Dave Abrahams 5f522787ca updates for MPL renaming; restore some portability.
[SVN r1059]
2003-02-28 01:27:15 +00:00
Thomas Witt 2d6d02dddf Split iterator_adaptors.hpp in multiple headers.
[SVN r1040]
2003-02-23 21:12:51 +00:00
Thomas Witt 78a01b30bc Added input_iterator support to filter_iterator.
[SVN r882]
2003-01-28 07:59:40 +00:00
Thomas Witt 4e63c5e8dc Added iterator_traits_adaptor.
Implemented minimum_category.
Removed base class injection facilities.


[SVN r879]
2003-01-27 20:41:09 +00:00
Jeremy Siek 7818686c94 did some updating to match the current implementation
[SVN r866]
2003-01-19 22:02:19 +00:00
Dave Abrahams ab750320d3 Repair VC7.1 is_convertible checks
[SVN r858]
2003-01-14 23:22:52 +00:00
Dave Abrahams 30a6b03a93 Clear out flotsam
[SVN r854]
2003-01-13 21:20:37 +00:00
Dave Abrahams 9aece673d9 Fix Borland problems constructor overload disabling.
Restore all interoperable_fail tests which got broken along the way


[SVN r853]
2003-01-13 20:28:27 +00:00
Dave Abrahams 05afa8467c Pass traits around instead of individual associated types.
[SVN r852]
2003-01-13 16:50:48 +00:00
Dave Abrahams dd9e6c3f57 tweak condition for workarounds
[SVN r851]
2003-01-13 16:47:15 +00:00
Dave Abrahams 6141b83c5e filter_iterator
[SVN r850]
2003-01-12 06:14:18 +00:00
Dave Abrahams 04f037ae5c iterator/const_iterator indirection interop
[SVN r849]
2003-01-12 06:12:17 +00:00
Dave Abrahams 9b8d62d560 borland workarounds
[SVN r848]
2003-01-11 23:19:53 +00:00
Dave Abrahams 09542a1e9f suppress borland warning
[SVN r847]
2003-01-11 23:18:39 +00:00
Dave Abrahams a61df20f61 bugfix, borland workarounds
[SVN r846]
2003-01-11 23:18:14 +00:00
Dave Abrahams 041408a39c workaround for gcc 2.95.2
[SVN r845]
2003-01-11 21:35:52 +00:00
Dave Abrahams fd7e3d577e Sad but true, no working is_convertible for vc7.1 :(
[SVN r844]
2003-01-11 19:04:45 +00:00
Dave Abrahams 9a99ffb2ab Fix indirect iterators for broken compilers
[SVN r843]
2003-01-11 18:13:43 +00:00
Dave Abrahams a20f712cdc simplify
[SVN r842]
2003-01-11 18:12:37 +00:00
Thomas Witt 33660d770e Readded concept_tests
[SVN r830]
2003-01-02 17:54:12 +00:00
Thomas Witt d5819a1b16 Made implementation work, if is_convertible
is not supported.
Moved categories in new detail header.
Introduced category detection metafunctions.


[SVN r829]
2003-01-02 17:52:51 +00:00
Thomas Witt b97ad86e9c Improved implementation documentation.
More structured approach towards compiler deficiencies.


[SVN r817]
2002-12-31 14:25:30 +00:00
Dave Abrahams fb5f2205c6 Use iterators which work without PTS
[SVN r796]
2002-12-26 18:29:20 +00:00
Dave Abrahams 962677e305 Cleaned up flotsam and jetsam, simplified
[SVN r795]
2002-12-26 00:22:34 +00:00
Dave Abrahams 751d4831ef Improved workaround tests
[SVN r794]
2002-12-25 23:46:58 +00:00
Thomas Witt 343eaa9704 Added iterator traits specializations for compilers
without PTS support.


[SVN r764]
2002-12-10 20:45:00 +00:00
Thomas Witt 8e6e19f074 Relaxed interoperable requirements.
[SVN r763]
2002-12-10 20:43:46 +00:00
Thomas Witt 45c0a299f5 More vc6/7 fixes.
[SVN r762]
2002-12-10 19:43:45 +00:00
Thomas Witt 33d3672f82 Fixed operator-
[SVN r761]
2002-12-10 18:25:09 +00:00
Thomas Witt c93c921109 Added compatibility workarounds for MW7/8 and MSVC6/7.
[SVN r756]
2002-12-09 18:09:37 +00:00
Thomas Witt 891d49bb1c Removed spurious ;
[SVN r755]
2002-12-09 18:08:18 +00:00
Thomas Witt c068ca0bda Added failure checks.
[SVN r754]
2002-12-09 18:07:16 +00:00
Thomas Witt b263f69da1 Interoperability tests added.
[SVN r704]
2002-11-22 08:06:26 +00:00
Thomas Witt 8f98c66857 New minimal friend interface.
[SVN r703]
2002-11-22 08:05:44 +00:00
Thomas Witt b412e85c2c traversal_category bugfix.
[SVN r702]
2002-11-22 08:05:08 +00:00
Thomas Witt ea27eb8c93 InteroperableConcept added.
[SVN r701]
2002-11-22 08:04:08 +00:00
Dave Abrahams 344ccf1a2f Better portability
[SVN r673]
2002-11-09 03:39:12 +00:00
Dave Abrahams 0f502e2476 indirect iterators
[SVN r672]
2002-11-09 03:38:24 +00:00
Dave Abrahams 844386825a tweak
[SVN r671]
2002-11-07 05:16:51 +00:00
Dave Abrahams 0157a68e1f Progress on indirect_iterator
[SVN r670]
2002-11-07 05:09:44 +00:00
Dave Abrahams ad9df3393d downcast() -> self()
distance_from() -> distance_to()


[SVN r669]
2002-11-07 03:09:00 +00:00
Dave Abrahams 15edaef66e Scratch out redundant super typedef
[SVN r668]
2002-11-07 01:40:07 +00:00
Dave Abrahams a267657b58 Fix build procedure
[SVN r667]
2002-11-07 01:26:54 +00:00
Dave Abrahams 4fe1bafd1d bug fixes, works on more compilers
[SVN r666]
2002-11-07 01:21:44 +00:00
Dave Abrahams 7ee6923867 cleanup, works on more compilers
[SVN r665]
2002-11-07 01:21:14 +00:00
Dave Abrahams 62f9e72e24 I meant to commit this long ago
[SVN r664]
2002-11-06 22:43:56 +00:00
Jeremy Siek 9da3519e44 work on transform_iterator and new generic iterator tests
[SVN r637]
2002-10-29 03:48:28 +00:00
Jeremy Siek fbd2e198fd new test
[SVN r627]
2002-10-26 20:17:32 +00:00
Jeremy Siek 04dccc8ea8 more progress
[SVN r626]
2002-10-26 20:16:48 +00:00
Jeremy Siek 5fd440c1d0 change to new/old category recognition code
[SVN r613]
2002-10-24 18:56:16 +00:00
Jeremy Siek 560c48fe7a updated tag mechanism for iterators using Dave's idea
[SVN r612]
2002-10-24 15:45:01 +00:00
Jeremy Siek c4f60fd24b indenting
[SVN r611]
2002-10-24 00:08:10 +00:00
Jeremy Siek 1574946e13 new test
[SVN r610]
2002-10-23 22:57:24 +00:00
Jeremy Siek 26f5ac9a55 added new iterator category support to iterator adaptors
[SVN r609]
2002-10-23 22:55:53 +00:00
Jeremy Siek 73e3961cd5 fixed some typos
[SVN r608]
2002-10-23 18:12:37 +00:00
Dave Abrahams a2534dd445 Genvocalese?
[SVN r607]
2002-10-23 18:06:10 +00:00
Dave Abrahams a17934adb5 iterator_adaptor portability and fleshing-out
[SVN r600]
2002-10-22 22:10:49 +00:00
Jeremy Siek bc15598388 little example
[SVN r598]
2002-10-22 20:33:16 +00:00
Jeremy Siek f0cc713521 work on new version of iterator adaptors
[SVN r597]
2002-10-22 20:32:13 +00:00
Ronald Garcia ff0bb3e320 Removed. Now part of Boost Iterator Adaptors library.
[SVN r504]
2002-09-05 14:10:26 +00:00
Ronald Garcia 4b96e0e5f9 Initial Revision.
[SVN r501]
2002-09-02 16:52:09 +00:00
Jeremy Siek 9ea89e9643 added array_traits and pri_queue from boost
[SVN r409]
2002-08-20 15:19:41 +00:00
Jeremy Siek ce20536587 added input and output traversal tags
[SVN r319]
2002-07-26 19:24:44 +00:00
Jeremy Siek fec6f79912 added input and output traversal tags
[SVN r316]
2002-07-26 18:35:11 +00:00
Jeremy Siek abe42d2dd6 new file, copied from boost/pending
[SVN r227]
2002-06-19 23:24:34 +00:00
Jeremy Siek 8e189aeb49 blah
[SVN r209]
2002-06-04 20:52:11 +00:00
Jeremy Siek 5a0e943068 added copyrights
[SVN r208]
2002-06-04 16:14:09 +00:00
Jeremy Siek b88e7ed3d0 added copyright
[SVN r207]
2002-06-04 16:13:10 +00:00
Jeremy Siek d05a51fd12 added more comments
[SVN r206]
2002-06-04 16:11:57 +00:00
Jeremy Siek 33e2f3cf70 iterator category stuff from a boost development branch
[SVN r205]
2002-06-04 16:05:17 +00:00
Jeremy Siek a71b033cf4 new file, brought over from a development branch of boost
[SVN r204]
2002-06-04 16:04:34 +00:00
Jeremy Siek fde7e06887 new file
[SVN r203]
2002-06-03 22:08:15 +00:00
nobody b683dba9be New repository initialized by cvs2svn.
[SVN r146]
2002-05-15 19:48:00 +00:00
54 changed files with 8931 additions and 2721 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+188
View File
@@ -0,0 +1,188 @@
/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:date: $Date$
:version: $Revision$
:copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
*/
.first {
margin-top: 0 }
.last {
margin-bottom: 0 }
a.toc-backref {
text-decoration: none ;
color: black }
dd {
margin-bottom: 0.5em }
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.attention, div.caution, div.danger, div.error, div.hint,
div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: red ;
font-weight: bold ;
font-family: sans-serif }
div.hint p.admonition-title, div.important p.admonition-title,
div.note p.admonition-title, div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em }
div.footer, div.header {
font-size: smaller }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr {
width: 75% }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font-family: serif ;
font-size: 100% }
pre.line-block {
font-family: serif ;
font-size: 100% }
pre.literal-block, pre.doctest-block {
margin-left: 2em ;
margin-right: 2em ;
background-color: #eeeeee }
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option-argument {
font-style: italic }
span.pre {
white-space: pre }
span.problematic {
color: red }
table {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.citation {
border-left: solid thin gray ;
padding-left: 0.5ex }
table.docinfo {
margin: 2em 4em }
table.footnote {
border-left: solid thin black ;
padding-left: 0.5ex }
td, th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
th.docinfo-name, th.field-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap }
h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
font-size: 100% }
tt {
background-color: #eeeeee }
ul.auto-toc {
list-style-type: none }
+1598
View File
File diff suppressed because it is too large Load Diff
+822
View File
@@ -0,0 +1,822 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0022)http://internet.e-mail --><HTML><HEAD><TITLE>Improved Iterator Categories and Requirements</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="MSHTML 5.00.2919.6307" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<H1>
<CENTER>Improved Iterator Categories and Requirements</CENTER></H1>
<H2>Introduction</H2>The standard iterator categories and requirements are
flawed because they use a single hierarchy of requirements to address two
orthogonal issues: <B><I>iterator traversal</I></B> and <B><I>dereference return
type</I></B>. The current iterator requirement hierarchy is mainly geared
towards iterator traversal (hence the category names), while requirements that
address dereference return type sneak in at various places. The following table
gives a summary of the current dereference return type requirements in the
iterator categories.
<P>
<CENTER>
<TABLE border=1>
<TBODY>
<TR>
<TD>Output Iterator</TD>
<TD><TT>*i = a</TT> </TD></TR>
<TR>
<TD>Input Iterator</TD>
<TD><TT>*i</TT> is convertible to <TT>T</TT></TD></TR>
<TR>
<TD>Forward Iterator</TD>
<TD><TT>*i</TT> is <TT>T&amp;</TT> (or <TT>const T&amp;</TT> once <A
href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#200">issue
200</A> is resolved)</TD></TR>
<TR>
<TD>Random Access Iterator</TD>
<TD><TT>i[n]</TT> is convertible to <TT>T</TT> (which is odd because the
operational semantics say <TT>i[n]</TT> is equivalent to <TT>*(i + n)</TT>
which would have a return type of <TT>T&amp;</TT>) </TD></TR><A name=table:2>
<CAPTION><B>Table 1.</B> Summary of current dereference return type
requirements.</CAPTION></A></TABLE></CENTER>
<H2>Examples of useful iterators that do not ``fit''</H2>
<P>Because of the mixing of iterator traversal and dereference return type, many
useful iterators can not be appropriately categorized. For example,
<TT>vector&lt;bool&gt;::iterator</TT> is almost a random access iterator, but
the return type is not <TT>bool&amp;</TT> (see
<a href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#96">issue 96</a>
and Herb Sutter's paper J16/99-0008 = WG21 N1185). Therefore, the
iterators only meet the requirements of input iterator and output iterator. This
is so nonintuitive that at least one implementation erroneously assigns
<TT>random_access_iterator_tag</TT> as its <TT>iterator_category</TT>. Also,
<TT>vector&lt;bool&gt;</TT> is not the only example of useful iterators that do
not return true references: there is the often cited example of disk-based
collections.
<P>Another example is a counting iterator, an iterator the returns a sequence of
integers when incremented and dereferenced (see <A
href="http://www.boost.org/libs/utility/counting_iterator.htm"><TT>boost::counting_iterator</TT></A>).
There are two ways to implement this iterator, 1) make the <TT>reference</TT>
type be a true reference (a reference to an integer data member of the counting
iterator) or 2) make the <TT>reference</TT> type be the same as the
<TT>value_type</TT>. Option 1) runs into the problems discussed in <A
href="http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#198">Issue
198</A>, the reference will not be valid after the iterator is destroyed. Option
2) is therefore a better choice, but then we have a counting iterator that
cannot be a random access iterator.
<P>Yet another example is a transform iterator, an iterator adaptor that applies
a unary function object to the dereference value of the wrapped iterator (see <A
href="http://www.boost.org/libs/utility/transform_iterator.htm"><TT>boost::transform_iterator</TT></A>).
For unary functions such as <TT>std::times</TT> the return type of
<TT>operator*</TT> clearly needs to be the <TT>result_type</TT> of the function
object, which is typically not a reference. However, with the current iterator
requirements, if you wrap <TT>int*</TT> with a transform iterator, you do not
get a random access iterator as expected, but an input iterator.
<P>A fourth example is found in the vertex and edge iterators of the <A
href="http://www.boost.org/libs/graph/doc/table_of_contents.html">Boost Graph
Library</A>. These iterators return vertex and edge descriptors, which are
lightweight handles created on-the-fly. They must be returned by-value. As a
result, their current standard iterator category is
<TT>std::input_iterator_tag</TT>, which means that, strictly speaking, you could
not use these iterators with algorithms like <TT>std::min_element()</TT>. As a
temporary solution, we introduced the concept <A
href="http://www.boost.org/libs/utility/MultiPassInputIterator.html">Multi-Pass
Input Iterator</A> to describe the vertex and edge descriptors, but as the
design notes for concept suggest, a better solution is needed.
<P>In short, there are many useful iterators that do not fit into the current
standard iterator categories. As a result, the following bad things happen:
<UL>
<LI>Iterators are often miss-categorized.
<LI>Algorithm requirements are more strict than necessary, because they can
not separate out the need for random-access from the need for a true reference
return type. </LI></UL>
<H2>Proposal for new iterator categories and requirements</H2>The iterator
requirements should be separated into two hierarchies. One set of concepts
handles the return type semantics:
<UL>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ReadableIterator">Readable
Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:WritableIterator">Writable
Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:SwappableIterator">Swappable
Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ConstantLvalueIterator">Constant
Lvalue Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:MutableLvalueIterator">Mutable
Lvalue Iterator</A> </LI></UL>The other set of concepts handles iterator
traversal:
<UL>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ForwardTraversalIterator">Forward
Traversal Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:BidirectionalTraversalIterator">Bidirectional
Traversal Iterator</A>
<LI><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:RandomAccessTraversalIterator">Random
Access Traversal Iterator</A> </LI>
</UL>
<P>The current Input Iterator and Output Iterator requirements will
continue to be used as is. Note that Input Iterator implies Readable
Iterator and Output Iterator implies Writable Iterator.</P>
<P>Note: we considered defining a Single-Pass Iterator, which could be
combined with Readable or Writable Iterator to replace the Input and
Output Iterator requirements. We rejected this idea because there are
several differences between Input and Output Iterators that make it
hard to merge them: Input Iterator requires Equality Comparable while
Output Iterator does not and Input Iterator requires Assignable while
Output Iterator does not.</P>
<H3>New category tags and traits classes</H3>
<P>The new iterator categories will require new tag classes.</P>
<PRE>namespace std {
// Returns Category Tags
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct swappable_iterator_tag { };
struct mutable_lvalue_iterator_tag : virtual public writable_iterator_tag,
virtual public readable_iterator_tag { };
struct constant_lvalue_iterator_tag : public readable_iterator_tag { };
// Traversal Category Tags
struct input_traversal_tag { };
struct output_traversal_tag { };
struct forward_traversal_tag { };
struct bidirectional_traversal_tag : public forward_traversal_tag { };
struct random_access_traversal_tag : public bidirectional_traversal_tag { };
}
</PRE>
<P>Access to the return and traversal tags will be through the
following two traits classes, which have a member typedef named
<TT>type</TT> that provides the tag type. We explain the
definitions of these classes later.</P>
<PRE>
template &lt;typename Iterator&gt;
struct return_category; // contains: typedef ... type;
template &lt;typename Iterator&gt;
struct traversal_category; // contains: typedef ... type;
</PRE>
<P>We want it to be convenient for programmers to create iterators
that satisfy both the old and new iterator requirements. Therefore
the following class is provided as a way to create tags for use as the
old <TT>iterator_category</TT> typedef within
<TT>iterator_traits</TT>.
<PRE>namespace std {
template &lt;class ReturnTag, class TraversalTag&gt;
struct iterator_tag : cvt_iterator_category&lt;ReturnTag, TraversalTag&gt;::type
{
typedef ReturnTag returns;
typedef TraversalTag traversal;
};
</PRE>
<P>The <TT>cvt_iterator_category</TT> template computes the
appropriate old iterator category based on the return and traversal
category.</P>
<PRE>namespace std {
template &lt;class RC, class TC&gt;
struct cvt_iterator_category
{
<B><I>// Pseudo-code, &lt;= means inherits or same type</I></B>
if (RC &lt;= constant_lvalue_iterator_tag || RC &lt;= mutable_lvalue_iterator_tag) {
if (TC &lt;= random_access_traversal_tag)
typedef random_access_iterator_tag type;
else if (TC &lt;= bidirectional_traversal_tag)
typedef bidirectional_iterator_tag type;
else if (TC &lt;= forward_traversal_tag)
typedef forward_iterator_tag type;
else
error;
} else if (RC &lt;= readable_iterator_tag && RC &lt;= input_traversal_tag)
typedef input_iterator_tag type;
else if (RC &lt;= writable_iterator_tag && output_traversal_tag)
typedef output_iterator_tag type;
else
error;
};
}
</PRE>
<P>The following is an example of a new iterator class using the
<TT>iterator_tag</TT> class to create its <TT>iterator_category</TT>
member typedef.</P>
<PRE>
struct my_iterator {
typedef std::iterator_tag&lt;std::readable_iterator_tag,
std::random_access_traversal_tag&gt; iterator_category;
...
};
</PRE>
We also want old iterators to work with new algorithms, that is,
algorithms that use the new iterator categories. We facilitate this by
defining the <TT>return_category</TT> and <TT>traversal_category</TT>
in such a way as they can be used with both old and new iterators.
For old iterators, the appropriate return and traversal categories are
computed based on the old iterator category. For new iterators, the
return and traversal tags are extracted from within the
<TT>iterator_category</TT> tag.
<PRE>
template &lt;typename Iterator&gt;
class return_category
{
<B><I>// Pseudo-code</I></B>
typedef iterator_traits&lt;Iterator&gt;::iterator_category tag;
typedef iterator_traits&lt;Iterator&gt;::value_type T;
public:
if (exists(tag::returns)) // must be a new iterator
typedef tag::returns type;
else if (tag &lt;= forward_iterator_tag) {
if (is-const(T))
typedef constant_lvalue_iterator_tag type;
else
typedef mutable_lvalue_iterator_tag type;
} else if (tag &lt;= input_iterator_tag)
typedef readable_iterator_tag type;
else if (tag &lt;= output_iterator_tag)
typedef writable_iterator_tag type;
else
error;
};
template &lt;typename T&gt;
struct return_category&lt;T*&gt;
{
<B><I>// Pseudo-code</I></B>
if (is-const(T))
typedef boost::constant_lvalue_iterator_tag type;
else
typedef boost::mutable_lvalue_iterator_tag type;
};
template &lt;typename Iterator&gt;
class traversal_category
{
typedef iterator_traits&lt;Iterator&gt;::iterator_category tag;
public:
<B><I>// Pseudo-code</I></B>
if (exists(tag::traversal)) // must be a new iterator
typedef tag::traversal type;
else if (tag &lt;= random_access_iterator_tag)
typedef random_access_traversal_tag type;
else if (tag &lt;= bidirectional_iterator_tag)
typedef bidirectional_traversal_tag type;
else if (tag &lt;= is_forward_iterator_tag)
typedef forward_traversal_tag type;
else if (tag &lt;= input_iterator_tag)
typedef input_traversal_tag type;
else if (tag &lt;= out_iterator_tag)
typedef output_traversal_tag type;
else
error;
};
template &lt;typename T&gt;
struct traversal_category&lt;T*&gt;
{
typedef random_access_traversal_tag type;
};
</PRE>
<H2>Impact on the Standard Algorithms</H2>
<P>Many of the standard algorithms place more requirements than
necessary on their iterator parameters due to the coarseness of the
current iterator categories. By using the new iterator categories a
better fit can be achieved, thereby increasing the reusability of the
algorithms. These changes will not affect user-code, though they will
require changes by standard implementers: dispatching should be based
on the new categories, and in places return values may need to be
handled more carefully. In particular, uses of <TT>std::swap()</TT>
will need to be replaced with <TT>std::iter_swap()</TT>, and
<TT>std::iter_swap()</TT> will need to call <TT>std::swap()</TT>. </P>
<P>
<CENTER>
<TABLE border=1>
<TBODY>
<TR>
<TH>Algorithm</TH>
<TH>Requirement Change</TH></TR>
<TR>
<TD>find_end</TD>
<TD rowSpan=12>Forward Iterator<BR>-&gt; Forward Traversal Iterator and
Readable Iterator </TD></TR>
<TR>
<TD>find_first_of</TD></TR>
<TR>
<TD>adjacent_find</TD></TR>
<TR>
<TD>search</TD></TR>
<TR>
<TD>search_n</TD></TR>
<TR>
<TD>rotate_copy</TD></TR>
<TR>
<TD>lower_bound</TD></TR>
<TR>
<TD>upper_bound</TD></TR>
<TR>
<TD>equal_range</TD></TR>
<TR>
<TD>binary_search</TD></TR>
<TR>
<TD>min_element</TD></TR>
<TR>
<TD>max_element</TD></TR>
<TR>
<TD>iter_swap</TD>
<TD>Forward Iterator<BR>-&gt; Swappable Iterator </TD></TR>
<TR>
<TD>fill</TD>
<TD rowSpan=2>Forward Iterator<BR>-&gt; Forward Traversal Iterator and
Writable Iterator </TD></TR>
<TR>
<TD>generate</TD></TR>
<TR>
<TD>swap_ranges</TD>
<TD rowSpan=2>Forward Iterator<BR>-&gt; Forward Traversal Iterator and
Swappable Iterator </TD></TR>
<TR>
<TD>rotate</TD></TR>
<TR>
<TD>replace</TD>
<TD rowSpan=5>Forward Iterator<BR>-&gt; Forward Traversal Iterator
and<BR>Readable Iterator and Writable Iterator </TD>
<TR>
<TD>replace_if</TD></TR>
<TR>
<TD>remove</TD></TR>
<TR>
<TD>remove_if</TD></TR>
<TR>
<TD>unique</TD></TR>
<TR>
<TD>reverse</TD>
<TD rowSpan=2>Bidirectional Iterator<BR>-&gt; Bidirectional Traversal
Iterator and Swappable Iterator </TD></TR>
<TR>
<TD>partition</TD></TR>
<TR>
<TD>copy_backwards</TD>
<TD>Bidirectional Iterator<BR>-&gt; Bidirectional Traversal Iterator and
Readable Iterator<BR>Bidirectional Iterator<BR>-&gt; Bidirectional
Traversal Iterator and Writable Iterator </TD></TR>
<TR>
<TD>next_permutation</TD>
<TD rowSpan=2>Bidirectional Iterator<BR>-&gt; Bidirectional Traversal
Iterator and <BR>Swappable Iterator and Readable Iterator </TD>
<TR>
<TD>prev_permutation</TD></TR>
<TR>
<TD>stable_partition</TD>
<TD rowSpan=2>Bidirectional Iterator<BR>-&gt; Bidirectional Traversal
Iterator and <BR>Readable Iterator and Writable Iterator </TD>
<TR>
<TD>inplace_merge</TD></TR>
<TR>
<TD>reverse_copy</TD>
<TD>Bidirectional Iterator<BR>-&gt; Bidirectional Traversal Iterator and
Readable Iterator </TD></TR>
<TR>
<TD>random_shuffle</TD>
<TD rowSpan=9>Random Access Iterator<BR>-&gt; Random Access Traversal
Iterator and Swappable Iterator </TD></TR>
<TR>
<TD>sort</TD></TR>
<TR>
<TD>stable_sort</TD></TR>
<TR>
<TD>partial_sort</TD></TR>
<TR>
<TD>nth_element</TD></TR>
<TR>
<TD>push_heap</TD></TR>
<TR>
<TD>pop_heap</TD></TR>
<TR>
<TD>make_heap</TD></TR>
<TR>
<TD>sort_heap</TD></TR><A name=table:2>
<CAPTION><B>Table 2.</B> Requirement changes for standard
algorithms.</CAPTION></A></TABLE></CENTER>
<H2>The New Iterator Requirements</H2>
<H3>Notation</H3>
<TABLE>
<TBODY>
<TR>
<TD><TT>X</TT></TD>
<TD>The iterator type.</TD></TR>
<TR>
<TD><TT>T</TT></TD>
<TD>The value type of <TT>X</TT>, i.e.,
<TT>std::iterator_traits&lt;X&gt;::value_type</TT>.</TD></TR>
<TR>
<TD><TT>x</TT>, <TT>y</TT></TD>
<TD>An object of type <TT>X</TT>.</TD></TR>
<TR>
<TD><TT>t</TT></TD>
<TD>An object of type <TT>T</TT>.</TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:ReadableIterator></A>Readable Iterator </H3>A Readable
Iterator is an iterator that dereferences to produce an rvalue that is
convertible to the <TT>value_type</TT> of the iterator.
<H3>Associated Types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Value type</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::value_type</TT></TD>
<TD>The type of the objects pointed to by the iterator.</TD></TR>
<TR>
<TD>Reference type</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::reference</TT></TD>
<TD>The return type of dereferencing the iterator. This type must be
convertible to <TT>T</TT>. </TD></TR>
<TR>
<TD>Return Category</TD>
<TD><TT>std::return_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::readable_iterator_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Refinement of</H3><A
href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</A>
<H3>Valid expressions</H3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Type requirements</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Dereference</TD>
<TD><TT>*x</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::reference</TT></TD></TR>
<TR>
<TD>Member access</TD>
<TD><TT>x-&gt;m</TT></TD>
<TD><TT>T</TT> is a type with a member named <TT>m</TT>.</TD>
<TD>If <TT>m</TT> is a data member, the type of <TT>m</TT>. If <TT>m</TT>
is a member function, the return type of <TT>m</TT>. </TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:WritableIterator></A>Writable Iterator </H3>A Writable
Iterator is an iterator that can be used to store a value using the
dereference-assignment expression.
<H3>Definitions</H3>If <TT>x</TT> is an Writable Iterator of type <TT>X</TT>,
then the expression <TT>*x = a;</TT> stores the value <TT>a</TT> into
<TT>x</TT>. Note that <TT>operator=</TT>, like other C++ functions, may be
overloaded; it may, in fact, even be a template function. In general, then,
<TT>a</TT> may be any of several different types. A type <TT>A</TT> belongs to
the <I>set of value types</I> of <TT>X</TT> if, for an object <TT>a</TT> of type
<TT>A</TT>, <TT>*x = a;</TT> is well-defined and does not require performing any
non-trivial conversions on <TT>a</TT>.
<H3>Associated Types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Return Category</TD>
<TD><TT>std::return_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::writable_iterator_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Refinement of</H3><A
href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</A>
<H3>Valid expressions</H3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Dereference assignment</TD>
<TD><TT>*x = a</TT></TD>
<TD>unspecified</TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:SwappableIterator></A>Swappable Iterator </H3>A Swappable
Iterator is an iterator whose dereferenced values can be swapped.
<P>Note: the requirements for Swappable Iterator are dependent on the issues
surrounding <TT>std::swap()</TT> being resolved. Here we assume that the issue
will be resolved by allowing the overload of <TT>std::swap()</TT> for
user-defined types.
<P>Note: Readable Iterator and Writable Iterator combined implies Swappable
Iterator because of the fully templated <TT>std::swap()</TT>. However, Swappable
Iterator does not imply Readable Iterator nor Writable Iterator.
<H3>Associated Types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Return Category</TD>
<TD><TT>std::return_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::swappable_iterator_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Valid expressions</H3>Of the two valid expressions listed below, only one
<B>OR</B> the other is required. If <TT>std::iter_swap()</TT> is overloaded for
<TT>X</TT> then <TT>std::swap()</TT> is not required. If
<TT>std::iter_swap()</TT> is not overloaded for <TT>X</TT> then the default
(fully templated) version is used, which will call <TT>std::swap()</TT> (this
means changing the current requirements for <TT>std::iter_swap()</TT>).
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Iterator Swap</TD>
<TD><TT>std::iter_swap(x, y)</TT></TD>
<TD>void</TD></TR>
<TR>
<TD>Dereference and Swap</TD>
<TD><TT>std::swap(*x, *y)</TT></TD>
<TD>void</TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:ConstantLvalueIterator></A>Constant Lvalue Iterator </H3>A
Constant Lvalue Iterator is an iterator that dereferences to produce a const
reference to the pointed-to object, i.e., the associated <TT>reference</TT> type
is <TT>const T&amp;</TT>. Changing the value of or destroying an iterator that
models Constant Lvalue Iterator does not invalidate pointers and references
previously obtained from that iterator.
<H3>Refinement of</H3><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ReadableIterator">Readable
Iterator</A>
<H3>Associated Types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Reference type</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::reference</TT></TD>
<TD>The return type of dereferencing the iterator, which must be <TT>const
T&amp;</TT>. </TD></TR><!-- I don't think this is needed
<tr>
<td>Pointer type</td>
<td><tt>std::iterator_traits&lt;X&gt;::pointer</tt></td>
<td>
The pointer to the value type, which must be <tt>const T*</tt>.
</td>
</tr>
-->
<TR>
<TD>Return Category</TD>
<TD><TT>std::return_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::constant_lvalue_iterator_tag</TT>
</TD></TR></TBODY></TABLE><!-- these are not necessary now that we use reference as operator* return type
<h3>Valid expressions</h3>
<Table border>
<tr><TH>Name</TH><TH>Expression</TH><TH>Type requirements</TH><TH>Return type</TH></tr>
<tr>
<td>Dereference</td>
<td><tt>*x</tt></td>
<td>&nbsp;</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
</tr>
<tr>
<td>Member access</td>
<td><tt>x-&gt;m</tt></td>
<td><tt>T</tt> is a type with a member named <tt>m</tt>.</td>
<td>
&nbsp;
</td>
</tr>
</table>
-->
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:MutableLvalueIterator></A>Mutable Lvalue Iterator </H3>A
Mutable Lvalue Iterator is an iterator that dereferences to produce a reference
to the pointed-to object. The associated <TT>reference</TT> type is
<TT>T&amp;</TT>. Changing the value of or destroying an iterator that models
Mutable Lvalue Iterator does not invalidate pointers and references previously
obtained from that iterator.
<H3>Refinement of</H3><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ReadableIterator">Readable
Iterator</A>, <A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:WritableIterator">Writable
Iterator</A>, and <A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:SwappableIterator">Swappable
Iterator</A>.
<H3>Associated Types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Reference type</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::reference</TT></TD>
<TD>The return type of dereferencing the iterator, which must be
<TT>T&amp;</TT>.</TD></TR><!-- I don't think this is necessary
<tr>
<td>Pointer type</td>
<td><tt>std::iterator_traits&lt;X&gt;::pointer</tt></td>
<td>
The pointer to the value type, which is <tt>T*</tt>.
</td>
</tr>
-->
<TR>
<TD>Return Category</TD>
<TD><TT>std::return_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::mutable_lvalue_iterator_tag</TT>
</TD></TR></TBODY></TABLE><!-- no longer needed since the return type is specified as reference in the readable iterator
<h3>Valid expressions</h3>
<Table border>
<tr><TH>Name</TH><TH>Expression</TH><TH>Type requirements</TH><TH>Return type</TH></tr>
<tr>
<td>Dereference</td>
<td><tt>*x</tt></td>
<td>&nbsp;</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
</tr>
<tr>
<td>Member access</td>
<td><tt>x-&gt;m</tt></td>
<td><tt>T</tt> is a type with a member named <tt>m</tt>.</td>
<td>
&nbsp;
</td>
</tr>
</table>
-->
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:ForwardTraversalIterator></A>Forward Traversal Iterator
</H3>The Forward Iterator is an iterator that can be incremented. Also, it is
permissible to make multiple passes through the iterator's range.
<H3>Refinement of</H3><A
href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</A>, <A
href="http://www.boost.org/libs/utility/Assignable.html">Assignable</A>, <A
href="http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
Constructible</A>, and <A
href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
Comparable</A>
<H3>Associated types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Difference Type</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::difference_type</TT></TD>
<TD>A signed integral type used for representing distances between
iterators that point into the same range. </TD></TR>
<TR>
<TD>Traversal Category</TD>
<TD><TT>std::traversal_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::forward_traversal_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Valid expressions</H3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Type requirements</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Preincrement</TD>
<TD><TT>++i</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X&amp;</TT></TD></TR>
<TR>
<TD>Postincrement</TD>
<TD><TT>i++</TT></TD>
<TD>&nbsp;</TD>
<TD>convertible to <TT>const X&amp;</TT></TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:BidirectionalTraversalIterator></A>Bidirectional Traversal
Iterator </H3>An iterator that can be incremented and decremented.
<H3>Refinement of</H3><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ForwardTraversalIterator">Forward
Traversal Iterator</A>
<H3>Associated types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Traversal Category</TD>
<TD><TT>std::traversal_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::bidirectional_traversal_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Valid expressions</H3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Type requirements</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Predecrement</TD>
<TD><TT>--i</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X&amp;</TT></TD></TR>
<TR>
<TD>Postdecrement</TD>
<TD><TT>i--</TT></TD>
<TD>&nbsp;</TD>
<TD>convertible to <TT>const X&amp;</TT></TD></TR></TBODY></TABLE>
<P>
<HR>
<!--------------------------------------------------------------------------->
<H3><A name=concept:RandomAccessTraversalIterator></A>Random Access Traversal
Iterator </H3>An iterator that provides constant-time methods for moving forward
and backward in arbitrary-sized steps.
<H3>Refinement of</H3><A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:BidirectionalTraversalIterator">Bidirectional
Traversal Iterator</A> and <A
href="http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
Comparable</A> where <TT>&lt;</TT> is a total ordering
<H3>Associated types</H3>
<TABLE border=1>
<TBODY>
<TR>
<TD>Traversal Category</TD>
<TD><TT>std::traversal_category&lt;X&gt;::type</TT></TD>
<TD>A type convertible to <TT>std::random_access_traversal_tag</TT>
</TD></TR></TBODY></TABLE>
<H3>Valid expressions</H3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Type requirements</TH>
<TH>Return type</TH></TR>
<TR>
<TD>Iterator addition</TD>
<TD><TT>i += n</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X&amp;</TT></TD></TR>
<TR>
<TD>Iterator addition</TD>
<TD><TT>i + n</TT> or <TT>n + i</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X</TT></TD></TR>
<TR>
<TD>Iterator subtraction</TD>
<TD><TT>i -= n</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X&amp;</TT></TD></TR>
<TR>
<TD>Iterator subtraction</TD>
<TD><TT>i - n</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>X</TT></TD></TR>
<TR>
<TD>Difference</TD>
<TD><TT>i - j</TT></TD>
<TD>&nbsp;</TD>
<TD><TT>std::iterator_traits&lt;X&gt;::difference_type</TT></TD></TR>
<TR>
<TD>Element operator</TD>
<TD><TT>i[n]</TT></TD>
<TD><TT>X</TT> must also be a model of <A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:ReadableIterator">Readable
Iterator</A>. </TD>
<TD><TT>std::iterator_traits&lt;X&gt;::reference</TT></TD></TR>
<TR>
<TD>Element assignment</TD>
<TD><TT>i[n] = t</TT></TD>
<TD><TT>X</TT> must also be a model of <A
href="file:///C:/WINDOWS/TEMP/iterator-categories.html#concept:WritableIterator">Writable
Iterator</A>.</TD>
<TD>unspecified</TD></TR></TBODY></TABLE>
<P>
<HR>
<!-- LocalWords: HTML BGCOLOR FFFFFF TR TD Siek HREF mailto jsiek
--><!-- LocalWords: lsc edu tt const href http anubis dkuug dk JTC SC WG docs lt
--><!-- LocalWords: lwg html bool gt Sutter's htm Lvalue namespace std struct
--><!-- LocalWords: lvalue typename OldTraits reusability min iter prev inplace
--><!-- LocalWords: rvalue templated Preincrement Postincrement Predecrement
--><!-- LocalWords: Postdecrement
--></BODY></HTML>
+731
View File
@@ -0,0 +1,731 @@
++++++++++++++++++++++
New Iterator Concepts
++++++++++++++++++++++
:Author: David Abrahams, Jeremy Siek, Thomas Witt
:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
:organization: `Boost Consulting`_, Indiana University `Open Systems Lab`_, University of Hanover `Institute for Transport Railway Operation and Construction`_
:date: $Date$
:Number: N1477=03-0060
:copyright: Copyright Dave Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
.. _`Boost Consulting`: http://www.boost-consulting.com
.. _`Open Systems Lab`: http://www.osl.iu.edu
.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de
:Abstract: We propose a new system of iterator concepts that treat
access and positioning independently. This allows the
concepts to more closely match the requirements
of algorithms and provides better categorizations
of iterators that are used in practice. This proposal
is a revision of paper n1297_.
.. contents:: Table of Contents
.. _n1297: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2001/n1297.html
============
Motivation
============
The standard iterator categories and requirements are flawed because
they use a single hierarchy of concepts to address two orthogonal
issues: *iterator traversal* and *value access*. As a result, many
algorithms with requirements expressed in terms of the iterator
categories are too strict. Also, many real-world iterators can not be
accurately categorized. A proxy-based iterator with random-access
traversal, for example, may only legally have a category of "input
iterator", so generic algorithms are unable to take advantage of its
random-access capabilities. The current iterator concept hierarchy is
geared towards iterator traversal (hence the category names), while
requirements that address value access sneak in at various places. The
following table gives a summary of the current value access
requirements in the iterator categories.
+------------------------+-------------------------------------------------------------------------+
| Output Iterator | ``*i = a`` |
+------------------------+-------------------------------------------------------------------------+
| Input Iterator | ``*i`` is convertible to ``T`` |
+------------------------+-------------------------------------------------------------------------+
| Forward Iterator | ``*i`` is ``T&`` (or ``const T&`` once |
| | `issue 200`_ is resolved) |
+------------------------+-------------------------------------------------------------------------+
| Random Access Iterator | ``i[n]`` is convertible to ``T`` (also ``i[n] = t`` is required for |
| | mutable iterators once `issue 299`_ is resolved) |
+------------------------+-------------------------------------------------------------------------+
.. _issue 200: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#200
.. _issue 299: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#299
Because iterator traversal and value access are mixed together in a
single hierarchy, many useful iterators can not be appropriately
categorized. For example, ``vector<bool>::iterator`` is almost a
random access iterator, but the return type is not ``bool&`` (see
`issue 96`_ and Herb Sutter's paper J16/99-0008 = WG21
N1185). Therefore, the iterators of ``vector<bool>`` only meet the
requirements of input iterator and output iterator. This is so
nonintuitive that at least one implementation erroneously assigns
``random_access_iterator_tag`` as its ``iterator_category``.
.. _issue 96: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#96
Another difficult-to-categorize iterator is the transform iterator, an
adaptor which applies a unary function object to the dereferenced
value of the some underlying iterator (see `transform_iterator`_).
For unary functions such as ``times``, the return type of
``operator*`` clearly needs to be the ``result_type`` of the function
object, which is typically not a reference. Because random access
iterators are required to return lvalues from ``operator*``, if you
wrap ``int*`` with a transform iterator, you do not get a random
access iterator as might be expected, but an input iterator.
.. _`transform_iterator`: http://www.boost.org/libs/utility/transform_iterator.htm
A third example is found in the vertex and edge iterators of the
`Boost Graph Library`_. These iterators return vertex and edge
descriptors, which are lightweight handles created on-the-fly. They
must be returned by-value. As a result, their current standard
iterator category is ``input_iterator_tag``, which means that,
strictly speaking, you could not use these iterators with algorithms
like ``min_element()``. As a temporary solution, the concept
`Multi-Pass Input Iterator`_ was introduced to describe the vertex and
edge descriptors, but as the design notes for the concept suggest, a
better solution is needed.
.. _Boost Graph Library: http://www.boost.org/libs/graph/doc/table_of_contents.html
.. _Multi-Pass Input Iterator: http://www.boost.org/libs/utility/MultiPassInputIterator.html
In short, there are many useful iterators that do not fit into the
current standard iterator categories. As a result, the following bad
things happen:
- Iterators are often mis-categorized.
- Algorithm requirements are more strict than necessary, because they
cannot separate the need for random access or bidirectional
traversal from the need for a true reference return type.
========================
Impact on the Standard
========================
The new iterator concepts are backward-compatible with the old
iterator requirements, and old iterators are forward-compatible with
the new iterator concepts. That is to say, iterators that satisfy the
old requirements also satisfy appropriate concepts in the new system,
and iterators modeling the new concepts will automatically satisfy the
appropriate old requirements.
.. I think we need to say something about the resolution to allow
convertibility to any of the old-style tags as a TR issue (hope it
made it). -DWA
.. Hmm, not sure I understand. Are you talking about whether a
standards conforming input iterator is allowed to have
a tag that is not input_iterator_tag but that
is convertible to input_iterator_tag? -JGS
The algorithms in the standard library benefit from the new iterator
concepts because the new concepts provide a more accurate way to
express their type requirements. The result is algorithms that are
usable in more situations and have fewer type requirements. The
following lists the proposed changes to the type requirements of
algorithms.
Forward Iterator -> Forward Traversal Iterator and Readable Iterator
``find_end, adjacent_find, search, search_n, rotate_copy, lower_bound, upper_bound, equal_range, binary_search, min_element, max_element``
Forward Iterator (1) -> Single Pass Iterator and Readable Iterator
Forward Iterator (2) -> Forward Traversal Iterator and Readable Iterator
``find_first_of``
Forward Iterator -> Readable Iterator and Writable Iterator
``iter_swap``
Forward Iterator -> Single Pass Iterator and Writable Iterator
``fill, generate``
Forward Iterator -> Forward Traversal Iterator and Swappable Iterator
``rotate``
Forward Iterator (1) -> Swappable Iterator and Single Pass Iterator
Forward Iterator (2) -> Swappable Iterator and Incrementable Iterator
``swap_ranges``
Forward Iterator -> Forward Traversal Iterator and Readable Iterator and Writable Iterator
``remove, remove_if, unique``
Forward Iterator -> Single Pass Iterator and Readable Iterator and Writable Iterator
``replace, replace_if``
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator
``reverse``
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable and Swappable Iterator
``partition``
Bidirectional Iterator (1) -> Bidirectional Traversal Iterator and Readable Iterator,
Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable Iterator
``copy_backwards``
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator and Readable Iterator
``next_permutation, prev_permutation``
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator and Writable Iterator
``stable_partition, inplace_merge``
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator
``reverse_copy``
Random Access Iterator -> Random Access Traversal Iterator and Readable and Swappable Iterator
``random_shuffle, sort, stable_sort, partial_sort, nth_element, push_heap, pop_heap
make_heap, sort_heap``
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
``equal``
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
``transform``
========
Design
========
The iterator requirements are be separated into two hierarchies. One
set of concepts handles the syntax and semantics of value access:
- Readable Iterator
- Writable Iterator
- Swappable Iterator
- Readable Lvalue Iterator
- Writable Lvalue Iterator
The refinement relationships among these iterator concepts are given
in the following diagram.
.. image:: access.png
The access concepts describe requirements related to ``operator*`` and
``operator->``, including the ``value_type``, ``reference``, and
``pointer`` associated types.
The other set of concepts handles traversal:
- Incrementable Iterator
- Single Pass Iterator
- Forward Traversal Iterator
- Bidirectional Traversal Iterator
- Random Access Traversal Iterator
The refinement relationships for the traversal concepts are in the
following diagram.
.. image:: traversal.png
In addition to the iterator movement operators, such as
``operator++``, the traversal concepts also include requirements on
position comparison such as ``operator==`` and ``operator<``. The
reason for the fine grain slicing of the concepts into the
Incrementable and Single Pass is to provide concepts that are exact
matches with the original input and output iterator requirements.
The relationship between the new iterator concepts and the old are
given in the following diagram.
.. image:: oldeqnew.png
Like the old iterator requirements, we provide tags for purposes of
dispatching. There are two hierarchies of tags, one for the access
concepts and one for the traversal concepts. We provide an access
mechanism for mapping iterator types to these new tags. Our design
reuses ``iterator_traits<Iter>::iterator_category`` as the access
mechanism. To enable this, a pair of access and traversal tags are
combined into a single type using the following `iterator_tag` class.
::
template <class AccessTag, class TraversalTag>
struct iterator_tag : /* appropriate old category or categories */
{
typedef AccessTag access;
typedef TraversalTag traversal;
};
The ``iterator_tag`` class template is derived from the appropriate
iterator tag or tags from the old requirements based on the new-style
tags passed as template parameters. The algorithm for determining the
old tag or tags from the new tags picks the least-refined old concepts
that include all of the requirements of the access and traversal
concepts (that is, the closest fit), if any such category exists. For
example, a the category tag for a Readable Single Pass Iterator will
always be derived from ``input_iterator_tag``, while the category tag
for a Single Pass Iterator that is both Readable and Writable will be
derived from both ``input_iterator_tag`` and ``output_iterator_tag``.
We also provide two helper classes that make it convenient to obtain
the access and traversal tags of an iterator. These helper classes
work both for iterators whose ``iterator_category`` is
``iterator_tag`` and also for iterators using the original iterator
categories.
::
template <class Iterator> struct access_category { typedef ... type; };
template <class Iterator> struct traversal_category { typedef ... type; };
The most difficult design decision concerned the ``operator[]``. The
direct approach for specifying ``operator[]`` would have a return type
of ``reference``; the same as ``operator*``. However, going in this
direction would mean that an iterator satisfying the old Random Access
Iterator requirements would not necessarily be a model of Readable or
Writable Lvalue Iterator. Instead we have chosen a design that
matches the preferred resolution of `issue 299`_: ``operator[]`` is
only required to return something convertible to the ``value_type``
(for a Readable Iterator), and is required to support assignment
``i[n] = t`` (for a Writable Iterator).
===============
Proposed Text
===============
Addition to [lib.iterator.requirements]
=======================================
Iterator Value Access Concepts [lib.iterator.value.access]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
In the tables below, ``X`` is an iterator type, ``a`` is a constant
object of type ``X``, ``T`` is
``std::iterator_traits<X>::value_type``, and ``v`` is a constant
object of type ``T``.
.. _Readable Iterator:
Readable Iterators [lib.readable.iterators]
-------------------------------------------
A class or built-in type ``X`` models the *Readable Iterator* concept
for the value type ``T`` if the following expressions are valid and
respect the stated semantics. ``U`` is the type of any specified
member of type ``T``.
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Readable Iterator Requirements (in addition to CopyConstructible) |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+======================================+===================================================+=================================================================+
| ``iterator_traits<X>::value_type`` | ``T`` | Any non-reference, non-cv-qualified type |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
| ``iterator_traits<X>::reference`` | Convertible to ``iterator_traits<X>::value_type`` | |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
| ``access_category<X>::type`` | Convertible to ``readable_iterator_tag`` | |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
| ``*a`` | ``iterator_traits<X>::reference`` | pre: ``a`` is dereferenceable. If ``a == b`` then |
| | | ``*a`` is equivalent to ``*b`` |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
| ``a->m`` | ``U&`` | pre: ``(*a).m`` is well-defined. Equivalent to ``(*a).m`` |
+--------------------------------------+---------------------------------------------------+-----------------------------------------------------------------+
.. _Writable Iterator:
Writable Iterators [lib.writable.iterators]
-------------------------------------------
A class or built-in type ``X`` models the *Writable Iterator* concept
if the following expressions are valid and respect the stated
semantics.
.. A type ``T`` belongs to the *set of value types* of ``X``
if, for an object ``v`` of type ``T``, ``*a = v`` is valid.
** This appears to be a mutual recursion which ends up meaning
nothing. Kill the assertion column?
Separate but related question: Is a writable iterator required
to have a meaningful value_type? If not, we need to use a
different name from ``v`` in this table -DWA
+------------------------------------------------------------------------------------------------------------------------------+
| Writable Iterator Requirements (in addition to CopyConstructible) |
+--------------------------------------+------------------------------------------+--------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+======================================+==========================================+============================================+
| ``access_category<X>::type`` | Convertible to ``writable_iterator_tag`` | |
+--------------------------------------+------------------------------------------+--------------------------------------------+
| ``*a = v`` | | .. ** pre: The type of ``v`` is in the set |
| | | of value types of ``X`` |
+--------------------------------------+------------------------------------------+--------------------------------------------+
Swappable Iterators [lib.swappable.iterators]
---------------------------------------------
A class or built-in type ``X`` models the *Swappable Iterator* concept
if the following expressions are valid and respect the stated
semantics.
+------------------------------------------------------------------------------------------------+
| Swappable Iterator Requirements (in addition to CopyConstructible) |
+------------------------------------+-------------+---------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+====================================+=============+=============================================+
| ``iter_swap(a, b)`` | ``void`` | post: the pointed to values are exchanged |
+------------------------------------+-------------+---------------------------------------------+
[*Note:* An iterator that is a model of the *Readable* and *Writable Iterator* concepts
is also a model of *Swappable Iterator*. *--end note*]
Readable Lvalue Iterators [lib.readable.lvalue.iterators]
---------------------------------------------------------
The *Readable Lvalue Iterator* concept adds the requirement that the
``reference`` type be a reference to the value type of the iterator.
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Readable Lvalue Iterator Requirements (in addition to Readable Iterator) |
+------------------------------------+-------------------------------------------------+-----------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+====================================+=================================================+===========================================================+
| ``iterator_traits<X>::reference`` | ``T&`` | ``T`` is *cv* ``iterator_traits<X>::value_type`` where |
| | | *cv* is an optional cv-qualification |
+------------------------------------+-------------------------------------------------+-----------------------------------------------------------+
| ``access_category<X>::type`` | Convertible to ``readable_lvalue_iterator_tag`` | |
+------------------------------------+-------------------------------------------------+-----------------------------------------------------------+
Writable Lvalue Iterators [lib.writable.lvalue.iterators]
---------------------------------------------------------
The *Writable Lvalue Iterator* concept adds the requirement that the
``reference`` type be a non-const reference to the value type of the
iterator.
+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Writable Lvalue Iterator Requirements (in addition to Readable Lvalue Iterator) |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+======================================+==================================================+============================================================+
| ``iterator_traits<X>::reference`` | ``iterator_traits<X>::value_type&`` | |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
| ``access_category<X>::type`` | Convertible to ``writable_lvalue_iterator_tag`` | |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
Iterator Traversal Concepts [lib.iterator.traversal]
++++++++++++++++++++++++++++++++++++++++++++++++++++
In the tables below, ``X`` is an iterator type, ``a`` and ``b`` are
constant objects of type ``X``, ``r`` and ``s`` are mutable objects of
type ``X``, ``T`` is ``std::iterator_traits<X>::value_type``, and
``v`` is a constant object of type ``T``.
Incrementable Iterators [lib.incrementable.iterators]
-----------------------------------------------------
A class or built-in type ``X`` models the *Incrementable Iterator*
concept if the following expressions are valid and respect the stated
semantics.
+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible) |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition |
+======================================+==================================================+============================================================+
| ``++r`` | ``X&`` | ``&r == &++r`` |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
| ``r++`` | convertible to ``const X&`` | ``{ X tmp = r; ++r; return tmp; }`` |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
| ``traversal_category<X>::type`` | | Convertible to ``incrementable_iterator_tag`` |
+--------------------------------------+--------------------------------------------------+------------------------------------------------------------+
Single Pass Iterators [lib.single.pass.iterators]
-------------------------------------------------
A class or built-in type ``X`` models the *Single Pass Iterator*
concept if the following expressions are valid and respect the stated
semantics.
+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality Comparable) |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition/Semantics |
+==================================+=========================+=========================================================================================+
| ``++r`` | ``X&`` | pre: ``r`` is dereferenceable; post: ``r`` is dereferenceable or ``r`` is past-the-end |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------+
| ``a == b`` | convertible to ``bool`` | ``==`` is an equivalence relation over its domain |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------+
| ``a != b`` | convertible to ``bool`` | ``!(a == b)`` |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------+
| ``traversal_category<X>::type`` | | Convertible to ``single_pass_iterator_tag`` |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------+
Forward Traversal Iterators [lib.forward.traversal.iterators]
-------------------------------------------------------------
A class or built-in type ``X`` models the *Forward Traversal Iterator*
concept if the following expressions are valid and respect the stated
semantics.
+----------------------------------------------------------------------------------------------------------------------------------+
| Forward Traversal Iterator Requirements (in addition to Single Pass Iterator) |
+------------------------------------------+--------------+------------------------------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition/Semantics |
+==========================================+==============+========================================================================+
| ``X u;`` | ``X&`` | ``note: u may have a singular value.`` |
+------------------------------------------+--------------+------------------------------------------------------------------------+
| ``++r`` | ``X&`` | ``r == s`` and ``r`` is dereferenceable implies ``++r == ++s.`` |
+------------------------------------------+--------------+------------------------------------------------------------------------+
| ``iterator_traits<X>::difference_type`` | | A signed integral type representing the distance between iterators |
+------------------------------------------+--------------+------------------------------------------------------------------------+
| ``traversal_category<X>::type`` | | Convertible to ``forward_traversal_iterator_tag`` |
+------------------------------------------+--------------+------------------------------------------------------------------------+
Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]
-------------------------------------------------------------------------
A class or built-in type ``X`` models the *Bidirectional Traversal
Iterator* concept if the following expressions are valid and respect
the stated semantics.
+-------------------------------------------------------------------------------------------------------------+
|Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal Iterator) |
+-----------------------------------------+-------------+-----------------------------------------------------+
| Expression | Return Type | Assertion/Note/Precondition/Postcondition/Semantics |
+=========================================+=============+=====================================================+
| ``--r`` | ``X&`` |pre: there exists ``s`` such that ``r == ++s``. |
| | |post: ``s`` is dereferenceable. ``--(++r) == r``. |
| | |``--r == --s`` implies ``r == s``. ``&r == &--r``. |
+-----------------------------------------+-------------+-----------------------------------------------------+
|``r--`` |convertible |``{ X tmp = r; --r; return tmp; }`` |
| |to ``const | |
| |X&`` | |
+-----------------------------------------+-------------+-----------------------------------------------------+
| ``traversal_category<X>::type`` | | Convertible to |
| | | ``bidirectional_traversal_iterator_tag`` |
| | | |
+-----------------------------------------+-------------+-----------------------------------------------------+
Random Access Traversal Iterators [lib.random.access.traversal.iterators]
-------------------------------------------------------------------------
A class or built-in type ``X`` models the *Random Access Traversal
Iterator* concept if the following expressions are valid and respect
the stated semantics. In the table below, ``Distance`` is
``iterator_traits<X>::difference_type`` and ``n`` represents a
constant object of type ``Distance``.
+--------------------------------------------------------------------------------------------------------------------------------------------+
| Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal Iterator) |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
| Expression | Return Type | Operational Semantics | Assertion/Note/Pre/Post-condition |
+================================+=======================================+==========================+========================================+
|``r += n`` | ``X&`` |:: | |
| | | | |
| | | { | |
| | | Distance m = n; | |
| | | if (m >= 0) | |
| | | while (m--) | |
| | | ++r; | |
| | | else | |
| | | while (m++) | |
| | | --r; | |
| | | return r; | |
| | | } | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
| ``a + n``, ``n + a`` | ``X`` |``{ X tmp = a; return tmp | |
| | |+= n; }`` | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``r -= n`` | ``X&`` |``return r += -n`` | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a - n`` | ``X`` |``{ X tmp = a; return tmp | |
| | |-= n; }`` | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``b - a`` |``Distance`` |``a < b ? distance(a,b) : |pre: there exists a value ``n`` of |
| | |-distance(b,a)`` |``Distance`` such that ``a + n == b``. |
| | | |``b == a + (b - a)``. |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a[n]`` |convertible to T |``*(a + n)`` |pre: a is a `readable iterator`_ |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a[n] = v`` |convertible to T |``*(a + n) = v`` |pre: a is a `writable iterator`_ |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a < b`` |convertible to ``bool`` |``b - a > 0`` |``<`` is a total ordering relation |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a > b`` |convertible to ``bool`` |``b < a`` |``>`` is a total ordering relation |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a >= b`` |convertible to ``bool`` |``!(a < b)`` | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``a <= b`` |convertible to ``bool`` |``!(a > b)`` | |
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
|``traversal_category<X>::type`` | | |Convertible to |
| | | |``random_access_traversal_iterator_tag``|
+--------------------------------+---------------------------------------+--------------------------+----------------------------------------+
Addition to [lib.iterator.synopsis]
===================================
::
// lib.iterator.traits, traits and tags
template <class Iterator> struct access_category;
template <class Iterator> struct traversal_category;
template <class AccessTag, class TraversalTag>
struct iterator_tag : /* appropriate old category or categories */ {
typedef AccessTag access;
typedef TraversalTag traversal;
};
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct swappable_iterator_tag { };
struct readable_writable_iterator_tag
: virtual readable_iterator_tag
, virtual writable_iterator_tag
, virtual swappable_iterator_tag { };
struct readable_lvalue_iterator_tag { };
struct writable_lvalue_iterator_tag
: virtual public readable_writable_iterator_tag
, virtual public readable_lvalue_iterator_tag { };
struct incrementable_iterator_tag { };
struct single_pass_iterator_tag : incrementable_iterator_tag { };
struct forward_traversal_tag : single_pass_iterator_tag { };
struct bidirectional_traversal_tag : forward_traversal_tag { };
struct random_access_traversal_tag : bidirectional_traversal_tag { };
struct null_category_tag { };
struct input_output_iterator_tag : input_iterator_tag, output_iterator_tag {};
Addition to [lib.iterator.traits]
=================================
The ``iterator_tag`` class template is an iterator category tag that
encodes the access and traversal tags in addition to being compatible
with the original iterator tags. The ``iterator_tag`` class inherits
from one of the original iterator tags according to the following
pseudo-code.
::
inherit-category(access-tag, traversal-tag) =
if (access-tag is convertible to readable_lvalue_iterator_tag) {
if (traversal-tag is convertible to random_access_traversal_tag)
return random_access_iterator_tag;
else if (traversal-tag is convertible to bidirectional_traversal_tag)
return bidirectional_iterator_tag;
else if (traversal-tag is convertible to forward_traversal_tag)
return forward_iterator_tag;
else if (traversal-tag is convertible to single_pass_traversal_tag)
if (access-tag is convertible to writable_iterator_tag)
return input_output_iterator_tag;
else
return input_iterator_tag;
else if (access-tag is convertible to writable_iterator_tag)
return output_iterator_tag;
else
return null_category_tag;
} else if (access-tag is convertible to readable_writable_iterator_tag
and traversal-tag is convertible to single_pass_iterator_tag)
return input_output_iterator_tag;
else if (access-tag is convertible to readable_iterator_tag
and traversal-tag is convertible to single_pass_iterator_tag)
return input_iterator_tag;
else if (access-tag is convertible to writable_iterator_tag
and traversal-tag is convertible to incrementable_iterator_tag)
return output_iterator_tag;
else
return null_category_tag;
The ``access_category`` and ``traversal_category`` class templates are
traits classes. For iterators whose
``iterator_traits<Iter>::iterator_category`` type is ``iterator_tag``,
the ``access_category`` and ``traversal_category`` traits access the
``access`` and ``traversal`` member types within ``iterator_tag``.
For iterators whose ``iterator_traits<Iter>::iterator_category`` type
is not ``iterator_tag`` and instead is a tag convertible to one of the
original tags, the appropriate traversal and access tags is deduced.
The following pseudo-code describes the algorithm.
::
access-category(Iterator) =
cat = iterator_traits<Iterator>::iterator_category;
if (cat == iterator_tag<Access,Traversal>)
return Access;
else if (cat is convertible to forward_iterator_tag) {
if (iterator_traits<Iterator>::reference is a const reference)
return readable_lvalue_iterator_tag;
else
return writable_lvalue_iterator_tag;
} else if (cat is convertible to input_iterator_tag)
return readable_iterator_tag;
else if (cat is convertible to output_iterator_tag)
return writable_iterator_tag;
else
return null_category_tag;
traversal-category(Iterator) =
cat = iterator_traits<Iterator>::iterator_category;
if (cat == iterator_tag<Access,Traversal>)
return Traversal;
else if (cat is convertible to random_access_iterator_tag)
return random_access_traversal_tag;
else if (cat is convertible to bidirectional_iterator_tag)
return bidirectional_traversal_tag;
else if (cat is convertible to forward_iterator_tag)
return forward_traversal_tag;
else if (cat is convertible to input_iterator_tag)
return single_pass_iterator_tag;
else if (cat is convertible to output_iterator_tag)
return incrementable_iterator_tag;
else
return null_category_tag;
The following specializations provide the access and traversal
category tags for pointer types.
::
template <typename T>
struct access_category<const T*>
{
typedef readable_lvalue_iterator_tag type;
};
template <typename T>
struct access_category<T*>
{
typedef writable_lvalue_iterator_tag type;
};
template <typename T>
struct traversal_category<T*>
{
typedef random_access_traversal_tag type;
};
..
LocalWords: Abrahams Siek Witt const bool Sutter's WG int UL LI href Lvalue
LocalWords: ReadableIterator WritableIterator SwappableIterator cv pre iter
LocalWords: ConstantLvalueIterator MutableLvalueIterator CopyConstructible TR
LocalWords: ForwardTraversalIterator BidirectionalTraversalIterator lvalue
LocalWords: RandomAccessTraversalIterator dereferenceable Incrementable tmp
LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct
LocalWords: TraversalTag typename lvalues DWA Hmm JGS
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

+1
View File
@@ -0,0 +1 @@
unit-test ia1 : reverse_iterator.cpp : <sysinclude>../../.. <sysinclude>$(BOOST) ;
+16
View File
@@ -0,0 +1,16 @@
#include <boost/iterator/iterator_adaptors.hpp>
#include <boost/cstdlib.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
int x[] = { 1, 2, 3, 4 };
boost::reverse_iterator<int*, int, int&, int*,
boost::iterator_tag<boost::mutable_lvalue_iterator_tag, boost::random_access_traversal_tag>
, std::ptrdiff_t> first(x + 4), last(x);
std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
return 0;
}
-229
View File
@@ -1,229 +0,0 @@
// (C) Copyright David Abrahams and Jeremy Siek 2000-2001. Permission to copy,
// use, modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided "as is"
// without express or implied warranty, and with no claim as to its suitability
// for any purpose.
//
// See http://www.boost.org/libs/utility/counting_iterator.htm for documentation.
//
// Supplies:
//
// template <class Incrementable> class counting_iterator_traits;
// template <class Incrementable> class counting_iterator_policies;
//
// Iterator traits and policies for adapted iterators whose dereferenced
// value progresses through consecutive values of Incrementable when the
// iterator is derferenced.
//
// template <class Incrementable> struct counting_iterator_generator;
//
// A "type generator" whose nested type "type" is a counting iterator as
// described above.
//
// template <class Incrementable>
// typename counting_iterator_generator<Incrementable>::type
// make_counting_iterator(Incrementable);
//
// A function which produces an adapted counting iterator over values of
// Incrementable.
//
// Revision History
// 14 Feb 2001 Removed unnecessary typedefs from counting_iterator_traits
// (Jeremy Siek)
// 11 Feb 2001 Use BOOST_STATIC_CONSTANT (Dave Abrahams)
// 11 Feb 2001 Clean up after John Maddocks's (finally effective!) Borland
// fixes (David Abrahams).
// 10 Feb 2001 Use new iterator_adaptor<> interface (David Abrahams)
// 10 Feb 2001 Rolled in supposed Borland fixes from John Maddock, but not
// seeing any improvement yet (David Abrahams)
// 09 Feb 2001 Factored out is_numeric computation. Borland still
// unhappy :( (David Abrahams)
// 08 Feb 2001 Beginning of a failed attempt to appease Borland
// (David Abrahams)
// 07 Feb 2001 rename counting_iterator() -> make_counting_iterator()
// (David Abrahams)
// 04 Feb 2001 Added counting_iterator_generator; updated comments
// (David Abrahams)
// 24 Jan 2001 initial revision, based on Jeremy Siek's
// boost/pending/integer_range.hpp (David Abrahams)
#ifndef BOOST_COUNTING_ITERATOR_HPP_DWA20000119
# define BOOST_COUNTING_ITERATOR_HPP_DWA20000119
# include <boost/config.hpp>
# include <boost/detail/iterator.hpp>
# include <boost/iterator_adaptors.hpp>
# include <boost/type_traits.hpp>
# include <boost/detail/numeric_traits.hpp>
# include <boost/static_assert.hpp>
# include <boost/limits.hpp>
namespace boost {
namespace detail {
// Template class counting_iterator_traits_select -- choose an
// iterator_category and difference_type for a counting_iterator at
// compile-time based on whether or not it wraps an integer or an iterator,
// using "poor man's partial specialization".
template <bool is_integer> struct counting_iterator_traits_select;
// Incrementable is an iterator type
template <>
struct counting_iterator_traits_select<false>
{
template <class Incrementable>
struct traits
{
private:
typedef boost::detail::iterator_traits<Incrementable> x;
public:
typedef typename x::iterator_category iterator_category;
typedef typename x::difference_type difference_type;
};
};
// Incrementable is a numeric type
template <>
struct counting_iterator_traits_select<true>
{
template <class Incrementable>
struct traits
{
typedef typename
boost::detail::numeric_traits<Incrementable>::difference_type
difference_type;
typedef std::random_access_iterator_tag iterator_category;
};
};
// Template class distance_policy_select -- choose a policy for computing the
// distance between counting_iterators at compile-time based on whether or not
// the iterator wraps an integer or an iterator, using "poor man's partial
// specialization".
template <bool is_integer> struct distance_policy_select;
// A policy for wrapped iterators
template <>
struct distance_policy_select<false>
{
template <class Distance, class Incrementable>
struct policy {
static Distance distance(Incrementable x, Incrementable y)
{ return boost::detail::distance(x, y); }
};
};
// A policy for wrapped numbers
template <>
struct distance_policy_select<true>
{
template <class Distance, class Incrementable>
struct policy {
static Distance distance(Incrementable x, Incrementable y)
{ return numeric_distance(x, y); }
};
};
// Try to detect numeric types at compile time in ways compatible with the
// limitations of the compiler and library.
template <class T>
struct is_numeric {
// For a while, this wasn't true, but we rely on it below. This is a regression assert.
BOOST_STATIC_ASSERT(::boost::is_integral<char>::value);
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
# if defined(BOOST_HAS_LONG_LONG)
BOOST_STATIC_CONSTANT(bool,
value = (
std::numeric_limits<T>::is_specialized
| boost::is_same<T,long long>::value
| boost::is_same<T,unsigned long long>::value));
# else
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
# endif
# else
# if !defined(__BORLANDC__)
BOOST_STATIC_CONSTANT(bool, value = (
boost::is_convertible<int,T>::value && boost::is_convertible<T,int>::value));
# else
BOOST_STATIC_CONSTANT(bool, value = ::boost::is_arithmetic<T>::value);
# endif
# endif
};
// Compute the distance over arbitrary numeric and/or iterator types
template <class Distance, class Incrementable>
Distance any_distance(Incrementable start, Incrementable finish, Distance* = 0)
{
return distance_policy_select<(
is_numeric<Incrementable>::value)>::template
policy<Distance, Incrementable>::distance(start, finish);
}
} // namespace detail
template <class Incrementable>
struct counting_iterator_traits {
private:
typedef ::boost::detail::counting_iterator_traits_select<(
::boost::detail::is_numeric<Incrementable>::value
)> binder;
typedef typename binder::template traits<Incrementable> traits;
public:
typedef typename traits::difference_type difference_type;
typedef typename traits::iterator_category iterator_category;
};
template <class Incrementable>
struct counting_iterator_policies : public default_iterator_policies
{
template <class IteratorAdaptor>
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& i) const
{ return i.base(); }
template <class Iterator1, class Iterator2>
typename Iterator1::difference_type distance(
const Iterator1& x, const Iterator2& y) const
{
typedef typename Iterator1::difference_type difference_type;
return boost::detail::any_distance<difference_type>(
x.base(), y.base());
}
};
// A type generator for counting iterators
template <class Incrementable>
struct counting_iterator_generator
{
typedef typename boost::remove_const<
Incrementable
>::type value_type;
typedef counting_iterator_traits<value_type> traits;
typedef iterator_adaptor<
value_type
, counting_iterator_policies<value_type>
, value_type
, value_type const&
, value_type const*
, typename traits::iterator_category
, typename traits::difference_type
> type;
};
// Manufacture a counting iterator for an arbitrary incrementable type
template <class Incrementable>
inline typename counting_iterator_generator<Incrementable>::type
make_counting_iterator(Incrementable x)
{
typedef typename counting_iterator_generator<Incrementable>::type result_t;
return result_t(x);
}
} // namespace boost
#endif // BOOST_COUNTING_ITERATOR_HPP_DWA20000119
@@ -1,55 +0,0 @@
// (C) Copyright Jeremy Siek 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// Revision History:
// 27 Feb 2001 Jeremy Siek
// Initial checkin.
#ifndef BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
#define BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
#include <iterator>
namespace boost {
template <class UnaryFunction>
class function_output_iterator {
typedef function_output_iterator self;
public:
typedef std::output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
explicit function_output_iterator(const UnaryFunction& f = UnaryFunction())
: m_f(f) {}
struct output_proxy {
output_proxy(UnaryFunction& f) : m_f(f) { }
template <class T> output_proxy& operator=(const T& value) {
m_f(value);
return *this;
}
UnaryFunction& m_f;
};
output_proxy operator*() { return output_proxy(m_f); }
self& operator++() { return *this; }
self& operator++(int) { return *this; }
private:
UnaryFunction m_f;
};
template <class UnaryFunction>
inline function_output_iterator<UnaryFunction>
make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
return function_output_iterator<UnaryFunction>(f);
}
} // namespace boost
#endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
-426
View File
@@ -1,426 +0,0 @@
// (C) Copyright Jeremy Siek and David Abrahams 2000-2001. Permission to copy,
// use, modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided "as is"
// without express or implied warranty, and with no claim as to its suitability
// for any purpose.
//
// Revision History:
// 11 Feb 2001 Use new iterator_adaptor interface, Fixes for Borland.
// (Dave Abrahams)
// 04 Feb 2001 Support for user-defined iterator categories (Dave Abrahams)
// 30 Jan 2001 Initial Checkin (Dave Abrahams)
#ifndef BOOST_HALF_OPEN_RANGE_HPP_
# define BOOST_HALF_OPEN_RANGE_HPP_
# include <boost/counting_iterator.hpp>
# include <functional>
# include <cassert>
# include <boost/operators.hpp>
# include <string>
# include <stdexcept>
# include <iterator>
namespace boost {
namespace detail {
// Template class choose_finish -- allows us to maintain the invariant that
// start() <= finish() on half_open_range specializations that support random
// access.
#ifdef __MWERKS__
template <class T>
const T& choose_finish(const T&, const T& finish, std::input_iterator_tag)
{
return finish;
}
template <class T>
const T& choose_finish(const T&, const T& finish, std::output_iterator_tag)
{
return finish;
}
template <class T>
const T& choose_finish(const T& start, const T& finish, std::random_access_iterator_tag)
{
return finish < start ? start : finish;
}
#else
template <bool is_random_access> struct finish_chooser;
template <>
struct finish_chooser<false>
{
template <class T>
struct rebind
{
static T choose(const T&, const T& finish)
{ return finish; }
};
};
template <>
struct finish_chooser<true>
{
template <class T>
struct rebind
{
static T choose(const T& start, const T& finish)
{ return finish < start ? start : finish; }
};
};
template <class Category, class Incrementable>
struct choose_finish
{
static const Incrementable choose(const Incrementable& start, const Incrementable& finish)
{
return finish_chooser<(
::boost::is_convertible<Category*,std::random_access_iterator_tag*>::value
)>::template rebind<Incrementable>::choose(start, finish);
}
};
#endif
}
template <class Incrementable>
struct half_open_range
{
typedef typename counting_iterator_generator<Incrementable>::type iterator;
private: // utility type definitions
// Using iter_t prevents compiler confusion with boost::iterator
typedef typename counting_iterator_generator<Incrementable>::type iter_t;
typedef std::less<Incrementable> less_value;
typedef typename iter_t::iterator_category category;
typedef half_open_range<Incrementable> self;
public:
typedef iter_t const_iterator;
typedef typename iterator::value_type value_type;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::reference reference;
typedef typename iterator::reference const_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::pointer const_pointer;
// It would be nice to select an unsigned type, but this is appropriate
// since the library makes an attempt to select a difference_type which can
// hold the difference between any two iterators.
typedef typename iterator::difference_type size_type;
half_open_range(Incrementable start, Incrementable finish)
: m_start(start),
m_finish(
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(start, finish)
#else
detail::choose_finish(start, finish, category())
#endif
)
{}
// Implicit conversion from std::pair<Incrementable,Incrementable> allows us
// to accept the results of std::equal_range(), for example.
half_open_range(const std::pair<Incrementable,Incrementable>& x)
: m_start(x.first),
m_finish(
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(x.first, x.second)
#else
detail::choose_finish(x.first, x.second, category())
#endif
)
{}
half_open_range& operator=(const self& x)
{
m_start = x.m_start;
m_finish = x.m_finish;
return *this;
}
half_open_range& operator=(const std::pair<Incrementable,Incrementable>& x)
{
m_start = x.first;
m_finish =
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(x.first, x.second);
#else
detail::choose_finish(x.first, x.second, category();
#endif
}
iterator begin() const { return iterator(m_start); }
iterator end() const { return iterator(m_finish); }
Incrementable front() const { assert(!this->empty()); return m_start; }
Incrementable back() const { assert(!this->empty()); return boost::prior(m_finish); }
Incrementable start() const { return m_start; }
Incrementable finish() const { return m_finish; }
size_type size() const { return boost::detail::distance(begin(), end()); }
bool empty() const
{
return m_finish == m_start;
}
void swap(half_open_range& x) {
std::swap(m_start, x.m_start);
std::swap(m_finish, x.m_finish);
}
public: // functions requiring random access elements
// REQUIRES: x is reachable from this->front()
bool contains(const value_type& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return !less_value()(x, m_start) && less_value()(x, m_finish);
}
bool contains(const half_open_range& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return x.empty() || !less_value()(x.m_start, m_start) && !less_value()(m_finish, x.m_finish);
}
bool intersects(const half_open_range& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return less_value()(
less_value()(this->m_start, x.m_start) ? x.m_start : this->m_start,
less_value()(this->m_finish, x.m_finish) ? this->m_finish : x.m_finish);
}
half_open_range& operator&=(const half_open_range& x)
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
if (less_value()(this->m_start, x.m_start))
this->m_start = x.m_start;
if (less_value()(x.m_finish, this->m_finish))
this->m_finish = x.m_finish;
if (less_value()(this->m_finish, this->m_start))
this->m_start = this->m_finish;
return *this;
}
half_open_range& operator|=(const half_open_range& x)
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
if (!x.empty())
{
if (this->empty())
{
*this = x;
}
else
{
if (less_value()(x.m_start, this->m_start))
this->m_start = x.m_start;
if (less_value()(this->m_finish, x.m_finish))
this->m_finish = x.m_finish;
}
}
return *this;
}
// REQUIRES: x is reachable from this->front()
const_iterator find(const value_type& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return const_iterator(this->contains(x) ? x : m_finish);
}
// REQUIRES: index >= 0 && index < size()
value_type operator[](size_type index) const
{
assert(index >= 0 && index < size());
return m_start + index;
}
value_type at(size_type index) const
{
if (index < 0 || index >= size())
throw std::out_of_range(std::string("half_open_range"));
return m_start + index;
}
private: // data members
Incrementable m_start, m_finish;
};
template <class Incrementable>
half_open_range<Incrementable> operator|(
half_open_range<Incrementable> x,
const half_open_range<Incrementable>& y)
{
return x |= y;
}
template <class Incrementable>
half_open_range<Incrementable> operator&(
half_open_range<Incrementable> x,
const half_open_range<Incrementable>& y)
{
return x &= y;
}
template <class Incrementable>
inline bool operator==(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
const bool y_empty = y.empty();
return x.empty() ? y_empty : !y_empty && x.start() == y.start() && x.finish() == y.finish();
}
template <class Incrementable>
inline bool operator!=(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(x == y);
}
template <class Incrementable>
inline half_open_range<Incrementable>
make_half_open_range(Incrementable first, Incrementable last)
{
return half_open_range<Incrementable>(first, last);
}
template <class Incrementable>
bool intersects(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return x.intersects(y);
}
template <class Incrementable>
bool contains(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return x.contains(y);
}
} // namespace boost
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace std {
template <class Incrementable> struct less<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
less<Incrementable> cmp;
return !y.empty() && (
cmp(x.start(), y.start())
|| !cmp(y.start(), x.start())
&& cmp(x.finish(), y.finish()));
}
};
template <class Incrementable> struct less_equal<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return !cmp(y,x);
}
};
template <class Incrementable> struct greater<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return cmp(y,x);
}
};
template <class Incrementable> struct greater_equal<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return !cmp(x,y);
}
};
} // namespace std
#else
namespace boost {
// Can't partially specialize std::less et al, so we must provide the operators
template <class Incrementable>
bool operator<(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !y.empty() && (
x.empty() || std::less<Incrementable>()(x.start(), y.start())
|| !std::less<Incrementable>()(y.start(), x.start())
&& std::less<Incrementable>()(x.finish(), y.finish()));
}
template <class Incrementable>
bool operator>(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return y < x;
}
template <class Incrementable>
bool operator<=(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(y < x);
}
template <class Incrementable>
bool operator>=(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(x < y);
}
} // namespace boost
#endif
#endif // BOOST_HALF_OPEN_RANGE_HPP_
-60
View File
@@ -1,60 +0,0 @@
// interator.hpp workarounds for non-conforming standard libraries ---------//
// (C) Copyright Boost.org 2000. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// See http://www.boost.org/libs/utility for documentation.
// Revision History
// 12 Jan 01 added <cstddef> for std::ptrdiff_t (Jens Maurer)
// 28 Jun 00 Workarounds to deal with known MSVC bugs (David Abrahams)
// 26 Jun 00 Initial version (Jeremy Siek)
#ifndef BOOST_ITERATOR_HPP
#define BOOST_ITERATOR_HPP
#include <iterator>
#include <cstddef> // std::ptrdiff_t
#include <boost/config.hpp>
namespace boost
{
# if defined(BOOST_NO_STD_ITERATOR) && !defined(BOOST_MSVC_STD_ITERATOR)
template <class Category, class T,
class Distance = std::ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator
{
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
# else
// declare iterator_base in namespace detail to work around MSVC bugs which
// prevent derivation from an identically-named class in a different namespace.
namespace detail {
template <class Category, class T, class Distance, class Pointer, class Reference>
# if !defined(BOOST_MSVC_STD_ITERATOR)
struct iterator_base : std::iterator<Category, T, Distance, Pointer, Reference> {};
# else
struct iterator_base : std::iterator<Category, T, Distance>
{
typedef Reference reference;
typedef Pointer pointer;
typedef Distance difference_type;
};
# endif
}
template <class Category, class T, class Distance = std::ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator : detail::iterator_base<Category, T, Distance, Pointer, Reference> {};
# endif
} // namespace boost
#endif // BOOST_ITERATOR_HPP
+193
View File
@@ -0,0 +1,193 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef COUNTING_ITERATOR_DWA200348_HPP
# define COUNTING_ITERATOR_DWA200348_HPP
# include <boost/iterator/iterator_adaptor.hpp>
# include <boost/detail/numeric_traits.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/identity.hpp>
# include <boost/mpl/apply_if.hpp>
namespace boost {
template <class Incrementable, class Category, class Difference> class counting_iterator;
namespace detail
{
// Try to detect numeric types at compile time in ways compatible
// with the limitations of the compiler and library.
template <class T>
struct is_numeric_impl
{
// For a while, this wasn't true, but we rely on it below. This is a regression assert.
BOOST_STATIC_ASSERT(::boost::is_integral<char>::value);
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
# if defined(BOOST_HAS_LONG_LONG)
BOOST_STATIC_CONSTANT(
bool, value = (
std::numeric_limits<T>::is_specialized
| boost::is_same<T,long long>::value
| boost::is_same<T,unsigned long long>::value
));
# else
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
# endif
# else
# if !defined(__BORLANDC__)
BOOST_STATIC_CONSTANT(
bool, value = (
boost::is_convertible<int,T>::value
&& boost::is_convertible<T,int>::value
));
# else
BOOST_STATIC_CONSTANT(bool, value = ::boost::is_arithmetic<T>::value);
# endif
# endif
};
template <class T>
struct is_numeric
: mpl::bool_<(::boost::detail::is_numeric_impl<T>::value)>
{};
template <class T>
struct numeric_difference
{
typedef typename boost::detail::numeric_traits<T>::difference_type type;
};
BOOST_STATIC_ASSERT(is_numeric<int>::value);
template <class Incrementable, class Category, class Difference>
struct counting_iterator_base
{
typedef typename mpl::apply_if<
is_same<Category, use_default>
, mpl::apply_if<
is_numeric<Incrementable>
, mpl::identity<std::random_access_iterator_tag>
, BOOST_ITERATOR_CATEGORY<Incrementable>
>
, mpl::identity<Category>
>::type category;
typedef typename mpl::apply_if<
is_same<Difference, use_default>
, mpl::apply_if<
is_numeric<Incrementable>
, numeric_difference<Incrementable>
, iterator_difference<Incrementable>
>
, mpl::identity<Difference>
>::type difference;
typedef iterator_adaptor<
counting_iterator<Incrementable, Category, Difference> // self
, Incrementable // Base
, Incrementable // value_type
, category
, Incrementable const& // reference
, difference
> type;
};
// Template class distance_policy_select -- choose a policy for computing the
// distance between counting_iterators at compile-time based on whether or not
// the iterator wraps an integer or an iterator, using "poor man's partial
// specialization".
template <bool is_integer> struct distance_policy_select;
// A policy for wrapped iterators
template <class Difference, class Incrementable1, class Incrementable2>
struct iterator_distance
{
static Difference distance(Incrementable1 x, Incrementable2 y)
{
return boost::detail::distance(x, y);
}
};
// A policy for wrapped numbers
template <class Difference, class Incrementable1, class Incrementable2>
struct number_distance
{
static Difference distance(Incrementable1 x, Incrementable2 y)
{
return numeric_distance(x, y);
}
};
}
template <class Incrementable, class Category = use_default, class Difference = use_default>
class counting_iterator
: public detail::counting_iterator_base<Incrementable, Category, Difference>::type
{
typedef typename detail::counting_iterator_base<Incrementable, Category, Difference>::type super_t;
friend class iterator_core_access;
public:
typedef typename super_t::difference_type difference_type;
counting_iterator() { }
counting_iterator(counting_iterator const& rhs) : super_t(rhs.base()) {}
counting_iterator(Incrementable x)
: super_t(x)
{
}
# if 0
template<class OtherIncrementable>
counting_iterator(
counting_iterator<OtherIncrementable> const& t
, typename enable_if_convertible<OtherIncrementable, Incrementable>::type* = 0
)
: super_t(t.base())
{}
# endif
private:
typename super_t::reference dereference() const
{
return this->base_reference();
}
template <class OtherIncrementable>
difference_type
distance_to(counting_iterator<OtherIncrementable> const& y) const
{
typedef typename mpl::if_<
detail::is_numeric<Incrementable>
, detail::number_distance<difference_type, Incrementable, OtherIncrementable>
, detail::iterator_distance<difference_type, Incrementable, OtherIncrementable>
>::type d;
return d::distance(this->base(), y.base());
}
};
// Manufacture a counting iterator for an arbitrary incrementable type
template <class Incrementable>
inline counting_iterator<Incrementable>
make_counting_iterator(Incrementable x)
{
typedef counting_iterator<Incrementable> result_t;
return result_t(x);
}
} // namespace boost::iterator
#endif // COUNTING_ITERATOR_DWA200348_HPP
@@ -0,0 +1,338 @@
// (C) Copyright Thomas Witt 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ITERATOR_DETAIL_CATEGORIES_HPP
# define BOOST_ITERATOR_DETAIL_CATEGORIES_HPP
# include <boost/config.hpp>
# include <boost/iterator/detail/config_def.hpp>
# include <boost/detail/workaround.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/apply_if.hpp>
# include <boost/mpl/identity.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/mpl/or.hpp>
# include <boost/mpl/and.hpp>
# include <iterator>
namespace boost
{
// faked new old-style categories needed to make new->old mapping
// work
namespace detail
{
struct null_category_tag {};
struct input_output_iterator_tag : std::input_iterator_tag, std::output_iterator_tag {};
}
//
// Access Categories
//
struct readable_iterator_tag
{
typedef std::input_iterator_tag max_category;
};
struct writable_iterator_tag
{
typedef std::output_iterator_tag max_category;
};
struct swappable_iterator_tag
{
typedef detail::null_category_tag max_category;
};
struct readable_writable_iterator_tag
: virtual readable_iterator_tag
, virtual writable_iterator_tag
, virtual swappable_iterator_tag
{
typedef detail::input_output_iterator_tag max_category;
};
struct readable_lvalue_iterator_tag
: virtual readable_iterator_tag
{
typedef std::random_access_iterator_tag max_category;
};
struct writable_lvalue_iterator_tag
: virtual public readable_writable_iterator_tag
, virtual public readable_lvalue_iterator_tag
{
typedef std::random_access_iterator_tag max_category;
};
//
// Traversal Categories
//
struct incrementable_traversal_tag
{
typedef std::output_iterator_tag max_category;
};
struct single_pass_traversal_tag
: incrementable_traversal_tag
{
typedef detail::input_output_iterator_tag max_category;
};
struct forward_traversal_tag
: single_pass_traversal_tag
{
typedef std::forward_iterator_tag max_category;
};
struct bidirectional_traversal_tag
: forward_traversal_tag
{
typedef std::bidirectional_iterator_tag max_category;
};
struct random_access_traversal_tag
: bidirectional_traversal_tag
{
typedef std::random_access_iterator_tag max_category;
};
struct error_iterator_tag { };
namespace detail
{
//
// Tag detection meta functions
//
// I bet this is defined somewhere else. Let's wait and see.
struct error_type;
# ifndef BOOST_NO_IS_CONVERTIBLE
// True iff T is a tag "derived" from Tag
template <class Tag, class T>
struct is_tag
: mpl::or_<
is_convertible<T, Tag>
// Because we can't actually get forward_iterator_tag to
// derive from input_output_iterator_tag, we need this
// case.
, mpl::and_<
is_convertible<T,std::forward_iterator_tag>
, is_convertible<detail::input_output_iterator_tag,Tag>
>
>
{};
# else
template <class Tag, class T>
struct is_tag;
# endif
// Generate specializations which will allow us to find
// null_category_tag as a minimum old-style category for new-style
// iterators which don't have an actual old-style category. We
// need that so there is a valid base class for all new-style
// iterators.
# define BOOST_OLD_ITERATOR_CATEGORY(category) \
template <> \
struct is_tag <detail::null_category_tag, std::category> \
: mpl::true_ {};
BOOST_OLD_ITERATOR_CATEGORY(input_iterator_tag)
BOOST_OLD_ITERATOR_CATEGORY(output_iterator_tag)
BOOST_OLD_ITERATOR_CATEGORY(forward_iterator_tag)
BOOST_OLD_ITERATOR_CATEGORY(bidirectional_iterator_tag)
BOOST_OLD_ITERATOR_CATEGORY(random_access_iterator_tag)
# undef BOOST_OLD_ITERATOR_CATEGORY
template <>
struct is_tag<detail::input_output_iterator_tag,std::forward_iterator_tag>
: mpl::true_
{
};
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
struct is_tag<T,T> : mpl::true_
{};
# ifdef BOOST_NO_IS_CONVERTIBLE
// Workarounds for CWPro7 which can't detect derivation at
// compile-time.
// Fact of life: we can only detect tag refinement relationships
// among predefined tags.
//
// Algorithm:
// is_tag(T,U) ->
// T == U
// || (exists d in derived_from(T) such that is_tag(d, U))
//
// T == U case is handled above
// false by default
template <class Tag, class T>
struct is_tag_impl : mpl::false_
{};
// The generalized template dispatches to is_tag_impl because
// is_tag<T,T> and is_tag<some_tag,T> are equally specialized.
// This technique simulates making is_tag<T,T> more-specialized.
template <class Tag, class T>
struct is_tag
: is_tag_impl<Tag, T>
{};
# define BOOST_ITERATOR_DERIVED_TAG1(base, derived) \
BOOST_ITERATOR_DERIVED_TAG1_AUX(base, _, derived)
# define BOOST_ITERATOR_DERIVED_TAG1_AUX(base, underscore, derived) \
template<class T> \
struct is_tag_impl<base##underscore##tag, T> \
: is_tag<derived##underscore##tag, T> \
{ \
};
// Old-style tag relations
template<class T>
struct is_tag_impl<detail::null_category_tag, T>
: mpl::or_<
is_tag<std::output_iterator_tag, T>
, is_tag<std::input_iterator_tag, T>
>
{
};
BOOST_ITERATOR_DERIVED_TAG1(std::output_iterator, detail::input_output_iterator)
BOOST_ITERATOR_DERIVED_TAG1(std::input_iterator, detail::input_output_iterator)
BOOST_ITERATOR_DERIVED_TAG1(detail::input_output_iterator, std::forward_iterator)
BOOST_ITERATOR_DERIVED_TAG1(std::forward_iterator, std::bidirectional_iterator)
BOOST_ITERATOR_DERIVED_TAG1(std::bidirectional_iterator, std::random_access_iterator)
// Access tag relations
BOOST_ITERATOR_DERIVED_TAG1(readable_lvalue_iterator, writable_lvalue_iterator)
BOOST_ITERATOR_DERIVED_TAG1(swappable_iterator, readable_writable_iterator)
BOOST_ITERATOR_DERIVED_TAG1(readable_writable_iterator, writable_lvalue_iterator)
template<class T>
struct is_tag_impl<readable_iterator_tag, T>
: mpl::or_<
is_tag<readable_lvalue_iterator_tag, T>
, is_tag<readable_writable_iterator_tag, T>
>
{
};
BOOST_ITERATOR_DERIVED_TAG1(writable_iterator, readable_writable_iterator)
// Traversal tag relations
BOOST_ITERATOR_DERIVED_TAG1(bidirectional_traversal, random_access_traversal)
BOOST_ITERATOR_DERIVED_TAG1(forward_traversal, bidirectional_traversal)
BOOST_ITERATOR_DERIVED_TAG1(single_pass_traversal, forward_traversal)
BOOST_ITERATOR_DERIVED_TAG1(incrementable_traversal, single_pass_traversal)
# endif // BOOST_NO_IS_CONVERTIBLE workarounds
# endif // ndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Tag, class Known, class Else>
struct known_tag
: mpl::apply_if<is_tag<Known,Tag>, mpl::identity<Known>, Else>
{};
template <class Tag>
struct max_known_traversal_tag
: known_tag<
Tag, random_access_traversal_tag
, known_tag<
Tag, bidirectional_traversal_tag
, known_tag<
Tag, forward_traversal_tag
, known_tag<
Tag, single_pass_traversal_tag
, known_tag<
Tag, incrementable_traversal_tag
, error_iterator_tag
>
>
>
>
>
{};
// Doesn't cope with these odd combinations: readable+swappable,
// writable+swappable. That doesn't matter for the sake of
// new-style tag base computation, which is all it's used for
// anyway.
template <class Tag>
struct max_known_access_tag
: known_tag<
Tag, writable_lvalue_iterator_tag
, known_tag<
Tag, readable_lvalue_iterator_tag
, known_tag<
Tag, readable_writable_iterator_tag
, known_tag<
Tag, writable_iterator_tag
, known_tag<
Tag, readable_iterator_tag
, mpl::apply_if<
is_tag<Tag, swappable_iterator_tag>
, mpl::identity<null_category_tag>
, error_iterator_tag
>
>
>
>
>
>
{};
//
// Returns the minimum category type or error_type
// if T1 and T2 are unrelated.
//
// For compilers not supporting is_convertible this only
// works with the new boost return and traversal category
// types. The exact boost _types_ are required. No derived types
// will work.
//
//
template <class T1, class T2>
struct minimum_category
: mpl::apply_if<
is_tag<T1,T2>
, mpl::identity<T1>
, mpl::if_<
is_tag<T2, T1>
, T2
, error_type
>
>
{};
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
// Deal with ETI
template <> struct minimum_category<int, int> { typedef minimum_category type; };
# endif
} // namespace detail
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ITERATOR_DETAIL_CATEGORIES_HPP
@@ -0,0 +1,104 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// no include guard multiple inclusion intended
//
// This is a temporary workaround until the bulk of this is
// available in boost config.
// 23/02/03 thw
//
#include <boost/config.hpp> // for prior
#include <boost/detail/workaround.hpp>
#define BOOST_ITERATOR_CONFIG_DEF // if you get an error here, you have nested config_def #inclusion.
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|| BOOST_WORKAROUND(__GNUC__, <= 2 && __GNUC_MINOR__ <= 95) \
|| BOOST_WORKAROUND(__MWERKS__, <= 0x3000) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_NO_SFINAE // "Substitution Failure Is Not An Error not implemented"
# if 0 // test code
template <bool x>
struct bar
{
typedef int type;
};
template <>
struct bar<false>
{
};
template <class T>
struct foo : bar<(sizeof(T) == 1)>
{
};
template <class T>
char* f(int, typename foo<T>::type = 0) { return 0; }
template <class T>
int f(...) { return 0; }
char* x = f<char>(0);
int y = f<char[2]>(0);
int main()
{
return 0;
}
# endif
#endif
#if BOOST_WORKAROUND(__MWERKS__, <=0x2407)
# define BOOST_NO_IS_CONVERTIBLE // "is_convertible doesn't work for simple types"
#endif
#if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_NO_IS_CONVERTIBLE_TEMPLATE // The following program fails to compile:
# if 0 // test code
template <class T>
struct foo
{
foo(T);
template <class U>
foo(foo<U> const& other) : p(other.p) { }
T p;
};
bool x = boost::is_convertible<foo<int const*>, foo<int*> >::value;
# endif
#endif
#if BOOST_WORKAROUND(__GNUC__, == 2 && __GNUC_MINOR__ == 95) \
|| BOOST_WORKAROUND(__MWERKS__, <= 0x2407) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_ITERATOR_NO_MPL_AUX_HAS_XXX // "MPL's has_xxx facility doesn't work"
#endif
#if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_IS_CONVERTIBLE_TEMPLATE)
# define BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
#endif
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# define BOOST_ARG_DEPENDENT_TYPENAME typename
# else
# define BOOST_ARG_DEPENDENT_TYPENAME
# endif
// no include guard multiple inclusion intended
@@ -0,0 +1,26 @@
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// no include guard multiple inclusion intended
//
// This is a temporary workaround until the bulk of this is
// available in boost config.
// 23/02/03 thw
//
#undef BOOST_NO_SFINAE
#undef BOOST_NO_IS_CONVERTIBLE
#undef BOOST_NO_IS_CONVERTIBLE_TEMPLATE
#undef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
#undef BOOST_ARG_DEPENDENT_TYPENAME
#ifdef BOOST_ITERATOR_CONFIG_DEF
# undef BOOST_ITERATOR_CONFIG_DEF
#else
# error missing or nested #include config_def
#endif
@@ -0,0 +1,88 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ENABLE_IF_23022003THW_HPP
#define BOOST_ENABLE_IF_23022003THW_HPP
#include <boost/detail/workaround.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/iterator/detail/config_def.hpp>
//
// Boost iterators uses its own enable_if cause we need
// special semantics for deficient compilers.
// 23/02/03 thw
//
namespace boost
{
namespace detail
{
//
// Base machinery for all kinds of enable if
//
template<bool>
struct enabled
{
template<typename T>
struct base
{
typedef T type;
};
};
//
// For compilers that don't support "Substitution Failure Is Not An Error"
// enable_if falls back to always enabled. See comments
// on operator implementation for consequences.
//
template<>
struct enabled<false>
{
template<typename T>
struct base
{
#ifdef BOOST_NO_SFINAE
typedef T type;
// This way to do it would give a nice error message containing
// invalid overload, but has the big disadvantage that
// there is no reference to user code in the error message.
//
// struct invalid_overload;
// typedef invalid_overload type;
//
#endif
};
};
template <class Cond,
class Return>
struct enable_if
# if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
: enabled<(Cond::value)>::template base<Return>
# else
: mpl::identity<Return>
# endif
{
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
typedef Return type;
# endif
};
} // namespace detail
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ENABLE_IF_23022003THW_HPP
+109
View File
@@ -0,0 +1,109 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_FILTER_ITERATOR_23022003THW_HPP
#define BOOST_FILTER_ITERATOR_23022003THW_HPP
#include <boost/iterator.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_categories.hpp>
namespace boost
{
namespace detail
{
template <class Iterator>
struct filter_iterator_category
{
typedef iterator_tag<
typename access_category<Iterator>::type
, typename minimum_category<
bidirectional_traversal_tag
, typename traversal_category<Iterator>::type
>::type
> type;
};
} // namespace detail
template <class Predicate, class Iterator>
class filter_iterator
: public iterator_adaptor<
filter_iterator<Predicate, Iterator>, Iterator
, use_default
, typename detail::filter_iterator_category<Iterator>::type
>
{
typedef iterator_adaptor<
filter_iterator<Predicate, Iterator>, Iterator
, use_default
, typename detail::filter_iterator_category<Iterator>::type
> super_t;
friend class iterator_core_access;
public:
filter_iterator() { }
filter_iterator(Predicate f, Iterator x, Iterator end = Iterator())
: super_t(x), m_predicate(f), m_end(end)
{
satisfy_predicate();
}
filter_iterator(Iterator x, Iterator end = Iterator())
: super_t(x), m_predicate(), m_end(end)
{
satisfy_predicate();
}
template<class OtherIterator>
filter_iterator(
filter_iterator<Predicate, OtherIterator> const& t
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
)
: super_t(t.base()), m_predicate(t.predicate()), m_end(t.end()) {}
Predicate predicate() const { return m_predicate; }
Iterator end() const { return m_end; }
private:
void increment()
{
++(this->base_reference());
satisfy_predicate();
}
void decrement()
{
while(!this->m_predicate(*--(this->base_reference()))){};
}
void satisfy_predicate()
{
while (this->base() != this->m_end && !this->m_predicate(*this->base()))
++(this->base_reference());
}
// Probably should be the initial base class so it can be
// optimized away via EBO if it is an empty class.
Predicate m_predicate;
Iterator m_end;
};
template <class Predicate, class Iterator>
filter_iterator<Predicate,Iterator>
make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator())
{
return filter_iterator<Predicate,Iterator>(f,x,end);
}
} // namespace boost
#endif // BOOST_FILTER_ITERATOR_23022003THW_HPP
@@ -0,0 +1,220 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP
#define BOOST_INDIRECT_ITERATOR_23022003THW_HPP
#include <boost/iterator.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/python/detail/indirect_traits.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/aux_/has_xxx.hpp>
#ifdef BOOST_NO_MPL_AUX_HAS_XXX
# include <boost/shared_ptr.hpp>
# include <boost/scoped_ptr.hpp>
# include <boost/mpl/bool.hpp>
# include <memory>
#endif
#include <boost/iterator/detail/config_def.hpp> // must be last #include
namespace boost
{
template <class Iter, class Value, class Category, class Reference, class Difference>
struct indirect_iterator;
namespace detail
{
struct unspecified {};
//
// Detection for whether a type has a nested `element_type'
// typedef. Used to detect smart pointers. For compilers not
// supporting mpl's has_xxx, we supply specializations. However, we
// really ought to have a specializable is_pointer template which
// can be used instead with something like
// boost/python/pointee.hpp to find the value_type.
//
# ifndef BOOST_NO_MPL_AUX_HAS_XXX
namespace aux
{
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
}
template <class T>
struct has_element_type
: mpl::bool_<
mpl::if_<
is_class<T>
, ::boost::detail::aux::has_element_type<T>
, mpl::false_
>::type::value
>
{
};
# else
template <class T>
struct has_element_type
: mpl::false_ {};
template <class T>
struct has_element_type<boost::shared_ptr<T> >
: mpl::true_ {};
template <class T>
struct has_element_type<boost::scoped_ptr<T> >
: mpl::true_ {};
template <class T>
struct has_element_type<std::auto_ptr<T> >
: mpl::true_ {};
# endif
// Metafunction returning the nested element_type typedef
template <class T>
struct smart_pointer_value : remove_const<typename T::element_type>
{};
template <class T>
struct iterator_is_mutable
: mpl::not_<
boost::python::detail::is_reference_to_const<
typename iterator_reference<T>::type
>
>
{
};
template <class T>
struct not_int_impl
{
template <class U>
struct apply {
typedef T type;
};
};
template <>
struct not_int_impl<int> {};
template <class T, class U>
struct not_int
: not_int_impl<T>::template apply<U> {};
// If the Value parameter is unspecified, we use this metafunction
// to deduce the default types
template <class Iter, class Value, class Category, class Reference, class Difference>
struct indirect_base
{
typedef typename iterator_value<Iter>::type dereferenceable;
typedef mpl::and_<
is_class<dereferenceable>
, has_element_type<dereferenceable>
> is_smart_ptr;
typedef typename mpl::apply_if<
is_smart_ptr
, smart_pointer_value<dereferenceable>
, iterator_value<dereferenceable>
>::type value_type;
typedef typename mpl::if_<
mpl::or_<
is_smart_ptr
, iterator_is_mutable<dereferenceable>
>
, value_type
, value_type const
>::type cv_value_type;
typedef iterator_adaptor<
indirect_iterator<Iter, Value, Category, Reference, Difference>
, Iter
, cv_value_type
, Category
, Reference
, Difference
> type;
};
template <>
struct indirect_base<int, int, int, int, int> {};
} // namespace detail
template <
class Iterator
, class Value = use_default
, class Category = use_default
, class Reference = use_default
, class Difference = use_default
>
class indirect_iterator
: public detail::indirect_base<
Iterator, Value, Category, Reference, Difference
>::type
{
typedef typename detail::indirect_base<
Iterator, Value, Category, Reference, Difference
>::type super_t;
friend class iterator_core_access;
public:
indirect_iterator() {}
indirect_iterator(Iterator iter)
: super_t(iter) {}
template <
class Iterator2, class Value2, class Category2
, class Reference2, class Difference2
>
indirect_iterator(
indirect_iterator<
Iterator2, Value2, Category2, Reference2, Difference2
> const& y
, typename enable_if_convertible<Iterator2, Iterator>::type* = 0
)
: super_t(y.base())
{}
private:
typename super_t::reference dereference() const
{
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
return const_cast<super_t::reference>(**this->base());
# else
return **this->base();
# endif
}
};
template <class Iter>
inline
indirect_iterator<Iter> make_indirect_iterator(Iter x)
{
return indirect_iterator<Iter>(x);
}
template <class Traits, class Iter>
inline
indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0)
{
return indirect_iterator<Iter, Traits>(x);
}
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP
+52
View File
@@ -0,0 +1,52 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_INTEROPERABLE_23022003THW_HPP
# define BOOST_INTEROPERABLE_23022003THW_HPP
# include <boost/mpl/bool.hpp>
# include <boost/mpl/or.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/iterator/detail/config_def.hpp> // must appear last
namespace boost
{
//
// Meta function that determines whether two
// iterator types are considered interoperable.
//
// Two iterator types A,B are considered interoperable if either
// A is convertible to B or vice versa.
// This interoperability definition is in sync with the
// standards requirements on constant/mutable container
// iterators (23.1 [lib.container.requirements]).
//
// For compilers that don't support is_convertible
// is_interoperable gives false positives. See comments
// on operator implementation for consequences.
//
template <typename A, typename B>
struct is_interoperable
# ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
: mpl::true_
# else
: mpl::or_<
is_convertible< A, B >
, is_convertible< B, A > >
# endif
{
};
} // namespace boost
# include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_INTEROPERABLE_23022003THW_HPP
+325
View File
@@ -0,0 +1,325 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ITERATOR_ADAPTOR_23022003THW_HPP
#define BOOST_ITERATOR_ADAPTOR_23022003THW_HPP
#include <boost/static_assert.hpp>
#include <boost/iterator.hpp>
#include <boost/detail/iterator.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/detail/enable_if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/or.hpp>
#include <boost/python/detail/is_xxx.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/iterator/detail/config_def.hpp>
#include <boost/iterator/iterator_traits.hpp>
namespace boost
{
namespace detail
{
//
// Result type used in enable_if_convertible meta function.
// This can be an incomplete type, as only pointers to
// enable_if_convertible< ... >::type are used.
// We could have used void for this, but conversion to
// void* is just to easy.
//
struct enable_type;
}
//
// enable_if for use in adapted iterators constructors.
//
// In order to provide interoperability between adapted constant and
// mutable iterators, adapted iterators will usually provide templated
// conversion constructors of the following form
//
// template <class BaseIterator>
// class adapted_iterator :
// public iterator_adaptor< adapted_iterator<Iterator>, Iterator >
// {
// public:
//
// ...
//
// template <class OtherIterator>
// adapted_iterator(
// OtherIterator const& it
// , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0);
//
// ...
// };
//
// enable_if_convertible is used to remove those overloads from the overload
// set that cannot be instantiated. For all practical purposes only overloads
// for constant/mutable interaction will remain. This has the advantage that
// meta functions like boost::is_convertible do not return false positives,
// as they can only look at the signature of the conversion constructor
// and not at the actual instantiation.
//
// enable_if_interoperable can be safely used in user code. It falls back to
// always enabled for compilers that don't support enable_if or is_convertible.
// There is no need for compiler specific workarounds in user code.
//
// The operators implementation relies on boost::is_convertible not returning
// false positives for user/library defined iterator types. See comments
// on operator implementation for consequences.
//
# if defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_SFINAE)
template <class From, class To>
struct enable_if_convertible
{
typedef detail::enable_type type;
};
# elif BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300
// For some reason vc7.1 needs us to "cut off" instantiation
// of is_convertible in a few cases.
template<typename From, typename To>
struct enable_if_convertible
: detail::enable_if<
mpl::or_<
is_same<From,To>
, is_convertible<From, To>
>
, detail::enable_type
>
{};
# else
template<typename From, typename To>
struct enable_if_convertible
: detail::enable_if<
is_convertible<From, To>
, detail::enable_type
>
{};
# endif
//
// Default template argument handling for iterator_adaptor
//
namespace detail
{
// If T is use_default, return the result of invoking
// DefaultNullaryFn, otherwise return T.
template <class T, class DefaultNullaryFn>
struct ia_dflt_help
: mpl::apply_if<
is_same<T, use_default>
, DefaultNullaryFn
, mpl::identity<T>
>
{
};
// A metafunction which computes an iterator_adaptor's base class,
// a specialization of iterator_facade.
template <
class Derived
, class Base
, class Value
, class Category
, class Reference
, class Difference
>
struct iterator_adaptor_base
{
private: // intermediate results
typedef typename detail::ia_dflt_help<
Category, BOOST_ITERATOR_CATEGORY<Base>
>::type category;
typedef typename detail::ia_dflt_help<
Reference
, mpl::apply_if<
is_same<Value, use_default>
, iterator_reference<Base>
, mpl::identity<Value&>
>
>::type reference;
public: // return type
typedef iterator_facade<
Derived
, typename detail::ia_dflt_help<
Value, iterator_value<Base>
>::type
, typename access_category_tag<category, reference>::type
, typename traversal_category_tag<category>::type
, reference
, typename detail::ia_dflt_help<
Difference, iterator_difference<Base>
>::type
>
type;
};
}
//
// Iterator Adaptor
//
// The parameter ordering changed slightly with respect to former
// versions of iterator_adaptor The idea is that when the user needs
// to fiddle with the reference type it is highly likely that the
// iterator category has to be adjusted as well. Any of the
// following four template arguments may be ommitted or explicitly
// replaced by use_default.
//
// Value - if supplied, the value_type of the resulting iterator, unless
// const. If const, a conforming compiler strips constness for the
// value_type. If not supplied, iterator_traits<Base>::value_type is used
//
// Category - the iterator_category of the resulting iterator. If not
// supplied, iterator_traits<Base>::iterator_category is used.
//
// Reference - the reference type of the resulting iterator, and in
// particular, the result type of operator*(). If not supplied but
// Value is supplied, Value& is used. Otherwise
// iterator_traits<Base>::reference is used.
//
// Difference - the difference_type of the resulting iterator. If not
// supplied, iterator_traits<Base>::difference_type is used.
//
template <
class Derived
, class Base
, class Value = use_default
, class Category = use_default
, class Reference = use_default
, class Difference = use_default
>
class iterator_adaptor
: public detail::iterator_adaptor_base<
Derived, Base, Value, Category, Reference, Difference
>::type
{
friend class iterator_core_access;
typedef typename detail::iterator_adaptor_base<
Derived, Base, Value, Category, Reference, Difference
>::type super_t;
public:
iterator_adaptor() {}
explicit iterator_adaptor(Base iter)
: m_iterator(iter)
{
}
Base base() const
{ return m_iterator; }
protected:
//
// lvalue access to the Base object for Derived
//
Base const& base_reference() const
{ return m_iterator; }
Base& base_reference()
{ return m_iterator; }
private:
//
// Core iterator interface for iterator_facade. This is private
// to prevent temptation for Derived classes to use it, which
// will often result in an error. Derived classes should use
// base_reference(), above, to get direct access to m_iterator.
//
typename super_t::reference dereference() const
{ return *m_iterator; }
template <
class OtherDerived, class OtherIterator, class V, class C, class R, class D
>
bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const
{
// Maybe readd with same_distance
// BOOST_STATIC_ASSERT(
// (detail::same_category_and_difference<Derived,OtherDerived>::value)
// );
return m_iterator == x.base();
}
void advance(typename super_t::difference_type n)
{
BOOST_STATIC_ASSERT(
(detail::is_tag<
random_access_traversal_tag
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
>::value)
);
m_iterator += n;
}
void increment() { ++m_iterator; }
void decrement()
{
BOOST_STATIC_ASSERT(
(detail::is_tag<
bidirectional_traversal_tag
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
>::value)
);
--m_iterator;
}
template <
class OtherDerived, class OtherIterator, class V, class C, class R, class D
>
typename super_t::difference_type distance_to(
iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const
{
BOOST_STATIC_ASSERT(
(detail::is_tag<
random_access_traversal_tag
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
>::value)
);
// Maybe readd with same_distance
// BOOST_STATIC_ASSERT(
// (detail::same_category_and_difference<Derived,OtherDerived>::value)
// );
return y.base() - m_iterator;
}
private: // data members
Base m_iterator;
};
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ITERATOR_ADAPTOR_23022003THW_HPP
@@ -0,0 +1,350 @@
// (C) Copyright Jeremy Siek 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ITERATOR_ARCHETYPES_HPP
#define BOOST_ITERATOR_ARCHETYPES_HPP
#include <boost/iterator/iterator_categories.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/operators.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/mpl/aux_/msvc_eti_base.hpp>
#include <cstddef>
namespace boost
{
template <class Value, class AccessCategory>
struct access_archetype;
template <class Derived, class Value, class AccessCategory, class TraversalCategory>
struct traversal_archetype;
namespace detail {
template <class T>
struct assign_proxy
{
assign_proxy& operator=(T);
};
template <class T>
struct read_write_proxy :
assign_proxy<T>
{
operator T();
};
template <class T>
struct arrow_proxy
{
T const* operator->() const;
};
struct no_operator_brackets {};
template <class ValueType>
struct readable_operator_brackets
{
ValueType operator[](std::ptrdiff_t n) const;
};
template <class ValueType>
struct writable_operator_brackets
{
read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const;
};
template <class Value, class AccessCategory, class TraversalCategory>
struct operator_brackets :
mpl::if_< is_tag<random_access_traversal_tag, TraversalCategory>,
mpl::if_< is_tag<writable_iterator_tag, AccessCategory>,
writable_operator_brackets< Value >,
mpl::if_< is_tag<readable_iterator_tag, AccessCategory>,
readable_operator_brackets<Value>,
no_operator_brackets > >,
no_operator_brackets >::type
{
};
template <class TraversalCategory>
struct traversal_archetype_impl
{
template <class Derived,class Value> struct archetype;
};
template <class Derived, class Value, class TraversalCategory>
struct traversal_archetype_
: mpl::aux::msvc_eti_base<
typename traversal_archetype_impl<TraversalCategory>::template archetype<Derived,Value>
>::type
{};
template <>
struct traversal_archetype_impl<incrementable_traversal_tag>
{
template<class Derived, class Value>
struct archetype
{
typedef void difference_type;
Derived& operator++();
Derived operator++(int) const;
};
};
template <>
struct traversal_archetype_impl<single_pass_traversal_tag>
{
template<class Derived, class Value>
struct archetype
: public equality_comparable< traversal_archetype_<Derived, Value, single_pass_traversal_tag> >,
public traversal_archetype_<Derived, Value, incrementable_traversal_tag>
{
};
};
template <class Derived, class Value>
bool operator==(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
// doesn't seem to pick up != from equality_comparable
template <class Derived, class Value>
bool operator!=(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
#endif
template <>
struct traversal_archetype_impl<forward_traversal_tag>
{
template<class Derived, class Value>
struct archetype
: public traversal_archetype_<Derived, Value, single_pass_traversal_tag>
{
typedef std::ptrdiff_t difference_type;
};
};
template <>
struct traversal_archetype_impl<bidirectional_traversal_tag>
{
template<class Derived, class Value>
struct archetype
: public traversal_archetype_<Derived, Value, forward_traversal_tag>
{
Derived& operator--();
Derived operator--(int) const;
};
};
template <>
struct traversal_archetype_impl<random_access_traversal_tag>
{
template<class Derived, class Value>
struct archetype
: public partially_ordered<traversal_archetype_<Derived, Value, random_access_traversal_tag> >,
public traversal_archetype_<Derived, Value, bidirectional_traversal_tag>
{
Derived& operator+=(std::ptrdiff_t);
Derived& operator-=(std::ptrdiff_t);
};
};
template <class Derived, class Value>
Derived& operator+(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
std::ptrdiff_t);
template <class Derived, class Value>
Derived& operator+(std::ptrdiff_t,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
template <class Derived, class Value>
Derived& operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
std::ptrdiff_t);
template <class Derived, class Value>
std::ptrdiff_t operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
template <class Derived, class Value>
bool operator<(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
struct bogus_type;
template <class Value>
struct convertible_type
: mpl::if_< is_const<Value>,
typename remove_const<Value>::type,
bogus_type >
{};
} // namespace detail
template <class> struct undefined;
template <class AccessCategory>
struct access_archetype_impl
{
template <class Value> struct archetype;
};
template <class Value, class AccessCategory>
struct access_archetype
: mpl::aux::msvc_eti_base<
typename access_archetype_impl<AccessCategory>::template archetype<Value>
>::type
{
};
template <>
struct access_archetype_impl<readable_iterator_tag>
{
template <class Value>
struct archetype
{
typedef typename remove_cv<Value>::type value_type;
typedef Value reference;
typedef Value* pointer;
value_type operator*() const;
detail::arrow_proxy<Value> operator->() const;
};
};
template <>
struct access_archetype_impl<writable_iterator_tag>
{
template <class Value>
struct archetype
{
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_STATIC_ASSERT(!is_const<Value>::value);
# endif
typedef void value_type;
typedef void reference;
typedef void pointer;
detail::assign_proxy<Value> operator*() const;
};
};
template <>
struct access_archetype_impl<readable_writable_iterator_tag>
{
template <class Value>
struct archetype
: public virtual access_archetype<Value, readable_iterator_tag>
{
typedef detail::read_write_proxy<Value> reference;
detail::read_write_proxy<Value> operator*() const;
};
};
template <>
struct access_archetype_impl<readable_lvalue_iterator_tag>
{
template <class Value>
struct archetype
: public virtual access_archetype<Value, readable_iterator_tag>
{
typedef Value& reference;
Value& operator*() const;
Value* operator->() const;
};
};
template <>
struct access_archetype_impl<writable_lvalue_iterator_tag>
{
template <class Value>
struct archetype
: public virtual access_archetype<Value, readable_lvalue_iterator_tag>
{
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_STATIC_ASSERT((!is_const<Value>::value));
# endif
};
};
template <class Value, class AccessCategory, class TraversalCategory>
struct iterator_archetype;
template <class Value, class AccessCategory, class TraversalCategory>
struct traversal_archetype_base
: detail::operator_brackets<
typename remove_cv<Value>::type
, AccessCategory
, TraversalCategory
>
, detail::traversal_archetype_<
iterator_archetype<Value, AccessCategory, TraversalCategory>
, Value
, TraversalCategory
>
{
};
template <class Value, class AccessCategory, class TraversalCategory>
struct iterator_archetype
: public traversal_archetype_base<Value, AccessCategory, TraversalCategory>
, public access_archetype<Value, AccessCategory>
// These broken libraries require derivation from std::iterator
// (or related magic) in order to handle iter_swap and other
// iterator operations
# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, < 310) \
|| BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(0x20101))
, public std::iterator<
iterator_tag<AccessCategory,TraversalCategory>
, typename access_archetype<Value, AccessCategory>::value_type
, typename traversal_archetype_base<
Value, AccessCategory, TraversalCategory
>::difference_type
>
# endif
{
// Derivation from std::iterator above caused ambiguity, so now
// we have to declare all the types here.
# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, < 310) \
|| BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(0x20101))
typedef typename access_archetype<Value, AccessCategory>::value_type value_type;
typedef typename access_archetype<Value, AccessCategory>::pointer pointer;
typedef typename access_archetype<Value, AccessCategory>::reference reference;
typedef typename traversal_archetype_base<
Value, AccessCategory, TraversalCategory
>::difference_type difference_type;
# endif
typedef iterator_tag<AccessCategory, TraversalCategory> iterator_category;
iterator_archetype();
iterator_archetype(iterator_archetype const&);
iterator_archetype& operator=(iterator_archetype const&);
// Optional conversion from mutable
// iterator_archetype(iterator_archetype<typename detail::convertible_type<Value>::type, AccessCategory, TraversalCategory> const&);
};
} // namespace boost
#endif // BOOST_ITERATOR_ARCHETYPES_HPP
@@ -0,0 +1,405 @@
// (C) Copyright Jeremy Siek 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// TODO:
// Add separate category tag for operator[].
#ifndef BOOST_ITERATOR_CATEGORIES_HPP
#define BOOST_ITERATOR_CATEGORIES_HPP
#include <boost/config.hpp>
#include <boost/iterator/detail/categories.hpp>
#include <boost/type_traits/conversion_traits.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/python/detail/indirect_traits.hpp>
#include <boost/detail/iterator.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/aux_/has_xxx.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/aux_/msvc_eti_base.hpp>
#include <iterator>
#include <boost/iterator/detail/config_def.hpp> // must be last #include
#if BOOST_WORKAROUND(__MWERKS__, <=0x2407)
# define BOOST_NO_IS_CONVERTIBLE // "Convertible does not provide enough/is not working"
#endif
namespace boost {
namespace detail
{
// Helper metafunction for std_category below
template <class Cat, class Tag, class Next>
struct match_tag
: mpl::apply_if<is_tag<Tag, Cat>, mpl::identity<Tag>, Next>
{
};
// Converts a possibly user-defined category tag to the
// most-derived standard tag which is a base of that tag.
template <class Category>
struct std_category
: match_tag<
Category, std::random_access_iterator_tag
, match_tag<Category, std::bidirectional_iterator_tag
, match_tag<Category, std::forward_iterator_tag
, match_tag<Category, std::input_iterator_tag
, match_tag<Category, std::output_iterator_tag
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
, mpl::identity<void>
# else
, void
# endif
>
>
>
>
>
{
};
// std_to_new_tags --
//
// A metafunction which converts any standard tag into its
// corresponding new-style traversal tag.
//
// Also, instantiations are metafunction classes which convert a
// reference type into a corresponding new-style access tag.
template <class Category> struct std_to_new_tags
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) // handle ETI
{
typedef void type;
template <class T> struct apply { typedef void type; };
}
# endif
;
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) // handle ETI
template <> struct std_to_new_tags<int> {};
# endif
//
// Specializations for specific standard tags
//
template <>
struct std_to_new_tags<std::input_iterator_tag>
{
typedef single_pass_traversal_tag type;
template <class Reference>
struct apply
: mpl::identity<readable_iterator_tag> {};
};
template <>
struct std_to_new_tags<std::output_iterator_tag>
{
typedef incrementable_traversal_tag type;
template <class Reference>
struct apply
: mpl::identity<writable_iterator_tag> {};
};
template <>
struct std_to_new_tags<std::forward_iterator_tag>
{
typedef forward_traversal_tag type;
template <class Reference>
struct apply
: mpl::if_<
python::detail::is_reference_to_const<Reference>
, boost::readable_lvalue_iterator_tag
, boost::writable_lvalue_iterator_tag
>
{};
};
template <>
struct std_to_new_tags<std::bidirectional_iterator_tag>
: std_to_new_tags<std::forward_iterator_tag>
{
typedef bidirectional_traversal_tag type;
};
template <>
struct std_to_new_tags<std::random_access_iterator_tag>
: std_to_new_tags<std::bidirectional_iterator_tag>
{
typedef random_access_traversal_tag type;
};
template <class Category>
struct old_tag_converter
: std_to_new_tags<
typename std_category<Category>::type
>
{
};
template <typename Category>
struct iter_category_to_traversal
: std_to_new_tags<
typename std_category<Category>::type
>
{};
template <typename Category, typename Reference>
struct iter_category_to_access
: mpl::apply1<
iter_category_to_traversal<Category>
, Reference
>
{};
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
// Deal with ETI
template <> struct iter_category_to_access<int, int> {};
template <> struct iter_category_to_traversal<int> {};
# endif
// A metafunction returning true iff T is boost::iterator_tag<R,U>
template <class T>
struct is_boost_iterator_tag;
#if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
//
// has_xxx fails, so we have to use
// something less sophisticated.
//
// The solution depends on the fact that only
// std iterator categories work with is_xxx_iterator
// meta functions, as BOOST_NO_IS_CONVERTIBLE is
// defined for cwpro7.
//
template <class Tag>
struct is_new_iterator_tag
: mpl::not_<
mpl::or_<
is_tag<std::input_iterator_tag, Tag>
, is_tag<std::output_iterator_tag, Tag>
>
>
{};
#elif BOOST_WORKAROUND(__GNUC__, == 2 && __GNUC_MINOR__ == 95) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template <class Tag>
struct is_new_iterator_tag
: is_boost_iterator_tag<Tag>
{
};
#else
BOOST_MPL_HAS_XXX_TRAIT_DEF(traversal)
template <class Tag>
struct is_new_iterator_tag
: mpl::if_<
is_class<Tag>
, has_traversal<Tag>
, mpl::false_
>::type
{
};
#endif
} // namespace detail
namespace detail {
template <class NewCategoryTag>
struct get_traversal_category {
typedef typename NewCategoryTag::traversal type;
};
// Remove all writability from the given access tag. This
// functionality is part of new_category_to_access in order to
// support deduction of the proper default access category for
// iterator_adaptor; when the reference type is a reference to
// constant we must strip writability.
template <class AccessTag>
struct remove_access_writability
: mpl::apply_if<
is_tag<writable_lvalue_iterator_tag, AccessTag>
, mpl::identity<readable_lvalue_iterator_tag>
, mpl::apply_if<
is_tag<readable_writable_iterator_tag, AccessTag>
, mpl::identity<readable_iterator_tag>
, mpl::if_<
is_tag<writable_iterator_tag, AccessTag>
// Is this OK? I think it may correct be for all
// legitimate cases, because at this point the
// iterator is not readable, so it could not have
// been any more than writable + swappable.
, swappable_iterator_tag
, AccessTag
>
>
>
{};
template <class NewCategoryTag, class Reference>
struct new_category_to_access
: mpl::apply_if<
python::detail::is_reference_to_const<Reference>
, remove_access_writability<typename NewCategoryTag::access>
, mpl::identity<typename NewCategoryTag::access>
>
{};
template <class CategoryTag, class Reference>
struct access_category_tag
: mpl::apply_if<
is_new_iterator_tag<CategoryTag>
, new_category_to_access<CategoryTag, Reference>
, iter_category_to_access<CategoryTag, Reference>
>
{
};
template <class CategoryTag>
struct traversal_category_tag
: mpl::apply_if<
is_new_iterator_tag<CategoryTag>
, get_traversal_category<CategoryTag>
, iter_category_to_traversal<CategoryTag>
>
{
};
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
// Deal with ETI
template <> struct access_category_tag<int, int> { typedef void type; };
template <> struct traversal_category_tag<int> { typedef void type; };
# endif
// iterator_tag_base - a metafunction to compute the appropriate
// old-style tag (if any) to use as a base for a new-style tag.
template <class KnownAccessTag, class KnownTraversalTag>
struct iterator_tag_base
: minimum_category<
typename KnownAccessTag::max_category
, typename KnownTraversalTag::max_category
>
{};
# if BOOST_WORKAROUND(BOOST_MSVC,<=1200)
template <>
struct iterator_tag_base<int,int>
: mpl::false_ {}; // just using false_ so that the result will be
// a legal base class
# endif
// specialization for this special case. Otherwise we get
// input_output_iterator_tag, because the standard hierarchy has a
// sudden anomalous distinction between readability and
// writability at the level of input iterator/output iterator.
template <>
struct iterator_tag_base<
readable_lvalue_iterator_tag,single_pass_traversal_tag>
{
typedef std::input_iterator_tag type;
};
} // namespace detail
template <class Iterator>
struct access_category
: detail::access_category_tag<
typename detail::iterator_traits<Iterator>::iterator_category
, typename detail::iterator_traits<Iterator>::reference>
{};
template <class Iterator>
struct traversal_category
: detail::traversal_category_tag<
typename detail::iterator_traits<Iterator>::iterator_category
>
{
};
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct access_category<T*>
: mpl::if_<
is_const<T>
, readable_lvalue_iterator_tag
, writable_lvalue_iterator_tag>
{
};
template <typename T>
struct traversal_category<T*>
{
typedef random_access_traversal_tag type;
};
# endif
template <class AccessTag, class TraversalTag>
struct iterator_tag
: detail::iterator_tag_base<
typename detail::max_known_access_tag<AccessTag>::type
, typename detail::max_known_traversal_tag<TraversalTag>::type
>::type
{
typedef AccessTag access;
typedef TraversalTag traversal;
};
namespace detail
{
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
struct is_boost_iterator_tag
: mpl::false_ {};
template <class R, class T>
struct is_boost_iterator_tag<iterator_tag<R,T> >
: mpl::true_ {};
# else
template <class T>
struct is_boost_iterator_tag
{
typedef char (&yes)[1];
typedef char (&no)[2];
template <class R, class U>
static yes test(mpl::identity<iterator_tag<R,U> >*);
static no test(...);
static mpl::identity<T>* inst;
BOOST_STATIC_CONSTANT(bool, value = sizeof(test(inst)) == sizeof(yes));
typedef mpl::bool_<value> type;
};
# endif
}
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ITERATOR_CATEGORIES_HPP
@@ -0,0 +1,358 @@
// (C) Copyright Jeremy Siek 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ITERATOR_CONCEPTS_HPP
#define BOOST_ITERATOR_CONCEPTS_HPP
// Revision History
// 26 Apr 2003 thw
// Adapted to new iterator concepts
// 22 Nov 2002 Thomas Witt
// Added interoperable concept.
#include <boost/concept_check.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/static_assert.hpp>
// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
#include <boost/detail/iterator.hpp>
// Use boost/limits to work around missing limits headers on some compilers
#include <boost/limits.hpp>
#include <algorithm>
namespace boost_concepts {
// Used a different namespace here (instead of "boost") so that the
// concept descriptions do not take for granted the names in
// namespace boost.
// We use this in place of STATIC_ASSERT((is_convertible<...>))
// because some compilers (CWPro7.x) can't detect convertibility.
//
// Of course, that just gets us a different error at the moment with
// some tests, since new iterator category deduction still depends
// on convertibility detection. We might need some specializations
// to support this compiler.
template <class Target, class Source>
struct static_assert_base_and_derived
{
static_assert_base_and_derived(Target* = (Source*)0) {}
};
//===========================================================================
// Iterator Access Concepts
template <typename Iterator>
class ReadableIteratorConcept {
public:
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::iterator_traits<Iterator>::value_type value_type;
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::iterator_traits<Iterator>::reference reference;
typedef BOOST_DEDUCED_TYPENAME ::boost::access_category<Iterator>::type access_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
boost::function_requires<
boost::DefaultConstructibleConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::readable_iterator_tag, access_category>::value));
reference r = *i; // or perhaps read(x)
value_type v(r);
boost::ignore_unused_variable_warning(v);
}
Iterator i;
};
template <typename Iterator, typename ValueType>
class WritableIteratorConcept {
public:
typedef typename boost::access_category<Iterator>::type access_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
boost::function_requires<
boost::DefaultConstructibleConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::writable_iterator_tag, access_category>::value));
*i = v; // a good alternative could be something like write(x, v)
}
ValueType v;
Iterator i;
};
template <typename Iterator>
class SwappableIteratorConcept {
public:
typedef typename boost::access_category<Iterator>::type access_category;
void constraints() {
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::swappable_iterator_tag, access_category>::value));
std::iter_swap(i1, i2);
}
Iterator i1;
Iterator i2;
};
template <typename Iterator>
class ReadableLvalueIteratorConcept {
public:
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
typedef typename boost::detail::iterator_traits<Iterator>::reference reference;
typedef typename boost::access_category<Iterator>::type access_category;
void constraints() {
boost::function_requires< ReadableIteratorConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::readable_lvalue_iterator_tag, access_category>::value));
typedef boost::mpl::or_<
boost::is_same<reference, value_type&>,
boost::is_same<reference, value_type const&> > correct_reference;
BOOST_STATIC_ASSERT(correct_reference::value);
reference v = *i;
boost::ignore_unused_variable_warning(v);
}
Iterator i;
};
template <typename Iterator>
class WritableLvalueIteratorConcept {
public:
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
typedef typename boost::detail::iterator_traits<Iterator>::reference reference;
typedef typename boost::access_category<Iterator>::type access_category;
void constraints() {
boost::function_requires<
ReadableLvalueIteratorConcept<Iterator> >();
boost::function_requires<
WritableIteratorConcept<Iterator, value_type> >();
boost::function_requires<
SwappableIteratorConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::writable_lvalue_iterator_tag, access_category>::value));
BOOST_STATIC_ASSERT((boost::is_same<reference, value_type&>::value));
}
};
//===========================================================================
// Iterator Traversal Concepts
template <typename Iterator>
class IncrementableIteratorConcept {
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
boost::function_requires<
boost::DefaultConstructibleConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::incrementable_traversal_tag, traversal_category>::value));
++i;
(void)i++;
}
Iterator i;
};
template <typename Iterator>
class SinglePassIteratorConcept {
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
void constraints() {
boost::function_requires< IncrementableIteratorConcept<Iterator> >();
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::single_pass_traversal_tag, traversal_category>::value));
}
};
template <typename Iterator>
class ForwardTraversalConcept {
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
void constraints() {
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
typedef boost::mpl::and_<
boost::is_integral<difference_type>,
boost::mpl::bool_< std::numeric_limits<difference_type>::is_signed >
> difference_type_is_signed_integral;
BOOST_STATIC_ASSERT(difference_type_is_signed_integral::value);
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::forward_traversal_tag, traversal_category>::value));
}
};
template <typename Iterator>
class BidirectionalTraversalConcept {
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
void constraints() {
boost::function_requires< ForwardTraversalConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::bidirectional_traversal_tag, traversal_category>::value));
--i;
(void)i--;
}
Iterator i;
};
template <typename Iterator>
class RandomAccessTraversalConcept {
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
typedef typename boost::detail::iterator_traits<Iterator>::difference_type
difference_type;
void constraints() {
boost::function_requires< BidirectionalTraversalConcept<Iterator> >();
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::random_access_traversal_tag, traversal_category>::value));
i += n;
i = i + n;
i = n + i;
i -= n;
i = i - n;
n = i - j;
}
difference_type n;
Iterator i, j;
};
//===========================================================================
// Iterator Interoperability Concept
namespace detail
{
template <typename TraversalTag>
struct Operations;
template <>
struct Operations<boost::incrementable_traversal_tag>
{
template <typename Iterator1, typename Iterator2>
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
{
// no interoperability constraints
}
};
template <>
struct Operations<boost::single_pass_traversal_tag>
{
template <typename Iterator1, typename Iterator2>
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
{
Operations<boost::incrementable_traversal_tag>(i1, i2);
i1 == i2;
i1 != i2;
i2 == i1;
i2 != i1;
}
};
template <>
struct Operations<boost::forward_traversal_tag>
{
template <typename Iterator1, typename Iterator2>
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
{
Operations<boost::single_pass_traversal_tag>::constraints(i1, i2);
}
};
template <>
struct Operations<boost::bidirectional_traversal_tag>
{
template <typename Iterator1, typename Iterator2>
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
{
Operations<boost::forward_traversal_tag>::constraints(i1, i2);
}
};
template <>
struct Operations<boost::random_access_traversal_tag>
{
template <typename Iterator1, typename Iterator2>
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
{
Operations<boost::bidirectional_traversal_tag>::constraints(i1, i2);
i1 < i2;
i1 <= i2;
i1 > i2;
i1 >= i2;
i1 - i2;
i2 < i1;
i2 <= i1;
i2 > i1;
i2 >= i1;
i2 - i1;
}
};
} // namespace detail
template <typename Iterator, typename ConstIterator>
class InteroperableConcept
{
public:
typedef typename boost::traversal_category<Iterator>::type traversal_category;
typedef typename boost::detail::iterator_traits<Iterator>::difference_type
difference_type;
typedef typename boost::traversal_category<ConstIterator>::type
const_traversal_category;
typedef typename boost::detail::iterator_traits<ConstIterator>::difference_type
const_difference_type;
void constraints() {
BOOST_STATIC_ASSERT((boost::is_same< difference_type,
const_difference_type>::value));
BOOST_STATIC_ASSERT((boost::is_same< traversal_category,
const_traversal_category>::value));
// ToDo check what the std really requires
// detail::Operations<traversal_category>::constraints(i, ci);
ci = i;
}
Iterator i;
ConstIterator ci;
};
} // namespace boost_concepts
#endif // BOOST_ITERATOR_CONCEPTS_HPP
+625
View File
@@ -0,0 +1,625 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_ITERATOR_FACADE_23022003THW_HPP
#define BOOST_ITERATOR_FACADE_23022003THW_HPP
#include <boost/static_assert.hpp>
#include <boost/iterator.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/interoperable.hpp>
#include <boost/iterator/detail/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/iterator/detail/config_def.hpp> // this goes last
namespace boost
{
struct use_default;
namespace detail
{
//
// enable if for use in operator implementation.
//
// enable_if_interoperable falls back to always enabled for compilers
// that don't support enable_if or is_convertible.
//
template <
class Facade1
, class Facade2
, class Return
>
struct enable_if_interoperable
#ifndef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
: ::boost::detail::enable_if<
mpl::or_<
is_convertible<Facade1, Facade2>
, is_convertible<Facade2, Facade1>
>
, Return
>
#endif
{
#ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
typedef Return type;
#endif
};
//
// Add const qualification for iterators which are not writable
//
template<class Value, class AccessCategory>
struct const_qualified_ref :
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
Value&,
Value const& >
{};
// The apparent duplication here works around a Borland problem
template<class Value, class AccessCategory>
struct const_qualified_ptr :
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
Value*,
Value const* >
{};
//
// Generates the associated types for an iterator_facade with the
// given parameters. Additionally generates a 'base' type for
// compiler/library combinations which require user-defined
// iterators to inherit from std::iterator.
//
template <
class Value
, class AccessCategory
, class TraversalCategory
, class Reference
, class Difference
>
struct iterator_facade_types
{
typedef iterator_tag<AccessCategory, TraversalCategory> iterator_category;
typedef typename remove_cv<Value>::type value_type;
typedef Difference difference_type;
typedef typename const_qualified_ptr<Value, AccessCategory>::type pointer;
// The use_default support is needed for iterator_adaptor.
// For practical reasons iterator_adaptor needs to specify
// a fixed number of template arguments of iterator_facade.
// So use_default is its way to say: "What I really mean
// is your default parameter".
typedef typename mpl::if_<
is_same<Reference, use_default>
, typename const_qualified_ref<Value, AccessCategory>::type
, Reference
>::type reference;
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
&& (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \
|| BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, BOOST_TESTED_AT(310))) \
|| BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)) \
|| BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 310)
// To interoperate with some broken library/compiler
// combinations, user-defined iterators must be derived from
// std::iterator. It is possible to implement a standard
// library for broken compilers without this limitation.
# define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1
typedef
iterator<iterator_category, value_type, difference_type, pointer, reference>
base;
# endif
};
// operator->() needs special support for input iterators to strictly meet the
// standard's requirements. If *i is not a reference type, we must still
// produce a (constant) lvalue to which a pointer can be formed. We do that by
// returning an instantiation of this special proxy class template.
template <class T>
struct operator_arrow_proxy
{
operator_arrow_proxy(T const* px) : m_value(*px) {}
const T* operator->() const { return &m_value; }
// This function is needed for MWCW and BCC, which won't call operator->
// again automatically per 13.3.1.2 para 8
operator const T*() const { return &m_value; }
T m_value;
};
// A metafunction that gets the result type for operator->. Also
// has a static function make() which builds the result from a
// Reference
template <class Value, class Category, class Reference, class Pointer>
struct operator_arrow_result
{
// CWPro8.3 won't accept "operator_arrow_result::type", and we
// need that type below, so metafunction forwarding would be a
// losing proposition here.
typedef typename mpl::if_<
is_tag<
readable_lvalue_iterator_tag
, typename access_category_tag<Category,Reference>::type
>
, Pointer
, operator_arrow_proxy<Value>
>::type type;
static type make(Reference x)
{
return type(&x);
}
};
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
// Deal with ETI
template<>
struct operator_arrow_result<int, int, int, int>
{
typedef int type;
};
# endif
//
// Facade is actually an iterator. We require Facade here
// so that we do not have to go through iterator_traits
// to access the traits
//
template <class Iterator>
class operator_brackets_proxy
{
typedef typename Iterator::reference reference;
typedef typename Iterator::value_type value_type;
public:
operator_brackets_proxy(Iterator const& iter)
: m_iter(iter)
{}
operator reference()
{
return *m_iter;
}
operator_brackets_proxy& operator=(value_type const& val)
{
*m_iter = val;
return *this;
}
private:
Iterator m_iter;
};
template <class Iterator, class ValueType, class Category, class Reference>
struct operator_brackets_result
{
typedef typename access_category_tag<Category,Reference>::type access_category;
typedef is_tag<writable_iterator_tag, access_category> use_proxy;
typedef typename mpl::if_<
use_proxy
, operator_brackets_proxy<Iterator>
, ValueType
>::type type;
};
template <class Iterator>
operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::true_)
{
return operator_brackets_proxy<Iterator>(iter);
}
template <class Iterator>
typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::false_)
{
return *iter;
}
} // namespace detail
// Macros which describe the declarations of binary operators
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
template < \
class Derived1, class V1, class AC1, class TC1, class R1, class D1 \
, class Derived2, class V2, class AC2, class TC2, class R2, class D2 \
> \
prefix typename detail::enable_if_interoperable< \
Derived1, Derived2, result_type \
>::type \
operator op( \
iterator_facade<Derived1, V1, AC1, TC1, R1, D1> const& lhs \
, iterator_facade<Derived2, V2, AC2, TC2, R2, D2> const& rhs)
# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
template <class Derived, class V, class AC, class TC, class R, class D> \
prefix Derived operator+ args
//
// Helper class for granting access to the iterator core interface.
//
// The simple core interface is used by iterator_facade. The core
// interface of a user/library defined iterator type should not be made public
// so that it does not clutter the public interface. Instead iterator_core_access
// should be made friend so that iterator_facade can access the core
// interface through iterator_core_access.
//
class iterator_core_access
{
# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
// Tasteless as this may seem, making all members public allows member templates
// to work in the absence of member template friends.
public:
# else
template <class I, class V, class AC, class TC, class R, class D> friend class iterator_facade;
# define BOOST_ITERATOR_FACADE_RELATION(op) \
BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, bool);
BOOST_ITERATOR_FACADE_RELATION(==)
BOOST_ITERATOR_FACADE_RELATION(!=)
BOOST_ITERATOR_FACADE_RELATION(<)
BOOST_ITERATOR_FACADE_RELATION(>)
BOOST_ITERATOR_FACADE_RELATION(<=)
BOOST_ITERATOR_FACADE_RELATION(>=)
# undef BOOST_ITERATOR_FACADE_RELATION
BOOST_ITERATOR_FACADE_INTEROP_HEAD(
friend, -, typename Derived1::difference_type)
;
BOOST_ITERATOR_FACADE_PLUS_HEAD(
friend
, (iterator_facade<Derived, V, AC, TC, R, D> const&
, typename Derived::difference_type)
)
;
BOOST_ITERATOR_FACADE_PLUS_HEAD(
friend
, (typename Derived::difference_type
, iterator_facade<Derived, V, AC, TC, R, D> const&)
)
;
# endif
template <class Facade>
static typename Facade::reference dereference(Facade const& f)
{
return f.dereference();
}
template <class Facade>
static void increment(Facade& f)
{
f.increment();
}
template <class Facade>
static void decrement(Facade& f)
{
f.decrement();
}
template <class Facade1, class Facade2>
static bool equal(Facade1 const& f1, Facade2 const& f2)
{
return f1.equal(f2);
}
template <class Facade>
static void advance(Facade& f, typename Facade::difference_type n)
{
f.advance(n);
}
template <class Facade1, class Facade2>
static typename Facade1::difference_type distance_to(
Facade1 const& f1, Facade2 const& f2)
{
return f1.distance_to(f2);
}
private:
// objects of this class are useless
iterator_core_access(); //undefined
};
//
// iterator_facade - use as a public base class for defining new
// standard-conforming iterators.
//
template <
class Derived // The derived iterator type being constructed
, class Value
, class AccessCategory
, class TraversalCategory
, class Reference = typename detail::const_qualified_ref<Value, AccessCategory>::type
, class Difference = std::ptrdiff_t
>
class iterator_facade
# ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
: public detail::iterator_facade_types<
Value, AccessCategory, TraversalCategory, Reference, Difference
>::base
# undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
# endif
{
private:
typedef typename
detail::iterator_facade_types<Value, AccessCategory, TraversalCategory, Reference, Difference>
types;
//
// Curiously Recursive Template interface.
//
typedef Derived derived_t;
Derived& derived()
{
return static_cast<Derived&>(*this);
}
Derived const& derived() const
{
return static_cast<Derived const&>(*this);
}
public:
typedef typename types::value_type value_type;
typedef typename types::reference reference;
typedef typename types::difference_type difference_type;
typedef typename types::pointer pointer;
typedef typename types::iterator_category iterator_category;
reference operator*() const
{
return iterator_core_access::dereference(this->derived());
}
typename detail::operator_arrow_result<
value_type
, iterator_category
, reference
, pointer
>::type
operator->() const
{
return detail::operator_arrow_result<
value_type
, iterator_category
, reference
, pointer
>::make(*this->derived());
}
typename detail::operator_brackets_result<Derived,value_type,iterator_category,reference>::type
operator[](difference_type n) const
{
typedef typename
detail::operator_brackets_result<Derived,value_type,iterator_category,reference>::use_proxy
use_proxy;
return detail::make_operator_brackets_result<Derived>(this->derived() + n, use_proxy());
}
Derived& operator++()
{
iterator_core_access::increment(this->derived());
return this->derived();
}
Derived operator++(int)
{
Derived tmp(this->derived());
++*this;
return tmp;
}
Derived& operator--()
{
iterator_core_access::decrement(this->derived());
return this->derived();
}
Derived operator--(int)
{
Derived tmp(this->derived());
--*this;
return tmp;
}
Derived& operator+=(difference_type n)
{
iterator_core_access::advance(this->derived(), n);
return this->derived();
}
Derived& operator-=(difference_type n)
{
iterator_core_access::advance(this->derived(), -n);
return this->derived();
}
Derived operator-(difference_type x) const
{
Derived result(this->derived());
return result -= x;
}
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
// There appears to be a bug which trashes the data of classes
// derived from iterator_facade when they are assigned unless we
// define this assignment operator. This bug is only revealed
// (so far) in STLPort debug mode, but it's clearly a codegen
// problem so we apply the workaround for all MSVC6.
iterator_facade& operator=(iterator_facade const&)
{
return *this;
}
# endif
};
//
// Operator implementation. The library supplied operators
// enables the user to provide fully interoperable constant/mutable
// iterator types. I.e. the library provides all operators
// for all mutable/constant iterator combinations.
//
// Note though that this kind of interoperability for constant/mutable
// iterators is not required by the standard for container iterators.
// All the standard asks for is a conversion mutable -> constant.
// Most standard library implementations nowadays provide fully interoperable
// iterator implementations, but there are still heavily used implementations
// that do not provide them. (Actually it's even worse, they do not provide
// them for only a few iterators.)
//
// ?? Maybe a BOOST_ITERATOR_NO_FULL_INTEROPERABILITY macro should
// enable the user to turn off mixed type operators
//
// The library takes care to provide only the right operator overloads.
// I.e.
//
// bool operator==(Iterator, Iterator);
// bool operator==(ConstIterator, Iterator);
// bool operator==(Iterator, ConstIterator);
// bool operator==(ConstIterator, ConstIterator);
//
// ...
//
// In order to do so it uses c++ idioms that are not yet widely supported
// by current compiler releases. The library is designed to degrade gracefully
// in the face of compiler deficiencies. In general compiler
// deficiencies result in less strict error checking and more obscure
// error messages, functionality is not affected.
//
// For full operation compiler support for "Substitution Failure Is Not An Error"
// (aka. enable_if) and boost::is_convertible is required.
//
// The following problems occur if support is lacking.
//
// Pseudo code
//
// ---------------
// AdaptorA<Iterator1> a1;
// AdaptorA<Iterator2> a2;
//
// // This will result in a no such overload error in full operation
// // If enable_if or is_convertible is not supported
// // The instantiation will fail with an error hopefully indicating that
// // there is no operator== for Iterator1, Iterator2
// // The same will happen if no enable_if is used to remove
// // false overloads from the templated conversion constructor
// // of AdaptorA.
//
// a1 == a2;
// ----------------
//
// AdaptorA<Iterator> a;
// AdaptorB<Iterator> b;
//
// // This will result in a no such overload error in full operation
// // If enable_if is not supported the static assert used
// // in the operator implementation will fail.
// // This will accidently work if is_convertible is not supported.
//
// a == b;
// ----------------
//
# define BOOST_ITERATOR_FACADE_INTEROP(op, result_type, condition, return_prefix, base_op) \
BOOST_ITERATOR_FACADE_INTEROP_HEAD(inline, op, result_type) \
{ \
/* For those compilers that do not support enable_if */ \
BOOST_STATIC_ASSERT(( \
is_interoperable< Derived1, Derived2 >::value \
&& condition \
)); \
return_prefix iterator_core_access::base_op( \
static_cast<Derived2 const&>(rhs), static_cast<Derived1 const&>(lhs)); \
}
# define BOOST_ITERATOR_FACADE_RELATION(op, return_prefix, base_op) \
BOOST_ITERATOR_FACADE_INTEROP( \
op \
, bool \
, true \
, return_prefix \
, base_op \
)
BOOST_ITERATOR_FACADE_RELATION(==, return, equal)
BOOST_ITERATOR_FACADE_RELATION(!=, return !, equal)
BOOST_ITERATOR_FACADE_RELATION(<, return 0 >, distance_to)
BOOST_ITERATOR_FACADE_RELATION(>, return 0 <, distance_to)
BOOST_ITERATOR_FACADE_RELATION(<=, return 0 >=, distance_to)
BOOST_ITERATOR_FACADE_RELATION(>=, return 0 <=, distance_to)
# undef BOOST_ITERATOR_FACADE_RELATION
// operator- requires an additional part in the static assertion
BOOST_ITERATOR_FACADE_INTEROP(
-
, typename Derived1::difference_type
, (is_same<
BOOST_DEDUCED_TYPENAME Derived1::difference_type
, BOOST_DEDUCED_TYPENAME Derived2::difference_type
>::value)
, return
, distance_to )
# undef BOOST_ITERATOR_FACADE_INTEROP
# undef BOOST_ITERATOR_FACADE_INTEROP_HEAD
# define BOOST_ITERATOR_FACADE_PLUS(args) \
BOOST_ITERATOR_FACADE_PLUS_HEAD(inline, args) \
{ \
Derived tmp(static_cast<Derived const&>(i)); \
return tmp += n; \
}
BOOST_ITERATOR_FACADE_PLUS((
iterator_facade<Derived, V, AC, TC, R, D> const& i
, typename Derived::difference_type n
))
BOOST_ITERATOR_FACADE_PLUS((
typename Derived::difference_type n
, iterator_facade<Derived, V, AC, TC, R, D> const& i
))
# undef BOOST_ITERATOR_FACADE_PLUS
# undef BOOST_ITERATOR_FACADE_PLUS_HEAD
} // namespace boost
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ITERATOR_FACADE_23022003THW_HPP
+93
View File
@@ -0,0 +1,93 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef ITERATOR_TRAITS_DWA200347_HPP
# define ITERATOR_TRAITS_DWA200347_HPP
# include <boost/detail/iterator.hpp>
# include <boost/detail/workaround.hpp>
namespace boost {
// Unfortunately, g++ 2.95.x chokes when we define a class template
// iterator_category which has the same name as its
// std::iterator_category() function, probably due in part to the
// "std:: is visible globally" hack it uses. Use
// BOOST_ITERATOR_CATEGORY to write code that's portable to older
// GCCs.
# if BOOST_WORKAROUND(__GNUC__, <= 2)
# define BOOST_ITERATOR_CATEGORY iterator_category_
# else
# define BOOST_ITERATOR_CATEGORY iterator_category
# endif
template <class Iterator>
struct iterator_value
{
typedef typename detail::iterator_traits<Iterator>::value_type type;
};
template <class Iterator>
struct iterator_reference
{
typedef typename detail::iterator_traits<Iterator>::reference type;
};
template <class Iterator>
struct iterator_pointer
{
typedef typename detail::iterator_traits<Iterator>::pointer type;
};
template <class Iterator>
struct iterator_difference
{
typedef typename detail::iterator_traits<Iterator>::difference_type type;
};
template <class Iterator>
struct BOOST_ITERATOR_CATEGORY
{
typedef typename detail::iterator_traits<Iterator>::iterator_category type;
};
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
template <>
struct iterator_value<int>
{
typedef void type;
};
template <>
struct iterator_reference<int>
{
typedef void type;
};
template <>
struct iterator_pointer<int>
{
typedef void type;
};
template <>
struct iterator_difference<int>
{
typedef void type;
};
template <>
struct BOOST_ITERATOR_CATEGORY<int>
{
typedef void type;
};
# endif
} // namespace boost::iterator
#endif // ITERATOR_TRAITS_DWA200347_HPP
@@ -0,0 +1,204 @@
#ifndef BOOST_NEW_ITERATOR_TESTS_HPP
# define BOOST_NEW_ITERATOR_TESTS_HPP
// This is meant to be the beginnings of a comprehensive, generic
// test suite for STL concepts such as iterators and containers.
//
// Revision History:
// 28 Oct 2002 Started update for new iterator categories
// (Jeremy Siek)
// 28 Apr 2002 Fixed input iterator requirements.
// For a == b a++ == b++ is no longer required.
// See 24.1.1/3 for details.
// (Thomas Witt)
// 08 Feb 2001 Fixed bidirectional iterator test so that
// --i is no longer a precondition.
// (Jeremy Siek)
// 04 Feb 2001 Added lvalue test, corrected preconditions
// (David Abrahams)
# include <iterator>
# include <assert.h>
# include <boost/type_traits.hpp>
# include <boost/static_assert.hpp>
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
# include <boost/detail/iterator.hpp>
# include <boost/pending/iterator_tests.hpp>
namespace boost {
void is_readable(readable_iterator_tag) { }
void is_writable(writable_iterator_tag) { }
void is_swappable(swappable_iterator_tag) { }
void is_constant_lvalue(readable_lvalue_iterator_tag) { }
void is_mutable_lvalue(writable_lvalue_iterator_tag) { }
// Preconditions: *i == v
template <class Iterator, class T>
void readable_iterator_test(const Iterator i1, T v)
{
Iterator i2(i1); // Copy Constructible
typedef typename detail::iterator_traits<Iterator>::reference ref_t;
ref_t r1 = *i1;
ref_t r2 = *i2;
T v1 = r1;
T v2 = r2;
assert(v1 == v);
assert(v2 == v);
typedef typename access_category<Iterator>::type result_category;
is_readable(result_category());
}
template <class Iterator, class T>
void writable_iterator_test(Iterator i, T v)
{
Iterator i2(i); // Copy Constructible
*i2 = v;
is_writable(typename access_category<Iterator>::type());
}
template <class Iterator>
void swappable_iterator_test(Iterator i, Iterator j)
{
Iterator i2(i), j2(j);
typename detail::iterator_traits<Iterator>::value_type bi = *i, bj = *j;
iter_swap(i2, j2);
typename detail::iterator_traits<Iterator>::value_type ai = *i, aj = *j;
assert(bi == aj && bj == ai);
typedef typename access_category<Iterator>::type result_category;
is_swappable(result_category());
}
template <class Iterator, class T>
void constant_lvalue_iterator_test(Iterator i, T v1)
{
Iterator i2(i);
typedef typename detail::iterator_traits<Iterator>::value_type value_type;
typedef typename detail::iterator_traits<Iterator>::reference reference;
BOOST_STATIC_ASSERT((is_same<const value_type&, reference>::value));
const T& v2 = *i2;
assert(v1 == v2);
typedef typename access_category<Iterator>::type result_category;
is_constant_lvalue(result_category());
}
template <class Iterator, class T>
void mutable_lvalue_iterator_test(Iterator i, T v1, T v2)
{
Iterator i2(i);
typedef typename detail::iterator_traits<Iterator>::value_type value_type;
typedef typename detail::iterator_traits<Iterator>::reference reference;
BOOST_STATIC_ASSERT((is_same<value_type&, reference>::value));
T& v3 = *i2;
assert(v1 == v3);
*i = v2;
T& v4 = *i2;
assert(v2 == v4);
typedef typename access_category<Iterator>::type result_category;
is_mutable_lvalue(result_category());
}
template <class Iterator, class T>
void forward_readable_iterator_test(Iterator i, Iterator j, T val1, T val2)
{
Iterator i2;
Iterator i3(i);
i2 = i;
assert(i2 == i3);
assert(i != j);
assert(i2 != j);
readable_iterator_test(i, val1);
readable_iterator_test(i2, val1);
readable_iterator_test(i3, val1);
assert(i == i2++);
assert(i != ++i3);
readable_iterator_test(i2, val2);
readable_iterator_test(i3, val2);
readable_iterator_test(i, val1);
}
template <class Iterator, class T>
void forward_swappable_iterator_test(Iterator i, Iterator j, T val1, T val2)
{
forward_readable_iterator_test(i, j, val1, val2);
Iterator i2 = i;
++i2;
swappable_iterator_test(i, i2);
}
// bidirectional
// Preconditions: *i == v1, *++i == v2
template <class Iterator, class T>
void bidirectional_readable_iterator_test(Iterator i, T v1, T v2)
{
Iterator j(i);
++j;
forward_readable_iterator_test(i, j, v1, v2);
++i;
Iterator i1 = i, i2 = i;
assert(i == i1--);
assert(i != --i2);
readable_iterator_test(i, v2);
readable_iterator_test(i1, v1);
readable_iterator_test(i2, v1);
--i;
assert(i == i1);
assert(i == i2);
++i1;
++i2;
readable_iterator_test(i, v1);
readable_iterator_test(i1, v2);
readable_iterator_test(i2, v2);
}
// random access
// Preconditions: [i,i+N) is a valid range
template <class Iterator, class TrueVals>
void random_access_readable_iterator_test(Iterator i, int N, TrueVals vals)
{
bidirectional_readable_iterator_test(i, vals[0], vals[1]);
const Iterator j = i;
int c;
for (c = 0; c < N-1; ++c) {
assert(i == j + c);
assert(*i == vals[c]);
assert(*i == j[c]);
assert(*i == *(j + c));
assert(*i == *(c + j));
++i;
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
}
Iterator k = j + N - 1;
for (c = 0; c < N-1; ++c) {
assert(i == k - c);
assert(*i == vals[N - 1 - c]);
assert(*i == j[N - 1 - c]);
Iterator q = k - c;
assert(*i == *q);
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
--i;
}
}
// #if 0'd code snipped; see CVS v 1.4 if you need it back
} // namespace boost
#endif // BOOST_NEW_ITERATOR_TESTS_HPP
@@ -0,0 +1,92 @@
// (C) Copyright Toon Knapen 2001.
// (C) Copyright David Abrahams 2003.
// (C) Copyright Roland Richter 2003.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
#ifndef BOOST_PERMUTATION_ITERATOR_HPP
#define BOOST_PERMUTATION_ITERATOR_HPP
#include <iterator>
#include <boost/iterator/iterator_adaptor.hpp>
namespace boost
{
template< class ElementIterator
, class IndexIterator
, class ValueT = use_default
, class CategoryT = use_default
, class ReferenceT = use_default
, class DifferenceT = use_default >
class permutation_iterator
: public iterator_adaptor<
permutation_iterator<ElementIterator, IndexIterator, ValueT, CategoryT, ReferenceT, DifferenceT>
, ElementIterator, ValueT, CategoryT, ReferenceT, DifferenceT >
{
typedef iterator_adaptor<
permutation_iterator<ElementIterator, IndexIterator, ValueT, CategoryT, ReferenceT, DifferenceT>
, ElementIterator, ValueT, CategoryT, ReferenceT, DifferenceT > super_t;
friend class iterator_core_access;
public:
permutation_iterator() : order_it_() {}
explicit permutation_iterator(ElementIterator x, IndexIterator y)
: super_t(x), order_it_(y) {}
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
permutation_iterator(
permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& r
, typename enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0
, typename enable_if_convertible<OtherIndexIterator, IndexIterator>::type* = 0
)
: super_t(r.base())
{}
private:
typename super_t::reference dereference() const
{ return *(this->base() + *this->order_it_); }
void increment() { ++this->order_it_; }
void decrement() { --this->order_it_; }
void advance(typename super_t::difference_type n)
{
std::advance( order_it_, n );
}
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
typename super_t::difference_type
distance_to( permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& y ) const
{
return std::distance( this->order_it_, y.order_it_ );
}
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
bool
equal( permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& y ) const
{
return( y.order_it_ == this->order_it_ );
}
IndexIterator order_it_;
};
template <class ElementIterator, class IndexIterator>
permutation_iterator<ElementIterator, IndexIterator>
make_permutation_iterator( ElementIterator e, IndexIterator i )
{
return permutation_iterator<ElementIterator, IndexIterator>( e, i );
}
} // namespace boost
#endif
@@ -0,0 +1,71 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_REVERSE_ITERATOR_23022003THW_HPP
#define BOOST_REVERSE_ITERATOR_23022003THW_HPP
#include <boost/iterator.hpp>
#include <boost/utility.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
namespace boost
{
//
//
//
template <class Iterator>
class reverse_iterator
: public iterator_adaptor< reverse_iterator<Iterator>, Iterator >
{
typedef iterator_adaptor< reverse_iterator<Iterator>, Iterator > super_t;
friend class iterator_core_access;
public:
reverse_iterator() {}
explicit reverse_iterator(Iterator x)
: super_t(x) {}
template<class OtherIterator>
reverse_iterator(
reverse_iterator<OtherIterator> const& r
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
)
: super_t(r.base())
{}
private:
typename super_t::reference dereference() const { return *boost::prior(this->base()); }
void increment() { --this->base_reference(); }
void decrement() { ++this->base_reference(); }
void advance(typename super_t::difference_type n)
{
this->base_reference() += -n;
}
template <class OtherIterator>
typename super_t::difference_type
distance_to(reverse_iterator<OtherIterator> const& y) const
{
return this->base_reference() - y.base();
}
};
template <class BidirectionalIterator>
reverse_iterator<BidirectionalIterator> make_reverse_iterator(BidirectionalIterator x)
{
return reverse_iterator<BidirectionalIterator>(x);
}
} // namespace boost
#endif // BOOST_REVERSE_ITERATOR_23022003THW_HPP
@@ -0,0 +1,154 @@
// (C) Copyright David Abrahams 2002.
// (C) Copyright Jeremy Siek 2002.
// (C) Copyright Thomas Witt 2002.
// Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
#define BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
#include <boost/function.hpp>
#include <boost/iterator.hpp>
#include <boost/iterator/detail/enable_if.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/type_traits/function_traits.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
namespace boost
{
template <class UnaryFunction, class Iterator, class Reference = use_default, class Value = use_default>
class transform_iterator;
namespace detail
{
template <class UnaryFunction>
struct function_object_result
{
typedef typename UnaryFunction::result_type type;
};
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Return, class Argument>
struct function_object_result<Return(*)(Argument)>
{
typedef Return type;
};
#endif
// Given the transform iterator's transformation and iterator, this
// is the type used as its traits.
template <class UnaryFunction, class Iterator, class Reference, class Value>
struct transform_iterator_base
{
private:
// transform_iterator does not support writable/swappable iterators
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_STATIC_ASSERT((is_tag< readable_iterator_tag, typename access_category<Iterator>::type >::value));
#endif
typedef typename mpl::apply_if<
is_same< Reference, use_default >
, function_object_result<UnaryFunction>
, mpl::identity<Reference>
>::type result_type;
typedef typename mpl::if_<
is_same< Value, use_default >
, typename remove_reference< result_type >::type
, Value
>::type cv_value_type;
typedef typename mpl::if_<
is_reference< result_type >
, typename mpl::if_<
is_const< cv_value_type >
, readable_lvalue_iterator_tag
, writable_lvalue_iterator_tag
>::type
, readable_iterator_tag
>::type maximum_access_tag;
typedef typename minimum_category<
maximum_access_tag
, typename access_category<Iterator>::type
>::type access_category;
public:
typedef iterator_adaptor<
transform_iterator<UnaryFunction, Iterator, Reference, Value>
, Iterator
, cv_value_type
, iterator_tag<
access_category
, typename traversal_category<Iterator>::type
>
, result_type
> type;
};
}
template <class UnaryFunction, class Iterator, class Reference, class Value>
class transform_iterator
: public detail::transform_iterator_base<UnaryFunction, Iterator, Reference, Value>::type
{
typedef typename
detail::transform_iterator_base<UnaryFunction, Iterator, Reference, Value>::type
super_t;
friend class iterator_core_access;
public:
transform_iterator() { }
transform_iterator(Iterator const& x, UnaryFunction f)
: super_t(x), m_f(f) { }
template<class OtherIterator>
transform_iterator(
transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
)
: super_t(t.base()), m_f(t.functor()) {}
UnaryFunction functor() const
{ return m_f; }
private:
typename super_t::reference dereference() const
{ return m_f(*this->base()); }
// Probably should be the initial base class so it can be
// optimized away via EBO if it is an empty class.
UnaryFunction m_f;
};
template <class UnaryFunction, class Iterator>
transform_iterator<UnaryFunction, Iterator> make_transform_iterator(Iterator it, UnaryFunction fun)
{
return transform_iterator<UnaryFunction, Iterator>(it, fun);
}
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
template <class Return, class Argument, class Iterator>
transform_iterator< Return (*)(Argument), Iterator, Return>
make_transform_iterator(Iterator it, Return (*fun)(Argument))
{
return transform_iterator<Return (*)(Argument), Iterator, Return>(it, fun);
}
#endif
} // namespace boost
#endif // BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
File diff suppressed because it is too large Load Diff
@@ -1,75 +0,0 @@
// (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef BOOST_INT_ITERATOR_H
#define BOOST_INT_ITERATOR_H
#include <boost/iterator.hpp>
#if !defined BOOST_MSVC
#include <boost/operators.hpp>
#endif
#include <iostream>
//using namespace std;
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
namespace boost {
#endif
// this should use random_access_iterator_helper but I've had
// VC++ portablility problems with that. -JGS
template <class IntT>
class int_iterator
{
typedef int_iterator self;
public:
typedef std::random_access_iterator_tag iterator_category;
typedef IntT value_type;
typedef IntT& reference;
typedef IntT* pointer;
typedef std::ptrdiff_t difference_type;
inline int_iterator() : _i(0) { }
inline int_iterator(IntT i) : _i(i) { }
inline int_iterator(const self& x) : _i(x._i) { }
inline self& operator=(const self& x) { _i = x._i; return *this; }
inline IntT operator*() { return _i; }
inline IntT operator[](IntT n) { return _i + n; }
inline self& operator++() { ++_i; return *this; }
inline self operator++(int) { self t = *this; ++_i; return t; }
inline self& operator+=(IntT n) { _i += n; return *this; }
inline self operator+(IntT n) { self t = *this; t += n; return t; }
inline self& operator--() { --_i; return *this; }
inline self operator--(int) { self t = *this; --_i; return t; }
inline self& operator-=(IntT n) { _i -= n; return *this; }
inline IntT operator-(const self& x) const { return _i - x._i; }
inline bool operator==(const self& x) const { return _i == x._i; }
// vc++ had a problem finding != in random_access_iterator_helper
// need to look into this... for now implementing everything here -JGS
inline bool operator!=(const self& x) const { return _i != x._i; }
inline bool operator<(const self& x) const { return _i < x._i; }
inline bool operator<=(const self& x) const { return _i <= x._i; }
inline bool operator>(const self& x) const { return _i > x._i; }
inline bool operator>=(const self& x) const { return _i >= x._i; }
protected:
IntT _i;
};
template <class IntT>
inline int_iterator<IntT>
operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
} /* namespace boost */
#endif
#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
namespace boost {
using ::int_iterator;
}
#endif
#endif /* BOOST_INT_ITERATOR_H */
-59
View File
@@ -1,59 +0,0 @@
// (C) Copyright David Abrahams and Jeremy Siek 2000-2001. Permission to copy,
// use, modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided "as is"
// without express or implied warranty, and with no claim as to its suitability
// for any purpose.
//
// Revision History:
// 04 Jan 2001 Factored counting_iterator stuff into
// boost/counting_iterator.hpp (David Abrahams)
#ifndef BOOST_INTEGER_RANGE_HPP_
#define BOOST_INTEGER_RANGE_HPP_
#include <boost/config.hpp>
#include <boost/counting_iterator.hpp>
namespace boost {
//=============================================================================
// Counting Iterator and Integer Range Class
template <class IntegerType>
struct integer_range {
typedef typename counting_iterator_generator<IntegerType>::type iterator;
typedef iterator const_iterator;
typedef IntegerType value_type;
typedef std::ptrdiff_t difference_type;
typedef IntegerType reference;
typedef IntegerType const_reference;
typedef const IntegerType* pointer;
typedef const IntegerType* const_pointer;
typedef IntegerType size_type;
integer_range(IntegerType start, IntegerType finish)
: m_start(start), m_finish(finish) { }
iterator begin() const { return iterator(m_start); }
iterator end() const { return iterator(m_finish); }
size_type size() const { return m_finish - m_start; }
bool empty() const { return m_finish == m_start; }
void swap(integer_range& x) {
std::swap(m_start, x.m_start);
std::swap(m_finish, x.m_finish);
}
protected:
IntegerType m_start, m_finish;
};
template <class IntegerType>
inline integer_range<IntegerType>
make_integer_range(IntegerType first, IntegerType last)
{
return integer_range<IntegerType>(first, last);
}
} // namespace boost
#endif // BOOST_INTEGER_RANGE_HPP_
@@ -1 +0,0 @@
#include <boost/iterator_adaptors.hpp>
-253
View File
@@ -1,253 +0,0 @@
#ifndef BOOST_ITERATOR_TESTS_HPP
# define BOOST_ITERATOR_TESTS_HPP
// This is meant to be the beginnings of a comprehensive, generic
// test suite for STL concepts such as iterators and containers.
//
// Revision History:
// 28 Apr 2002 Fixed input iterator requirements.
// For a == b a++ == b++ is no longer required.
// See 24.1.1/3 for details.
// (Thomas Witt)
// 08 Feb 2001 Fixed bidirectional iterator test so that
// --i is no longer a precondition.
// (Jeremy Siek)
// 04 Feb 2001 Added lvalue test, corrected preconditions
// (David Abrahams)
# include <iterator>
# include <assert.h>
# include <boost/type_traits.hpp>
# include <boost/static_assert.hpp>
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
namespace boost {
// use this for the value type
struct dummyT {
dummyT() { }
dummyT(detail::dummy_constructor) { }
dummyT(int x) : m_x(x) { }
int foo() const { return m_x; }
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
int m_x;
};
// Tests whether type Iterator satisfies the requirements for a
// TrivialIterator.
// Preconditions: i != j, *i == val
template <class Iterator, class T>
void trivial_iterator_test(const Iterator i, const Iterator j, T val)
{
Iterator k;
assert(i == i);
assert(j == j);
assert(i != j);
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
T v = *i;
#else
typename std::iterator_traits<Iterator>::value_type v = *i;
#endif
assert(v == val);
#if 0
// hmm, this will give a warning for transform_iterator... perhaps
// this should be separated out into a stand-alone test since there
// are several situations where it can't be used, like for
// integer_range::iterator.
assert(v == i->foo());
#endif
k = i;
assert(k == k);
assert(k == i);
assert(k != j);
assert(*k == val);
}
// Preconditions: i != j
template <class Iterator, class T>
void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
{
*i = val;
trivial_iterator_test(i, j, val);
}
// Preconditions: *i == v1, *++i == v2
template <class Iterator, class T>
void input_iterator_test(Iterator i, T v1, T v2)
{
Iterator i1(i);
assert(i == i1);
assert(!(i != i1));
// I can see no generic way to create an input iterator
// that is in the domain of== of i and != i.
// The following works for istream_iterator but is not
// guaranteed to work for arbitrary input iterators.
//
// Iterator i2;
//
// assert(i != i2);
// assert(!(i == i2));
assert(*i1 == v1);
assert(*i == v1);
// we cannot test for equivalence of (void)++i & (void)i++
// as i is only guaranteed to be single pass.
assert(*i++ == v1);
i1 = i;
assert(i == i1);
assert(!(i != i1));
assert(*i1 == v2);
assert(*i == v2);
// i is dereferencable, so it must be incrementable.
++i;
// how to test for operator-> ?
}
// how to test output iterator?
template <bool is_pointer> struct lvalue_test
{
template <class Iterator> static void check(Iterator)
{
# ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename std::iterator_traits<Iterator>::value_type value_type;
# else
typedef typename Iterator::reference reference;
typedef typename Iterator::value_type value_type;
# endif
BOOST_STATIC_ASSERT(boost::is_reference<reference>::value);
BOOST_STATIC_ASSERT((boost::is_same<reference,value_type&>::value
|| boost::is_same<reference,const value_type&>::value
));
}
};
# ifdef BOOST_NO_STD_ITERATOR_TRAITS
template <> struct lvalue_test<true> {
template <class T> static void check(T) {}
};
#endif
template <class Iterator, class T>
void forward_iterator_test(Iterator i, T v1, T v2)
{
input_iterator_test(i, v1, v2);
Iterator i1 = i, i2 = i;
assert(i == i1++);
assert(i != ++i2);
trivial_iterator_test(i, i1, v1);
trivial_iterator_test(i, i2, v1);
++i;
assert(i == i1);
assert(i == i2);
++i1;
++i2;
trivial_iterator_test(i, i1, v2);
trivial_iterator_test(i, i2, v2);
// borland doesn't allow non-type template parameters
# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551)
lvalue_test<(boost::is_pointer<Iterator>::value)>::check(i);
#endif
}
// Preconditions: *i == v1, *++i == v2
template <class Iterator, class T>
void bidirectional_iterator_test(Iterator i, T v1, T v2)
{
forward_iterator_test(i, v1, v2);
++i;
Iterator i1 = i, i2 = i;
assert(i == i1--);
assert(i != --i2);
trivial_iterator_test(i, i1, v2);
trivial_iterator_test(i, i2, v2);
--i;
assert(i == i1);
assert(i == i2);
++i1;
++i2;
trivial_iterator_test(i, i1, v1);
trivial_iterator_test(i, i2, v1);
}
// mutable_bidirectional_iterator_test
// Preconditions: [i,i+N) is a valid range
template <class Iterator, class TrueVals>
void random_access_iterator_test(Iterator i, int N, TrueVals vals)
{
bidirectional_iterator_test(i, vals[0], vals[1]);
const Iterator j = i;
int c;
for (c = 0; c < N-1; ++c) {
assert(i == j + c);
assert(*i == vals[c]);
assert(*i == j[c]);
assert(*i == *(j + c));
assert(*i == *(c + j));
++i;
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
}
Iterator k = j + N - 1;
for (c = 0; c < N-1; ++c) {
assert(i == k - c);
assert(*i == vals[N - 1 - c]);
assert(*i == j[N - 1 - c]);
Iterator q = k - c;
assert(*i == *q);
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
--i;
}
}
// Precondition: i != j
template <class Iterator, class ConstIterator>
void const_nonconst_iterator_test(Iterator i, ConstIterator j)
{
assert(i != j);
assert(j != i);
ConstIterator k(i);
assert(k == i);
assert(i == k);
k = i;
assert(k == i);
assert(i == k);
}
} // namespace boost
#endif // BOOST_ITERATOR_TESTS_HPP
-74
View File
@@ -1,74 +0,0 @@
// (C) Copyright Toon Knapen 2001. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
// See http://www.boost.org/libs/utility/permutation_iterator.htm for documentation.
#ifndef boost_permutation_iterator_hpp
#define boost_permutation_iterator_hpp
#include <boost/iterator_adaptors.hpp>
namespace boost {
template < typename IndexIterator >
struct permutation_iterator_policies : public default_iterator_policies
{
permutation_iterator_policies() {}
permutation_iterator_policies(IndexIterator order_it)
: order_it_( order_it )
{}
template <class IteratorAdaptor>
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const
{ return *(x.base() + *order_it_); }
template <class IteratorAdaptor>
void increment(IteratorAdaptor&)
{ ++order_it_; }
template <class IteratorAdaptor>
void decrement(IteratorAdaptor&)
{ --order_it_; }
template <class IteratorAdaptor, class DifferenceType>
void advance(IteratorAdaptor& x, DifferenceType n)
{ std::advance( order_it_, n ); }
template <class IteratorAdaptor1, class IteratorAdaptor2>
typename IteratorAdaptor1::difference_type
distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
{ return std::distance( x.policies().order_it_, y.policies().order_it_ ); }
template <class IteratorAdaptor1, class IteratorAdaptor2>
bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
{ return x.policies().order_it_ == y.policies().order_it_; }
IndexIterator order_it_;
};
template < typename ElementIterator, typename IndexIterator >
struct permutation_iterator_generator
{
typedef boost::iterator_adaptor
< ElementIterator,
permutation_iterator_policies< IndexIterator >
> type;
};
template < class IndexIterator, class ElementIterator >
inline typename permutation_iterator_generator< ElementIterator, IndexIterator >::type
make_permutation_iterator(ElementIterator base, IndexIterator order)
{
typedef typename permutation_iterator_generator< ElementIterator, IndexIterator >::type result_t;
return result_t( base, order );
}
} // namespace boost
#endif // boost_permutation_iterator_hpp
@@ -1,59 +0,0 @@
// (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// See http://www.boost.org/libs/utility/shared_container_iterator.html for documentation.
#ifndef SHARED_CONTAINER_ITERATOR_RG08102002_HPP
#define SHARED_CONTAINER_ITERATOR_RG08102002_HPP
#include "boost/iterator_adaptors.hpp"
#include "boost/shared_ptr.hpp"
#include <utility>
namespace boost {
template <typename Container>
struct shared_container_iterator_policies :
public boost::default_iterator_policies {
typedef boost::shared_ptr<Container> container_ref_t;
container_ref_t container_ref;
shared_container_iterator_policies(container_ref_t const& c) :
container_ref(c) { }
shared_container_iterator_policies() { }
};
template <typename Container>
class shared_container_iterator_generator {
typedef typename Container::iterator iterator;
typedef shared_container_iterator_policies<Container> policy;
public:
typedef boost::iterator_adaptor<iterator,policy> type;
};
template <typename Container>
typename shared_container_iterator_generator<Container>::type
make_shared_container_iterator(typename Container::iterator iter,
boost::shared_ptr<Container> const& container) {
typedef typename shared_container_iterator_generator<Container>::type
iterator;
typedef shared_container_iterator_policies<Container> policy;
return iterator(iter,policy(container));
}
template <typename Container>
std::pair<
typename shared_container_iterator_generator<Container>::type,
typename shared_container_iterator_generator<Container>::type>
make_shared_container_range(boost::shared_ptr<Container> const& container) {
return
std::make_pair(
make_shared_container_iterator(container->begin(),container),
make_shared_container_iterator(container->end(),container));
}
} // namespace boost
#endif // SHARED_CONTAINER_ITERATOR_RG08102002_HPP
+14
View File
@@ -0,0 +1,14 @@
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ;
run unit_tests.cpp ;
run concept_tests.cpp ;
run iterator_adaptor_cc.cpp ;
run iterator_adaptor_test.cpp ;
compile iterator_archetype_cc.cpp ;
run transform_iterator_test.cpp ;
run indirect_iterator_test.cpp ;
run filter_iterator_test.cpp ;
run reverse_iterator_test.cpp ;
run counting_iterator_test.cpp ;
run is_convertible_fail.cpp ; # test changed to expected success, so that we catch compilation failures.
compile-fail interoperable_fail.cpp ;
+174
View File
@@ -0,0 +1,174 @@
// (C) Copyright Jeremy Siek 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/operators.hpp>
#include <boost/static_assert.hpp> // remove
#include <boost/detail/workaround.hpp>
#include "static_assert_same.hpp" // remove
struct new_iterator
: public boost::iterator< boost::iterator_tag<
boost::writable_lvalue_iterator_tag
, boost::random_access_traversal_tag>, int>
{
int& operator*() const { return *m_x; }
new_iterator& operator++() { return *this; }
new_iterator operator++(int) { return *this; }
new_iterator& operator--() { return *this; }
new_iterator operator--(int) { return *this; }
new_iterator& operator+=(std::ptrdiff_t) { return *this; }
new_iterator operator+(std::ptrdiff_t) { return *this; }
new_iterator& operator-=(std::ptrdiff_t) { return *this; }
std::ptrdiff_t operator-(const new_iterator&) const { return 0; }
new_iterator operator-(std::ptrdiff_t) const { return *this; }
bool operator==(const new_iterator&) const { return false; }
bool operator!=(const new_iterator&) const { return false; }
bool operator<(const new_iterator&) const { return false; }
int* m_x;
};
new_iterator operator+(std::ptrdiff_t, new_iterator x) { return x; }
struct old_iterator
: public boost::iterator<std::random_access_iterator_tag, int>
{
int& operator*() const { return *m_x; }
old_iterator& operator++() { return *this; }
old_iterator operator++(int) { return *this; }
old_iterator& operator--() { return *this; }
old_iterator operator--(int) { return *this; }
old_iterator& operator+=(std::ptrdiff_t) { return *this; }
old_iterator operator+(std::ptrdiff_t) { return *this; }
old_iterator& operator-=(std::ptrdiff_t) { return *this; }
old_iterator operator-(std::ptrdiff_t) const { return *this; }
std::ptrdiff_t operator-(const old_iterator&) const { return 0; }
bool operator==(const old_iterator&) const { return false; }
bool operator!=(const old_iterator&) const { return false; }
bool operator<(const old_iterator&) const { return false; }
int* m_x;
};
old_iterator operator+(std::ptrdiff_t, old_iterator x) { return x; }
struct my_writable_lvalue_iterator_tag
{
operator boost::writable_lvalue_iterator_tag() const;
};
struct my_single_pass_traversal_tag
{
operator boost::single_pass_traversal_tag() const;
};
void test_tag_convertibility()
{
// This set of tests is by no means complete.
// Test that this is an input/output iterator
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
{
typedef boost::iterator_tag<
boost::writable_lvalue_iterator_tag
, boost::single_pass_traversal_tag
> tag;
BOOST_STATIC_ASSERT((
boost::is_convertible<tag, std::output_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
boost::is_convertible<tag, std::input_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
!boost::is_convertible<tag, std::forward_iterator_tag>::value
));
}
// Test that it's possible to build new sub-tags without
// derivation. Convertibility should be enough
{
typedef boost::iterator_tag<
my_writable_lvalue_iterator_tag
, my_single_pass_traversal_tag
> tag;
BOOST_STATIC_ASSERT((
boost::is_convertible<tag, std::output_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
boost::is_convertible<tag, std::input_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
!boost::is_convertible<tag, std::forward_iterator_tag>::value
));
}
// Test that a single-pass readable lvalue iterator is only an
// input iterator. Requires special case handling in
// categories.hpp
{
typedef boost::iterator_tag<
boost::readable_lvalue_iterator_tag
, boost::single_pass_traversal_tag
> tag;
BOOST_STATIC_ASSERT((
boost::is_convertible<tag, std::input_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
!boost::is_convertible<tag, std::output_iterator_tag>::value
));
BOOST_STATIC_ASSERT((
!boost::is_convertible<tag, std::forward_iterator_tag>::value
));
}
#endif
}
int
main()
{
test_tag_convertibility();
typedef boost::iterator_tag< boost::writable_lvalue_iterator_tag, boost::random_access_traversal_tag > tag;
// BOOST_STATIC_ASSERT((boost::detail::is_random_access_iterator<tag>::value));
int test = static_assert_same<tag::access, boost::writable_lvalue_iterator_tag>::value;
test = static_assert_same<tag::traversal, boost::random_access_traversal_tag>::value;
// BOOST_STATIC_ASSERT((boost::detail::is_random_access_iterator<new_iterator::iterator_category>::value));
test = static_assert_same<new_iterator::iterator_category::access, boost::writable_lvalue_iterator_tag>::value;
test = static_assert_same<new_iterator::iterator_category::traversal, boost::random_access_traversal_tag>::value;
typedef boost::traversal_category<new_iterator>::type traversal_category;
// BOOST_STATIC_ASSERT(boost::detail::has_traversal<new_iterator::iterator_category>::value);
BOOST_STATIC_ASSERT(boost::detail::is_new_iterator_tag<new_iterator::iterator_category>::value);
test = static_assert_same<traversal_category, boost::random_access_traversal_tag>::value;
(void)test;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
boost::function_requires<
boost_concepts::WritableLvalueIteratorConcept<int*> >();
boost::function_requires<
boost_concepts::RandomAccessTraversalConcept<int*> >();
boost::function_requires<
boost_concepts::ReadableLvalueIteratorConcept<const int*> >();
boost::function_requires<
boost_concepts::RandomAccessTraversalConcept<const int*> >();
#endif
boost::function_requires<
boost_concepts::WritableLvalueIteratorConcept<new_iterator> >();
boost::function_requires<
boost_concepts::RandomAccessTraversalConcept<new_iterator> >();
boost::function_requires<
boost_concepts::WritableLvalueIteratorConcept<old_iterator> >();
boost::function_requires<
boost_concepts::RandomAccessTraversalConcept<old_iterator> >();
return 0;
}
+295
View File
@@ -0,0 +1,295 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears in
// all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
// See http://www.boost.org for most recent version including documentation.
//
// Revision History
// 16 Feb 2001 Added a missing const. Made the tests run (somewhat) with
// plain MSVC again. (David Abrahams)
// 11 Feb 2001 #if 0'd out use of counting_iterator on non-numeric types in
// MSVC without STLport, so that the other tests may proceed
// (David Abrahams)
// 04 Feb 2001 Added use of iterator_tests.hpp (David Abrahams)
// 28 Jan 2001 Removed not_an_iterator detritus (David Abrahams)
// 24 Jan 2001 Initial revision (David Abrahams)
#include <boost/config.hpp>
#ifdef __BORLANDC__ // Borland mis-detects our custom iterators
# pragma warn -8091 // template argument ForwardIterator passed to '...' is a output iterator
# pragma warn -8071 // Conversion may lose significant digits (due to counting_iterator<char> += n).
#endif
#ifdef BOOST_MSVC
# pragma warning(disable:4786) // identifier truncated in debug info
#endif
#include <boost/detail/iterator.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <boost/next_prior.hpp>
#include <boost/mpl/if.hpp>
#include <boost/detail/iterator.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/limits.hpp>
#include <algorithm>
#include <climits>
#include <iterator>
#include <stdlib.h>
#ifndef __BORLANDC__
# include <boost/tuple/tuple.hpp>
#endif
#include <vector>
#include <list>
#include <cassert>
#ifndef BOOST_NO_SLIST
# include <slist>
#endif
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
template <class T>
struct signed_assert_nonnegative
{
static void test(T x) { assert(x >= 0); }
};
template <class T>
struct unsigned_assert_nonnegative
{
static void test(T x) {}
};
template <class T>
struct assert_nonnegative
: boost::mpl::if_c<
std::numeric_limits<T>::is_signed
, signed_assert_nonnegative<T>
, unsigned_assert_nonnegative<T>
>::type
{
};
#endif
// Special tests for RandomAccess CountingIterators.
template <class CountingIterator, class Value>
void category_test(
CountingIterator start,
CountingIterator finish,
Value,
std::random_access_iterator_tag)
{
typedef typename
boost::detail::iterator_traits<CountingIterator>::difference_type
difference_type;
difference_type distance = boost::detail::distance(start, finish);
// Pick a random position internal to the range
difference_type offset = (unsigned)rand() % distance;
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
assert(offset >= 0);
#else
assert_nonnegative<difference_type>::test(offset);
#endif
CountingIterator internal = start;
std::advance(internal, offset);
// Try some binary searches on the range to show that it's ordered
assert(std::binary_search(start, finish, *internal));
// #including tuple crashed borland, so I had to give up on tie().
std::pair<CountingIterator,CountingIterator> xy(
std::equal_range(start, finish, *internal));
CountingIterator x = xy.first, y = xy.second;
assert(boost::detail::distance(x, y) == 1);
// Show that values outside the range can't be found
assert(!std::binary_search(start, boost::prior(finish), *finish));
// Do the generic random_access_iterator_test
typedef typename CountingIterator::value_type value_type;
std::vector<value_type> v;
for (value_type z = *start; !(z == *finish); ++z)
v.push_back(z);
// Note that this test requires a that the first argument is
// dereferenceable /and/ a valid iterator prior to the first argument
boost::random_access_iterator_test(start, v.size(), v.begin());
}
// Special tests for bidirectional CountingIterators
template <class CountingIterator, class Value>
void category_test(CountingIterator start, Value v1, std::bidirectional_iterator_tag)
{
Value v2 = v1;
++v2;
// Note that this test requires a that the first argument is
// dereferenceable /and/ a valid iterator prior to the first argument
boost::bidirectional_iterator_test(start, v1, v2);
}
template <class CountingIterator, class Value>
void category_test(CountingIterator start, CountingIterator finish, Value v1, std::forward_iterator_tag)
{
Value v2 = v1;
++v2;
if (finish != start && finish != boost::next(start))
boost::forward_readable_iterator_test(start, finish, v1, v2);
}
template <class CountingIterator, class Value>
void test_aux(CountingIterator start, CountingIterator finish, Value v1)
{
typedef typename CountingIterator::iterator_category category;
typedef typename CountingIterator::value_type value_type;
// If it's a RandomAccessIterator we can do a few delicate tests
category_test(start, finish, v1, category());
// Okay, brute force...
for (CountingIterator p = start
; p != finish && boost::next(p) != finish
; ++p)
{
assert(boost::next(*p) == *boost::next(p));
}
// prove that a reference can be formed to these values
typedef typename CountingIterator::value_type value;
const value* q = &*start;
(void)q; // suppress unused variable warning
}
template <class Incrementable>
void test(Incrementable start, Incrementable finish)
{
test_aux(boost::make_counting_iterator(start), boost::make_counting_iterator(finish), start);
}
template <class Integer>
void test_integer(Integer* = 0) // default arg works around MSVC bug
{
Integer start = 0;
Integer finish = 120;
test(start, finish);
}
template <class Integer, class Category, class Difference>
void test_integer3(Integer* = 0, Category* = 0, Difference* = 0) // default arg works around MSVC bug
{
Integer start = 0;
Integer finish = 120;
typedef boost::counting_iterator<Integer,Category,Difference> iterator;
test_aux(iterator(start), iterator(finish), start);
}
template <class Container>
void test_container(Container* = 0) // default arg works around MSVC bug
{
Container c(1 + (unsigned)rand() % 1673);
const typename Container::iterator start = c.begin();
// back off by 1 to leave room for dereferenceable value at the end
typename Container::iterator finish = start;
std::advance(finish, c.size() - 1);
test(start, finish);
typedef typename Container::const_iterator const_iterator;
test(const_iterator(start), const_iterator(finish));
}
class my_int1 {
public:
my_int1() { }
my_int1(int x) : m_int(x) { }
my_int1& operator++() { ++m_int; return *this; }
bool operator==(const my_int1& x) const { return m_int == x.m_int; }
private:
int m_int;
};
class my_int2 {
public:
typedef void value_type;
typedef void pointer;
typedef void reference;
typedef std::ptrdiff_t difference_type;
typedef std::bidirectional_iterator_tag iterator_category;
my_int2() { }
my_int2(int x) : m_int(x) { }
my_int2& operator++() { ++m_int; return *this; }
my_int2& operator--() { --m_int; return *this; }
bool operator==(const my_int2& x) const { return m_int == x.m_int; }
private:
int m_int;
};
class my_int3 {
public:
typedef void value_type;
typedef void pointer;
typedef void reference;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
my_int3() { }
my_int3(int x) : m_int(x) { }
my_int3& operator++() { ++m_int; return *this; }
my_int3& operator+=(std::ptrdiff_t n) { m_int += n; return *this; }
std::ptrdiff_t operator-(const my_int3& x) const { return m_int - x.m_int; }
my_int3& operator--() { --m_int; return *this; }
bool operator==(const my_int3& x) const { return m_int == x.m_int; }
bool operator!=(const my_int3& x) const { return m_int != x.m_int; }
bool operator<(const my_int3& x) const { return m_int < x.m_int; }
private:
int m_int;
};
int main()
{
// Test the built-in integer types.
test_integer<char>();
test_integer<unsigned char>();
test_integer<signed char>();
test_integer<wchar_t>();
test_integer<short>();
test_integer<unsigned short>();
test_integer<int>();
test_integer<unsigned int>();
test_integer<long>();
test_integer<unsigned long>();
#if defined(BOOST_HAS_LONG_LONG)
test_integer<long long>();
test_integer<unsigned long long>();
#endif
// Test user-defined type.
test_integer3<my_int1, std::forward_iterator_tag, int>();
test_integer<my_int2>();
test_integer<my_int3>();
// Some tests on container iterators, to prove we handle a few different categories
test_container<std::vector<int> >();
test_container<std::list<int> >();
# ifndef BOOST_NO_SLIST
test_container<BOOST_STD_EXTENSION_NAMESPACE::slist<int> >();
# endif
// Also prove that we can handle raw pointers.
int array[2000];
test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1));
return 0;
}
+87
View File
@@ -0,0 +1,87 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/iterator/filter_iterator.hpp>
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <deque>
#include <iostream>
using boost::dummyT;
struct one_or_four
{
bool operator()(dummyT x) const
{
return x.foo() == 1 || x.foo() == 4;
}
};
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost { namespace detail
{
template<> struct iterator_traits<dummyT*>
: ptr_iter_traits<dummyT> {};
}}
#endif
template <class T> struct undefined;
// Test filter iterator
int main()
{
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
typedef boost::filter_iterator<one_or_four, dummyT*> filter_iter;
boost::bidirectional_readable_iterator_test(
filter_iter(one_or_four(), array, array+N)
, dummyT(1), dummyT(4));
BOOST_STATIC_ASSERT((
!boost::detail::is_tag<
boost::random_access_traversal_tag
, boost::traversal_category<filter_iter>::type
>::value
));
//# endif
// On compilers not supporting partial specialization, we can do more type
// deduction with deque iterators than with pointers... unless the library
// is broken ;-(
std::deque<dummyT> array2;
std::copy(array+0, array+N, std::back_inserter(array2));
boost::bidirectional_readable_iterator_test(
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
dummyT(1), dummyT(4));
boost::bidirectional_readable_iterator_test(
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
dummyT(1), dummyT(4));
boost::bidirectional_readable_iterator_test(
boost::make_filter_iterator(
one_or_four()
, boost::make_reverse_iterator(array2.end())
, boost::make_reverse_iterator(array2.begin())
),
dummyT(4), dummyT(1));
boost::bidirectional_readable_iterator_test(
filter_iter(array+0, array+N),
dummyT(1), dummyT(4));
boost::bidirectional_readable_iterator_test(
filter_iter(one_or_four(), array, array + N),
dummyT(1), dummyT(4));
std::cout << "test successful " << std::endl;
return 0;
}
+253
View File
@@ -0,0 +1,253 @@
// (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// Revision History
// 22 Nov 2002 Thomas Witt
// Added interoperability check.
// 08 Mar 2001 Jeremy Siek
// Moved test of indirect iterator into its own file. It to
// to be in iterator_adaptor_test.cpp.
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <boost/iterator/indirect_iterator.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/concept_archetype.hpp>
#include <boost/concept_check.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <stdlib.h>
#include <set>
#if !defined(__SGI_STL_PORT) \
&& (defined(BOOST_MSVC_STD_ITERATOR) \
|| BOOST_WORKAROUND(_CPPLIB_VER, <= 310) \
|| BOOST_WORKAROUND(__GNUC__, <= 2))
// std container random-access iterators don't support mutable/const
// interoperability (but may support const/mutable interop).
# define NO_MUTABLE_CONST_STD_DEQUE_ITERATOR_INTEROPERABILITY
# define NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
#endif
#if defined(BOOST_MSVC_STD_ITERATOR) \
|| defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
// No working iterator_traits implementation, so we must use deque
# define RA_CONTAINER std::deque
# include <deque>
# ifdef NO_MUTABLE_CONST_STD_DEQUE_ITERATOR_INTEROPERABILITY
# define NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
# endif
#else
# define RA_CONTAINER std::vector
# include <vector>
#endif
struct my_iterator_tag : public std::random_access_iterator_tag { };
using boost::dummyT;
typedef RA_CONTAINER<int> storage;
typedef RA_CONTAINER<int*> pointer_ra_container;
typedef std::set<storage::iterator> iterator_set;
template <class Container>
struct indirect_iterator_pair_generator
{
typedef boost::indirect_iterator<typename Container::iterator> iterator;
typedef boost::indirect_iterator<
typename Container::iterator
, typename iterator::value_type const
> const_iterator;
};
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost { namespace detail
{
template<> struct iterator_traits<int*>
: ptr_iter_traits<int> {};
template<> struct iterator_traits<dummyT*>
: ptr_iter_traits<dummyT> {};
template<> struct iterator_traits<dummyT*const>
: ptr_iter_traits<dummyT> {};
template<> struct iterator_traits<dummyT const*>
: ptr_iter_traits<dummyT, dummyT const> {};
template<> struct iterator_traits<dummyT**>
: ptr_iter_traits<dummyT*> {};
template<> struct iterator_traits<dummyT*const*>
: ptr_iter_traits<dummyT*const> {};
template<> struct iterator_traits<dummyT const*const*>
: ptr_iter_traits<dummyT const*, dummyT const*const> {};
}}
#endif
void more_indirect_iterator_tests()
{
# if 0
storage store(1000);
std::generate(store.begin(), store.end(), rand);
pointer_ra_container ptr_ra_container;
iterator_set iter_set;
for (storage::iterator p = store.begin(); p != store.end(); ++p)
{
ptr_ra_container.push_back(&*p);
iter_set.insert(p);
}
typedef indirect_iterator_pair_generator<pointer_ra_container> indirect_ra_container;
indirect_ra_container::iterator db(ptr_ra_container.begin());
indirect_ra_container::iterator de(ptr_ra_container.end());
assert(static_cast<std::size_t>(de - db) == store.size());
assert(db + store.size() == de);
indirect_ra_container::const_iterator dci = db;
assert(dci == db);
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
assert(db == dci);
#endif
assert(dci != de);
assert(dci < de);
assert(dci <= de);
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
assert(de >= dci);
assert(de > dci);
#endif
dci = de;
assert(dci == de);
boost::random_access_iterator_test(db + 1, store.size() - 1, boost::next(store.begin()));
*db = 999;
assert(store.front() == 999);
// Borland C++ is getting very confused about the typedefs here
typedef boost::indirect_iterator<iterator_set::iterator> indirect_set_iterator;
typedef boost::indirect_iterator<
iterator_set::iterator
, iterator_set::iterator::value_type const
> const_indirect_set_iterator;
indirect_set_iterator sb(iter_set.begin());
indirect_set_iterator se(iter_set.end());
const_indirect_set_iterator sci(iter_set.begin());
assert(sci == sb);
# ifndef NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
assert(se != sci);
# endif
assert(sci != se);
sci = se;
assert(sci == se);
*boost::prior(se) = 888;
assert(store.back() == 888);
assert(std::equal(sb, se, store.begin()));
boost::bidirectional_iterator_test(boost::next(sb), store[1], store[2]);
assert(std::equal(db, de, store.begin()));
#endif
}
int
main()
{
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
typedef RA_CONTAINER<boost::shared_ptr<dummyT> > shared_t;
shared_t shared;
// Concept checks
{
typedef boost::indirect_iterator<shared_t::iterator> iter_t;
BOOST_STATIC_ASSERT(
boost::detail::has_element_type<
boost::shared_ptr<dummyT>
// std::iterator_traits<shared_t::iterator>::value_type
>::value
);
typedef boost::indirect_iterator<
shared_t::iterator
, boost::iterator_value<shared_t::iterator>::type const
> c_iter_t;
# ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
boost::function_requires< boost_concepts::InteroperableConcept<iter_t, c_iter_t> >();
# endif
}
// Test indirect_iterator_generator
{
for (int jj = 0; jj < N; ++jj)
shared.push_back(boost::shared_ptr<dummyT>(new dummyT(jj)));
dummyT* ptr[N];
for (int k = 0; k < N; ++k)
ptr[k] = array + k;
typedef boost::indirect_iterator<dummyT**> indirect_iterator;
typedef boost::indirect_iterator<dummyT**, dummyT const>
const_indirect_iterator;
indirect_iterator i(ptr);
boost::random_access_iterator_test(i, N, array);
boost::random_access_iterator_test(
boost::indirect_iterator<shared_t::iterator>(shared.begin())
, N, array);
boost::random_access_iterator_test(boost::make_indirect_iterator(ptr), N, array);
// check operator->
assert((*i).m_x == i->foo());
const_indirect_iterator j(ptr);
boost::random_access_iterator_test(j, N, array);
dummyT const*const* const_ptr = ptr;
boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array);
boost::const_nonconst_iterator_test(i, ++j);
more_indirect_iterator_tests();
}
std::cout << "test successful " << std::endl;
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
// Copyright Thomas Witt 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/iterator/indirect_iterator.hpp>
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/concept_check.hpp>
#include <boost/cstdlib.hpp>
#include <list>
int main()
{
{
typedef boost::reverse_iterator<std::list<int*>::iterator> rev_iter;
typedef boost::indirect_iterator<std::list<int*>::iterator> ind_iter;
ind_iter() == rev_iter();
}
return boost::exit_success;
}
+11
View File
@@ -0,0 +1,11 @@
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/cstdlib.hpp>
int main()
{
typedef boost::reverse_iterator<int*> rev_iter1;
typedef boost::reverse_iterator<char*> rev_iter2;
return boost::is_convertible<rev_iter1, rev_iter2>::value
? boost::exit_failure : boost::exit_success;
}
+40
View File
@@ -0,0 +1,40 @@
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/concept_check.hpp>
#include <boost/cstdlib.hpp>
#include <list>
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost { namespace detail
{
template<> struct iterator_traits<int*>
: ptr_iter_traits<int> {};
template<> struct iterator_traits<int const*>
: ptr_iter_traits<int, int const> {};
}}
#endif
int main()
{
{
typedef boost::reverse_iterator<int*> rev_iter;
typedef boost::reverse_iterator<int const*> c_rev_iter;
boost::function_requires< boost_concepts::WritableLvalueIteratorConcept<rev_iter> >();
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<rev_iter> >();
boost::function_requires< boost::RandomAccessIteratorConcept<rev_iter> >();
boost::function_requires< boost_concepts::InteroperableConcept<rev_iter, c_rev_iter> >();
}
{
typedef boost::reverse_iterator<std::list<int>::iterator> rev_iter;
typedef boost::reverse_iterator<std::list<int>::const_iterator> c_rev_iter;
boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept<c_rev_iter> >();
boost::function_requires< boost_concepts::BidirectionalTraversalConcept<c_rev_iter> >();
boost::function_requires< boost::BidirectionalIteratorConcept<c_rev_iter> >();
boost::function_requires< boost_concepts::InteroperableConcept<rev_iter, c_rev_iter> >();
}
return boost::exit_success;
}
+261
View File
@@ -0,0 +1,261 @@
// (C) Copyright Thomas Witt 2003. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// See http://www.boost.org for most recent version including documentation.
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/pending/iterator_tests.hpp>
#include <stdlib.h>
#include <vector>
#include <deque>
#include <set>
#include <list>
#include "static_assert_same.hpp"
struct my_iterator_tag : public std::random_access_iterator_tag { };
using boost::dummyT;
struct mult_functor {
typedef int result_type;
typedef int argument_type;
// Functors used with transform_iterator must be
// DefaultConstructible, as the transform_iterator must be
// DefaultConstructible to satisfy the requirements for
// TrivialIterator.
mult_functor() { }
mult_functor(int aa) : a(aa) { }
int operator()(int b) const { return a * b; }
int a;
};
template <class Pair>
struct select1st_
: public std::unary_function<Pair, typename Pair::first_type>
{
const typename Pair::first_type& operator()(const Pair& x) const {
return x.first;
}
typename Pair::first_type& operator()(Pair& x) const {
return x.first;
}
};
struct one_or_four {
bool operator()(dummyT x) const {
return x.foo() == 1 || x.foo() == 4;
}
};
typedef std::deque<int> storage;
typedef std::deque<int*> pointer_deque;
typedef std::set<storage::iterator> iterator_set;
template <class T> struct foo;
void blah(int) { }
struct my_gen
{
typedef int result_type;
my_gen() : n(0) { }
int operator()() { return ++n; }
int n;
};
template <class V>
struct ptr_iterator
: boost::iterator_adaptor<
ptr_iterator<V>
, V*
, V
, std::random_access_iterator_tag
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
, V&
#endif
>
{
private:
typedef boost::iterator_adaptor<
ptr_iterator<V>
, V*
, V
, std::random_access_iterator_tag
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
, V&
#endif
> super_t;
public:
ptr_iterator() { }
ptr_iterator(V* d) : super_t(d) { }
template <class V2>
ptr_iterator(
const ptr_iterator<V2>& x
, typename boost::enable_if_convertible<V2*, V*>::type* = 0
)
: super_t(x.base())
{}
};
template <class T>
struct fwd_iterator
: boost::iterator_adaptor<
fwd_iterator<T>
, boost::forward_iterator_archetype<T>
>
{
private:
typedef boost::iterator_adaptor<
fwd_iterator<T>
, boost::forward_iterator_archetype<T>
> super_t;
public:
fwd_iterator() { }
fwd_iterator(boost::forward_iterator_archetype<T> d) : super_t(d) { }
};
template <class T>
struct in_iterator
: boost::iterator_adaptor<
in_iterator<T>
, boost::input_iterator_archetype<T>
>
{
private:
typedef boost::iterator_adaptor<
in_iterator<T>
, boost::input_iterator_archetype<T>
> super_t;
public:
in_iterator() { }
in_iterator(boost::input_iterator_archetype<T> d) : super_t(d) { }
};
template <class Iter>
struct constant_iterator
: boost::iterator_adaptor<
constant_iterator<Iter>
, Iter
, typename std::iterator_traits<Iter>::value_type const
>
{
typedef boost::iterator_adaptor<
constant_iterator<Iter>
, Iter
, typename std::iterator_traits<Iter>::value_type const
> base_t;
constant_iterator() {}
constant_iterator(Iter it)
: base_t(it) {}
};
int
main()
{
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
// sanity check, if this doesn't pass the test is buggy
boost::random_access_iterator_test(array, N, array);
// Test the iterator_adaptor
{
ptr_iterator<dummyT> i(array);
boost::random_access_iterator_test(i, N, array);
ptr_iterator<const dummyT> j(array);
boost::random_access_iterator_test(j, N, array);
boost::const_nonconst_iterator_test(i, ++j);
}
int test;
// Test the iterator_traits
{
// Test computation of defaults
typedef ptr_iterator<int> Iter1;
// don't use std::iterator_traits here to avoid VC++ problems
test = static_assert_same<Iter1::value_type, int>::value;
test = static_assert_same<Iter1::reference, int&>::value;
test = static_assert_same<Iter1::pointer, int*>::value;
test = static_assert_same<Iter1::difference_type, std::ptrdiff_t>::value;
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
BOOST_STATIC_ASSERT((boost::is_convertible<Iter1::iterator_category, std::random_access_iterator_tag>::value));
#endif
}
{
// Test computation of default when the Value is const
typedef ptr_iterator<int const> Iter1;
test = static_assert_same<Iter1::value_type, int>::value;
test = static_assert_same<Iter1::reference, const int&>::value;
test = static_assert_same<Iter1::iterator_category::access, boost::readable_lvalue_iterator_tag>::value; test = static_assert_same<Iter1::pointer, const int*>::value;
}
{
// Test constant iterator idiom
typedef ptr_iterator<int> BaseIter;
typedef constant_iterator<BaseIter> Iter;
test = static_assert_same<Iter::value_type, int>::value;
test = static_assert_same<Iter::reference, int const&>::value;
test = static_assert_same<Iter::pointer, int const*>::value;
test = static_assert_same<BaseIter::iterator_category::access, boost::writable_lvalue_iterator_tag>::value;
test = static_assert_same<Iter::iterator_category::access, boost::readable_lvalue_iterator_tag>::value;
}
// Test the iterator_adaptor
{
ptr_iterator<dummyT> i(array);
boost::random_access_iterator_test(i, N, array);
ptr_iterator<const dummyT> j(array);
boost::random_access_iterator_test(j, N, array);
boost::const_nonconst_iterator_test(i, ++j);
}
// check operator-> with a forward iterator
{
boost::forward_iterator_archetype<dummyT> forward_iter;
typedef fwd_iterator<dummyT> adaptor_type;
adaptor_type i(forward_iter);
int zero = 0;
if (zero) // don't do this, just make sure it compiles
assert((*i).m_x == i->foo());
}
// check operator-> with an input iterator
{
boost::input_iterator_archetype<dummyT> input_iter;
typedef in_iterator<dummyT> adaptor_type;
adaptor_type i(input_iter);
int zero = 0;
if (zero) // don't do this, just make sure it compiles
assert((*i).m_x == i->foo());
}
std::cout << "test successful " << std::endl;
(void)test;
return 0;
}
+25
View File
@@ -0,0 +1,25 @@
//
// Copyright Thomas Witt 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
#include <boost/iterator/iterator_archetypes.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/concept_check.hpp>
int main()
{
{
typedef boost::iterator_archetype<int,
boost::writable_lvalue_iterator_tag,
boost::random_access_traversal_tag> iter;
boost::function_requires< boost_concepts::WritableLvalueIteratorConcept<iter> >();
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<iter> >();
}
return 0; // keep msvc happy
}
+101
View File
@@ -0,0 +1,101 @@
// (C) Copyright Toon Knapen 2001.
// (C) Copyright Roland Richter 2003.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
#include <boost/config.hpp>
#include <boost/test/minimal.hpp>
#include <boost/iterator/permutation_iterator.hpp>
#include <vector>
#include <list>
#include <algorithm>
void permutation_test()
{
// Example taken from documentation of old permutation_iterator.
typedef std::vector< int > element_range_type;
typedef std::list< int > index_type;
const int element_range_size = 10;
const int index_size = 4;
element_range_type elements( element_range_size );
for( element_range_type::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it )
{ *el_it = std::distance(elements.begin(), el_it); }
index_type indices( index_size );
for( index_type::iterator i_it = indices.begin(); i_it != indices.end(); ++i_it )
{ *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it); }
std::reverse( indices.begin(), indices.end() );
#ifdef BOOST_MSVC
typedef boost::permutation_iterator< element_range_type::iterator
, index_type::iterator
, boost::use_default
, boost::use_default
, element_range_type::reference > permutation_type;
permutation_type begin( elements.begin(), indices.begin() );
permutation_type it = begin;
permutation_type end( elements.begin(), indices.end() );
#else
typedef boost::permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type;
permutation_type begin = boost::make_permutation_iterator( elements.begin(), indices.begin() );
permutation_type it = begin;
permutation_type end = boost::make_permutation_iterator( elements.begin(), indices.end() );
#endif
BOOST_CHECK( it == begin );
BOOST_CHECK( it != end );
BOOST_CHECK( std::distance( begin, end ) == index_size );
for( index_type::iterator i_it = indices.begin(); it != end; ++i_it, ++it )
{
BOOST_CHECK( *it == elements[ *i_it ] );
}
it = begin;
for( int i = 0; i < index_size ; i+=2, it+=2 )
{
index_type::iterator i_it = indices.begin(); std::advance( i_it, i );
BOOST_CHECK( *it == elements[ *i_it ] );
}
it = begin + (index_size);
BOOST_CHECK( it != begin );
for( index_type::iterator i_it = --indices.end(); it-- != begin; --i_it )
{
BOOST_CHECK( *it == elements[ *i_it ] );
}
it = begin + (index_size - 1);
for( int i = 0; i < index_size; i+=2, it-=2 )
{
index_type::iterator i_it = --indices.end(); std::advance( i_it, -i );
BOOST_CHECK( *it == elements[ *i_it ] );
}
}
int test_main(int, char *[])
{
permutation_test();
bool error_on_purpose = false;
//BOOST_CHECK( error_on_purpose );
return 0;
}
+97
View File
@@ -0,0 +1,97 @@
// Copyright Thomas Witt 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <algorithm>
#include <deque>
using boost::dummyT;
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost
{
namespace detail
{
template<> struct iterator_traits<dummyT*>
: ptr_iter_traits<dummyT> {};
template<> struct iterator_traits<dummyT const*>
: ptr_iter_traits<dummyT const> {};
}
}
#endif
// Test reverse iterator
int main()
{
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
// Test reverse_iterator_generator
{
dummyT reversed[N];
std::copy(array, array + N, reversed);
std::reverse(reversed, reversed + N);
typedef boost::reverse_iterator<dummyT*> reverse_iterator;
reverse_iterator i(reversed + N);
boost::random_access_iterator_test(i, N, array);
boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array);
typedef boost::reverse_iterator<const dummyT*> const_reverse_iterator;
const_reverse_iterator j(reversed + N);
boost::random_access_iterator_test(j, N, array);
const dummyT* const_reversed = reversed;
boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array);
boost::const_nonconst_iterator_test(i, ++j);
}
// Test reverse_iterator_generator again, with traits fully deducible on all platforms
{
std::deque<dummyT> reversed_container;
std::reverse_copy(array, array + N, std::back_inserter(reversed_container));
const std::deque<dummyT>::iterator reversed = reversed_container.begin();
typedef boost::reverse_iterator<
std::deque<dummyT>::iterator> reverse_iterator;
typedef boost::reverse_iterator<
std::deque<dummyT>::const_iterator> const_reverse_iterator;
// MSVC/STLport gives an INTERNAL COMPILER ERROR when any computation
// (e.g. "reversed + N") is used in the constructor below.
const std::deque<dummyT>::iterator finish = reversed_container.end();
reverse_iterator i(finish);
boost::random_access_iterator_test(i, N, array);
boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array);
const_reverse_iterator j = reverse_iterator(finish);
boost::random_access_iterator_test(j, N, array);
const std::deque<dummyT>::const_iterator const_reversed = reversed;
boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array);
// Many compilers' builtin deque iterators don't interoperate well, though
// STLport fixes that problem.
#if defined(__SGI_STL_PORT) \
|| !BOOST_WORKAROUND(__GNUC__, <= 2) \
&& !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) \
&& !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 1)
boost::const_nonconst_iterator_test(i, ++j);
#endif
}
return 0;
}
+31
View File
@@ -0,0 +1,31 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#ifndef STATIC_ASSERT_SAME_DWA2003530_HPP
# define STATIC_ASSERT_SAME_DWA2003530_HPP
# include <boost/type.hpp>
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T, class U>
struct static_assert_same;
template <class T>
struct static_assert_same<T,T>
{
enum { value = 1 };
};
#else
# include <boost/mpl/if.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/type_traits/is_same.hpp>
template <class T, class U>
struct static_assert_same
: boost::mpl::if_<boost::is_same<T,U>,boost::mpl::true_,void>::type
{};
#endif
#endif // STATIC_ASSERT_SAME_DWA2003530_HPP
+248
View File
@@ -0,0 +1,248 @@
// (C) Copyright Jeremy Siek 2002. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// Revision History
// 22 Nov 2002 Thomas Witt
// Added interoperability check.
// 28 Oct 2002 Jeremy Siek
// Updated for new iterator adaptors.
// 08 Mar 2001 Jeremy Siek
// Moved test of transform iterator into its own file. It to
// to be in iterator_adaptor_test.cpp.
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <boost/pending/iterator_tests.hpp>
#include <boost/bind.hpp>
#include <boost/concept_check.hpp>
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost { namespace detail
{
template<> struct iterator_traits<int*>
: ptr_iter_traits<int> {};
template<> struct iterator_traits<std::pair<int, int>*>
: ptr_iter_traits<std::pair<int, int> > {};
template<> struct iterator_traits<int const*>
: ptr_iter_traits<int, int const> {};
template<> struct iterator_traits<std::pair<int, int> const*>
: ptr_iter_traits<std::pair<int, int>, std::pair<int, int> const> {};
}}
#endif
struct mult_functor {
// Functors used with transform_iterator must be
// DefaultConstructible, as the transform_iterator must be
// DefaultConstructible to satisfy the requirements for
// TrivialIterator.
mult_functor() { }
mult_functor(int aa) : a(aa) { }
int operator()(int b) const { return a * b; }
int a;
};
struct adaptable_mult_functor
: mult_functor
{
typedef int result_type;
typedef int argument_type;
// Functors used with transform_iterator must be
// DefaultConstructible, as the transform_iterator must be
// DefaultConstructible to satisfy the requirements for
// TrivialIterator.
adaptable_mult_functor() { }
adaptable_mult_functor(int aa) : mult_functor(aa) { }
};
struct select_first
{
typedef int& result_type;
int& operator()(std::pair<int, int>& p) const
{
return p.first;
}
};
struct select_second
{
typedef int& result_type;
int& operator()(std::pair<int, int>& p) const
{
return p.second;
}
};
struct const_select_first
{
typedef int const& result_type;
int const& operator()(std::pair<int, int>const& p) const
{
return p.first;
}
};
struct value_select_first
{
typedef int result_type;
int operator()(std::pair<int, int>const& p) const
{
return p.first;
}
};
int mult_2(int arg)
{
return arg*2;
}
int
main()
{
const int N = 10;
// Concept checks
{
typedef boost::transform_iterator<adaptable_mult_functor, int*> iter_t;
typedef boost::transform_iterator<adaptable_mult_functor, int const*> c_iter_t;
boost::function_requires< boost_concepts::InteroperableConcept<iter_t, c_iter_t> >();
}
// Test transform_iterator
{
int x[N], y[N];
for (int k = 0; k < N; ++k)
x[k] = k;
std::copy(x, x + N, y);
for (int k2 = 0; k2 < N; ++k2)
x[k2] = x[k2] * 2;
typedef boost::transform_iterator<adaptable_mult_functor, int*> iter_t;
iter_t i(y, adaptable_mult_functor(2));
boost::input_iterator_test(i, x[0], x[1]);
boost::input_iterator_test(iter_t(&y[0], adaptable_mult_functor(2)), x[0], x[1]);
boost::random_access_readable_iterator_test(i, N, x);
}
// Test transform_iterator non adaptable functor
{
int x[N], y[N];
for (int k = 0; k < N; ++k)
x[k] = k;
std::copy(x, x + N, y);
for (int k2 = 0; k2 < N; ++k2)
x[k2] = x[k2] * 2;
typedef boost::transform_iterator<mult_functor, int*, int> iter_t;
iter_t i(y, mult_functor(2));
boost::input_iterator_test(i, x[0], x[1]);
boost::input_iterator_test(iter_t(&y[0], mult_functor(2)), x[0], x[1]);
boost::random_access_readable_iterator_test(i, N, x);
}
// Test transform_iterator default argument handling
{
{
typedef boost::transform_iterator<adaptable_mult_functor, int*, float> iter_t;
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, float>::value));
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, float>::value));
}
{
typedef boost::transform_iterator<adaptable_mult_functor, int*, boost::use_default, float> iter_t;
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, float>::value));
}
{
typedef boost::transform_iterator<adaptable_mult_functor, int*, float, double> iter_t;
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, float>::value));
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, double>::value));
}
}
// Test transform_iterator with function pointers
{
int x[N], y[N];
for (int k = 0; k < N; ++k)
x[k] = k;
std::copy(x, x + N, y);
for (int k2 = 0; k2 < N; ++k2)
x[k2] = x[k2] * 2;
boost::input_iterator_test(boost::make_transform_iterator(y, mult_2)
, x[0]
, x[1]);
boost::input_iterator_test(boost::make_transform_iterator(&y[0], mult_2)
, x[0]
, x[1]);
boost::random_access_readable_iterator_test(boost::make_transform_iterator(y, mult_2)
, N
, x);
}
// Test transform_iterator as projection iterator
{
typedef std::pair<int, int> pair_t;
int x[N];
int y[N];
pair_t values[N];
for(int i = 0; i < N; ++i) {
x[i] = i;
y[i] = N - (i + 1);
}
std::copy(x,
x + N,
boost::make_transform_iterator((pair_t*)values, select_first()));
std::copy(y,
y + N,
boost::make_transform_iterator((pair_t*)values, select_second()));
boost::random_access_readable_iterator_test(boost::make_transform_iterator((pair_t*)values, value_select_first()),
N,
x);
boost::random_access_readable_iterator_test(boost::make_transform_iterator((pair_t*)values, const_select_first()),
N,
x);
boost::constant_lvalue_iterator_test(boost::make_transform_iterator((pair_t*)values, const_select_first()), x[0]);
boost::mutable_lvalue_iterator_test(boost::make_transform_iterator((pair_t*)values, select_first()), x[0], 17);
}
std::cout << "test successful " << std::endl;
return 0;
}
+103
View File
@@ -0,0 +1,103 @@
// Copyright David Abrahams 2003. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/static_assert.hpp>
#include "static_assert_same.hpp"
struct X { int a; };
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost { namespace detail {
template<> struct iterator_traits<X*>
: ptr_iter_traits<X> {};
}}
#endif
struct Xiter : boost::iterator_adaptor<Xiter,X*>
{
Xiter();
Xiter(X* p) : boost::iterator_adaptor<Xiter, X*>(p) {}
};
void take_xptr(X*) {}
void operator_arrow_test()
{
// check that the operator-> result is a pointer for lvalue iterators
X x;
take_xptr(Xiter(&x).operator->());
}
template <class T, class U, class Min>
struct static_assert_min_cat
: static_assert_same<
typename boost::detail::minimum_category<T,U>::type, Min
>
{};
void category_test()
{
using namespace boost;
using namespace boost::detail;
BOOST_STATIC_ASSERT((
!is_tag<
input_output_iterator_tag
, std::input_iterator_tag>::value));
BOOST_STATIC_ASSERT((
!is_tag<
input_output_iterator_tag
, std::output_iterator_tag>::value));
BOOST_STATIC_ASSERT((
is_tag<
std::input_iterator_tag
, input_output_iterator_tag>::value));
BOOST_STATIC_ASSERT((
is_tag<
std::output_iterator_tag
, input_output_iterator_tag>::value));
BOOST_STATIC_ASSERT((
is_tag<
input_output_iterator_tag
, std::forward_iterator_tag>::value));
int test = static_assert_min_cat<
std::input_iterator_tag,input_output_iterator_tag, std::input_iterator_tag
>::value;
test = static_assert_min_cat<
input_output_iterator_tag,std::input_iterator_tag, std::input_iterator_tag
>::value;
test = static_assert_min_cat<
input_output_iterator_tag,std::forward_iterator_tag, input_output_iterator_tag
>::value;
test = static_assert_min_cat<
std::input_iterator_tag,std::forward_iterator_tag, std::input_iterator_tag
>::value;
test = static_assert_min_cat<
std::input_iterator_tag,std::random_access_iterator_tag, std::input_iterator_tag
>::value;
test = static_assert_min_cat<
std::output_iterator_tag,std::random_access_iterator_tag, std::output_iterator_tag
>::value;
(void)test;
}
int main()
{
category_test();
operator_arrow_test();
return 0;
}