home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: Tape Archive
(archive/tar).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| Tape Archive (archive/tar)
| magic
| Supported |
100%
| file
| POSIX tar archive
| default
| |
99%
| file
| POSIX tar archive, file algo.h, mode 000644 , uid 062616 , gid 000012 , size 00000235235 , seconds 06315624673, user austern, group engr
| default
| |
98%
| file
| data
| default
| |
41%
| TrID
| Sybase iAnywhere database files
| default (weak)
| |
36%
| TrID
| TAR - Tape ARchive (POSIX)
| default
| |
21%
| TrID
| TAR - Tape ARchive (file)
| default
| |
100%
| siegfried
| x-fmt/265 Tape Archive Format
| default
| |
100%
| lsar
| Tar
| default
| |
100%
| gt2
| TAR Archiv gefunden (Auflistung ist deaktiviert)
| default
| |
100%
| disktype
| POSIX tar archive
| default
| |
100%
| detectItEasy
| Archive: tar
| default
| |
100%
| binwalkID
| POSIX tar archive
| default
| |
100%
| xdgMime
| application/x-tar
| default
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 61 6c 67 6f 2e 68 00 00 | 00 00 00 00 00 00 00 00 |algo.h..|........|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000050| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000060| 00 00 00 00 30 30 30 36 | 34 34 20 00 30 36 32 36 |....0006|44 .0626|
|00000070| 31 36 20 00 30 30 30 30 | 31 32 20 00 30 30 30 30 |16 .0000|12 .0000|
|00000080| 30 32 33 35 32 33 35 20 | 30 36 33 31 35 36 32 34 |0235235 |06315624|
|00000090| 36 37 33 20 30 31 32 36 | 35 33 00 20 30 00 00 00 |673 0126|53. 0...|
|000000a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000100| 00 75 73 74 61 72 00 30 | 30 61 75 73 74 65 72 6e |.ustar.0|0austern|
|00000110| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000120| 00 00 00 00 00 00 00 00 | 00 65 6e 67 72 00 00 00 |........|.engr...|
|00000130| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000140| 00 00 00 00 00 00 00 00 | 00 30 30 30 30 30 30 20 |........|.000000 |
|00000150| 00 30 30 30 30 30 30 20 | 00 00 00 00 00 00 00 00 |.000000 |........|
|00000160| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000170| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000180| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000190| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000001f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000200| 2f 2a 0a 20 2a 0a 20 2a | 20 43 6f 70 79 72 69 67 |/*. *. *| Copyrig|
|00000210| 68 74 20 28 63 29 20 31 | 39 39 34 0a 20 2a 20 48 |ht (c) 1|994. * H|
|00000220| 65 77 6c 65 74 74 2d 50 | 61 63 6b 61 72 64 20 43 |ewlett-P|ackard C|
|00000230| 6f 6d 70 61 6e 79 0a 20 | 2a 0a 20 2a 20 50 65 72 |ompany. |*. * Per|
|00000240| 6d 69 73 73 69 6f 6e 20 | 74 6f 20 75 73 65 2c 20 |mission |to use, |
|00000250| 63 6f 70 79 2c 20 6d 6f | 64 69 66 79 2c 20 64 69 |copy, mo|dify, di|
|00000260| 73 74 72 69 62 75 74 65 | 20 61 6e 64 20 73 65 6c |stribute| and sel|
|00000270| 6c 20 74 68 69 73 20 73 | 6f 66 74 77 61 72 65 0a |l this s|oftware.|
|00000280| 20 2a 20 61 6e 64 20 69 | 74 73 20 64 6f 63 75 6d | * and i|ts docum|
|00000290| 65 6e 74 61 74 69 6f 6e | 20 66 6f 72 20 61 6e 79 |entation| for any|
|000002a0| 20 70 75 72 70 6f 73 65 | 20 69 73 20 68 65 72 65 | purpose| is here|
|000002b0| 62 79 20 67 72 61 6e 74 | 65 64 20 77 69 74 68 6f |by grant|ed witho|
|000002c0| 75 74 20 66 65 65 2c 0a | 20 2a 20 70 72 6f 76 69 |ut fee,.| * provi|
|000002d0| 64 65 64 20 74 68 61 74 | 20 74 68 65 20 61 62 6f |ded that| the abo|
|000002e0| 76 65 20 63 6f 70 79 72 | 69 67 68 74 20 6e 6f 74 |ve copyr|ight not|
|000002f0| 69 63 65 20 61 70 70 65 | 61 72 20 69 6e 20 61 6c |ice appe|ar in al|
|00000300| 6c 20 63 6f 70 69 65 73 | 20 61 6e 64 0a 20 2a 20 |l copies| and. * |
|00000310| 74 68 61 74 20 62 6f 74 | 68 20 74 68 61 74 20 63 |that bot|h that c|
|00000320| 6f 70 79 72 69 67 68 74 | 20 6e 6f 74 69 63 65 20 |opyright| notice |
|00000330| 61 6e 64 20 74 68 69 73 | 20 70 65 72 6d 69 73 73 |and this| permiss|
|00000340| 69 6f 6e 20 6e 6f 74 69 | 63 65 20 61 70 70 65 61 |ion noti|ce appea|
|00000350| 72 0a 20 2a 20 69 6e 20 | 73 75 70 70 6f 72 74 69 |r. * in |supporti|
|00000360| 6e 67 20 64 6f 63 75 6d | 65 6e 74 61 74 69 6f 6e |ng docum|entation|
|00000370| 2e 20 20 48 65 77 6c 65 | 74 74 2d 50 61 63 6b 61 |. Hewle|tt-Packa|
|00000380| 72 64 20 43 6f 6d 70 61 | 6e 79 20 6d 61 6b 65 73 |rd Compa|ny makes|
|00000390| 20 6e 6f 0a 20 2a 20 72 | 65 70 72 65 73 65 6e 74 | no. * r|epresent|
|000003a0| 61 74 69 6f 6e 73 20 61 | 62 6f 75 74 20 74 68 65 |ations a|bout the|
|000003b0| 20 73 75 69 74 61 62 69 | 6c 69 74 79 20 6f 66 20 | suitabi|lity of |
|000003c0| 74 68 69 73 20 73 6f 66 | 74 77 61 72 65 20 66 6f |this sof|tware fo|
|000003d0| 72 20 61 6e 79 0a 20 2a | 20 70 75 72 70 6f 73 65 |r any. *| purpose|
|000003e0| 2e 20 20 49 74 20 69 73 | 20 70 72 6f 76 69 64 65 |. It is| provide|
|000003f0| 64 20 22 61 73 20 69 73 | 22 20 77 69 74 68 6f 75 |d "as is|" withou|
|00000400| 74 20 65 78 70 72 65 73 | 73 20 6f 72 20 69 6d 70 |t expres|s or imp|
|00000410| 6c 69 65 64 20 77 61 72 | 72 61 6e 74 79 2e 0a 20 |lied war|ranty.. |
|00000420| 2a 0a 20 2a 0a 20 2a 20 | 43 6f 70 79 72 69 67 68 |*. *. * |Copyrigh|
|00000430| 74 20 28 63 29 20 31 39 | 39 36 0a 20 2a 20 53 69 |t (c) 19|96. * Si|
|00000440| 6c 69 63 6f 6e 20 47 72 | 61 70 68 69 63 73 20 43 |licon Gr|aphics C|
|00000450| 6f 6d 70 75 74 65 72 20 | 53 79 73 74 65 6d 73 2c |omputer |Systems,|
|00000460| 20 49 6e 63 2e 0a 20 2a | 0a 20 2a 20 50 65 72 6d | Inc.. *|. * Perm|
|00000470| 69 73 73 69 6f 6e 20 74 | 6f 20 75 73 65 2c 20 63 |ission t|o use, c|
|00000480| 6f 70 79 2c 20 6d 6f 64 | 69 66 79 2c 20 64 69 73 |opy, mod|ify, dis|
|00000490| 74 72 69 62 75 74 65 20 | 61 6e 64 20 73 65 6c 6c |tribute |and sell|
|000004a0| 20 74 68 69 73 20 73 6f | 66 74 77 61 72 65 0a 20 | this so|ftware. |
|000004b0| 2a 20 61 6e 64 20 69 74 | 73 20 64 6f 63 75 6d 65 |* and it|s docume|
|000004c0| 6e 74 61 74 69 6f 6e 20 | 66 6f 72 20 61 6e 79 20 |ntation |for any |
|000004d0| 70 75 72 70 6f 73 65 20 | 69 73 20 68 65 72 65 62 |purpose |is hereb|
|000004e0| 79 20 67 72 61 6e 74 65 | 64 20 77 69 74 68 6f 75 |y grante|d withou|
|000004f0| 74 20 66 65 65 2c 0a 20 | 2a 20 70 72 6f 76 69 64 |t fee,. |* provid|
|00000500| 65 64 20 74 68 61 74 20 | 74 68 65 20 61 62 6f 76 |ed that |the abov|
|00000510| 65 20 63 6f 70 79 72 69 | 67 68 74 20 6e 6f 74 69 |e copyri|ght noti|
|00000520| 63 65 20 61 70 70 65 61 | 72 20 69 6e 20 61 6c 6c |ce appea|r in all|
|00000530| 20 63 6f 70 69 65 73 20 | 61 6e 64 0a 20 2a 20 74 | copies |and. * t|
|00000540| 68 61 74 20 62 6f 74 68 | 20 74 68 61 74 20 63 6f |hat both| that co|
|00000550| 70 79 72 69 67 68 74 20 | 6e 6f 74 69 63 65 20 61 |pyright |notice a|
|00000560| 6e 64 20 74 68 69 73 20 | 70 65 72 6d 69 73 73 69 |nd this |permissi|
|00000570| 6f 6e 20 6e 6f 74 69 63 | 65 20 61 70 70 65 61 72 |on notic|e appear|
|00000580| 0a 20 2a 20 69 6e 20 73 | 75 70 70 6f 72 74 69 6e |. * in s|upportin|
|00000590| 67 20 64 6f 63 75 6d 65 | 6e 74 61 74 69 6f 6e 2e |g docume|ntation.|
|000005a0| 20 20 53 69 6c 69 63 6f | 6e 20 47 72 61 70 68 69 | Silico|n Graphi|
|000005b0| 63 73 20 6d 61 6b 65 73 | 20 6e 6f 0a 20 2a 20 72 |cs makes| no. * r|
|000005c0| 65 70 72 65 73 65 6e 74 | 61 74 69 6f 6e 73 20 61 |epresent|ations a|
|000005d0| 62 6f 75 74 20 74 68 65 | 20 73 75 69 74 61 62 69 |bout the| suitabi|
|000005e0| 6c 69 74 79 20 6f 66 20 | 74 68 69 73 20 73 6f 66 |lity of |this sof|
|000005f0| 74 77 61 72 65 20 66 6f | 72 20 61 6e 79 0a 20 2a |tware fo|r any. *|
|00000600| 20 70 75 72 70 6f 73 65 | 2e 20 20 49 74 20 69 73 | purpose|. It is|
|00000610| 20 70 72 6f 76 69 64 65 | 64 20 22 61 73 20 69 73 | provide|d "as is|
|00000620| 22 20 77 69 74 68 6f 75 | 74 20 65 78 70 72 65 73 |" withou|t expres|
|00000630| 73 20 6f 72 20 69 6d 70 | 6c 69 65 64 20 77 61 72 |s or imp|lied war|
|00000640| 72 61 6e 74 79 2e 0a 20 | 2a 2f 0a 0a 23 69 66 6e |ranty.. |*/..#ifn|
|00000650| 64 65 66 20 41 4c 47 4f | 5f 48 0a 23 64 65 66 69 |def ALGO|_H.#defi|
|00000660| 6e 65 20 41 4c 47 4f 5f | 48 0a 0a 23 69 6e 63 6c |ne ALGO_|H..#incl|
|00000670| 75 64 65 20 3c 73 74 64 | 6c 69 62 2e 68 3e 0a 23 |ude <std|lib.h>.#|
|00000680| 69 6e 63 6c 75 64 65 20 | 3c 6c 69 6d 69 74 73 2e |include |<limits.|
|00000690| 68 3e 0a 23 69 6e 63 6c | 75 64 65 20 3c 61 6c 67 |h>.#incl|ude <alg|
|000006a0| 6f 62 61 73 65 2e 68 3e | 0a 23 69 6e 63 6c 75 64 |obase.h>|.#includ|
|000006b0| 65 20 3c 68 65 61 70 2e | 68 3e 0a 23 69 6e 63 6c |e <heap.|h>.#incl|
|000006c0| 75 64 65 20 3c 74 65 6d | 70 62 75 66 2e 68 3e 0a |ude <tem|pbuf.h>.|
|000006d0| 0a 74 65 6d 70 6c 61 74 | 65 20 3c 63 6c 61 73 73 |.templat|e <class|
|000006e0| 20 54 3e 0a 69 6e 6c 69 | 6e 65 20 63 6f 6e 73 74 | T>.inli|ne const|
|000006f0| 20 54 26 20 5f 5f 6d 65 | 64 69 61 6e 28 63 6f 6e | T& __me|dian(con|
|00000700| 73 74 20 54 26 20 61 2c | 20 63 6f 6e 73 74 20 54 |st T& a,| const T|
|00000710| 26 20 62 2c 20 63 6f 6e | 73 74 20 54 26 20 63 29 |& b, con|st T& c)|
|00000720| 20 7b 0a 20 20 20 20 69 | 66 20 28 61 20 3c 20 62 | {. i|f (a < b|
|00000730| 29 0a 09 69 66 20 28 62 | 20 3c 20 63 29 0a 09 20 |)..if (b| < c).. |
|00000740| 20 20 20 72 65 74 75 72 | 6e 20 62 3b 0a 09 65 6c | retur|n b;..el|
|00000750| 73 65 20 69 66 20 28 61 | 20 3c 20 63 29 0a 09 20 |se if (a| < c).. |
|00000760| 20 20 20 72 65 74 75 72 | 6e 20 63 3b 0a 09 65 6c | retur|n c;..el|
|00000770| 73 65 0a 09 20 20 20 20 | 72 65 74 75 72 6e 20 61 |se.. |return a|
|00000780| 3b 0a 20 20 20 20 65 6c | 73 65 20 69 66 20 28 61 |;. el|se if (a|
|00000790| 20 3c 20 63 29 0a 09 72 | 65 74 75 72 6e 20 61 3b | < c)..r|eturn a;|
|000007a0| 0a 20 20 20 20 65 6c 73 | 65 20 69 66 20 28 62 20 |. els|e if (b |
|000007b0| 3c 20 63 29 0a 09 72 65 | 74 75 72 6e 20 63 3b 0a |< c)..re|turn c;.|
|000007c0| 20 20 20 20 65 6c 73 65 | 0a 09 72 65 74 75 72 6e | else|..return|
|000007d0| 20 62 3b 0a 7d 0a 0a 74 | 65 6d 70 6c 61 74 65 20 | b;.}..t|emplate |
|000007e0| 3c 63 6c 61 73 73 20 54 | 2c 20 63 6c 61 73 73 20 |<class T|, class |
|000007f0| 43 6f 6d 70 61 72 65 3e | 0a 69 6e 6c 69 6e 65 20 |Compare>|.inline |
|00000800| 63 6f 6e 73 74 20 54 26 | 20 5f 5f 6d 65 64 69 61 |const T&| __media|
|00000810| 6e 28 63 6f 6e 73 74 20 | 54 26 20 61 2c 20 63 6f |n(const |T& a, co|
|00000820| 6e 73 74 20 54 26 20 62 | 2c 20 63 6f 6e 73 74 20 |nst T& b|, const |
|00000830| 54 26 20 63 2c 20 43 6f | 6d 70 61 72 65 20 63 6f |T& c, Co|mpare co|
|00000840| 6d 70 29 20 7b 0a 20 20 | 20 20 69 66 20 28 63 6f |mp) {. | if (co|
|00000850| 6d 70 28 61 2c 20 62 29 | 29 0a 09 69 66 20 28 63 |mp(a, b)|)..if (c|
|00000860| 6f 6d 70 28 62 2c 20 63 | 29 29 0a 09 20 20 20 20 |omp(b, c|)).. |
|00000870| 72 65 74 75 72 6e 20 62 | 3b 0a 09 65 6c 73 65 20 |return b|;..else |
|00000880| 69 66 20 28 63 6f 6d 70 | 28 61 2c 20 63 29 29 0a |if (comp|(a, c)).|
|00000890| 09 20 20 20 20 72 65 74 | 75 72 6e 20 63 3b 0a 09 |. ret|urn c;..|
|000008a0| 65 6c 73 65 0a 09 20 20 | 20 20 72 65 74 75 72 6e |else.. | return|
|000008b0| 20 61 3b 0a 20 20 20 20 | 65 6c 73 65 20 69 66 20 | a;. |else if |
|000008c0| 28 63 6f 6d 70 28 61 2c | 20 63 29 29 0a 09 72 65 |(comp(a,| c))..re|
|000008d0| 74 75 72 6e 20 61 3b 0a | 20 20 20 20 65 6c 73 65 |turn a;.| else|
|000008e0| 20 69 66 20 28 63 6f 6d | 70 28 62 2c 20 63 29 29 | if (com|p(b, c))|
|000008f0| 0a 09 72 65 74 75 72 6e | 20 63 3b 0a 20 20 20 20 |..return| c;. |
|00000900| 65 6c 73 65 0a 09 72 65 | 74 75 72 6e 20 62 3b 0a |else..re|turn b;.|
|00000910| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00000920| 73 73 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |ss Input|Iterator|
|00000930| 2c 20 63 6c 61 73 73 20 | 46 75 6e 63 74 69 6f 6e |, class |Function|
|00000940| 3e 0a 46 75 6e 63 74 69 | 6f 6e 20 66 6f 72 5f 65 |>.Functi|on for_e|
|00000950| 61 63 68 28 49 6e 70 75 | 74 49 74 65 72 61 74 6f |ach(Inpu|tIterato|
|00000960| 72 20 66 69 72 73 74 2c | 20 49 6e 70 75 74 49 74 |r first,| InputIt|
|00000970| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 20 46 75 6e |erator l|ast, Fun|
|00000980| 63 74 69 6f 6e 20 66 29 | 20 7b 0a 20 20 20 20 77 |ction f)| {. w|
|00000990| 68 69 6c 65 20 28 66 69 | 72 73 74 20 21 3d 20 6c |hile (fi|rst != l|
|000009a0| 61 73 74 29 20 66 28 2a | 66 69 72 73 74 2b 2b 29 |ast) f(*|first++)|
|000009b0| 3b 0a 20 20 20 20 72 65 | 74 75 72 6e 20 66 3b 0a |;. re|turn f;.|
|000009c0| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|000009d0| 73 73 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |ss Input|Iterator|
|000009e0| 2c 20 63 6c 61 73 73 20 | 54 3e 0a 49 6e 70 75 74 |, class |T>.Input|
|000009f0| 49 74 65 72 61 74 6f 72 | 20 66 69 6e 64 28 49 6e |Iterator| find(In|
|00000a00| 70 75 74 49 74 65 72 61 | 74 6f 72 20 66 69 72 73 |putItera|tor firs|
|00000a10| 74 2c 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |t, Input|Iterator|
|00000a20| 20 6c 61 73 74 2c 20 63 | 6f 6e 73 74 20 54 26 20 | last, c|onst T& |
|00000a30| 76 61 6c 75 65 29 20 7b | 0a 20 20 20 20 77 68 69 |value) {|. whi|
|00000a40| 6c 65 20 28 66 69 72 73 | 74 20 21 3d 20 6c 61 73 |le (firs|t != las|
|00000a50| 74 20 26 26 20 2a 66 69 | 72 73 74 20 21 3d 20 76 |t && *fi|rst != v|
|00000a60| 61 6c 75 65 29 20 2b 2b | 66 69 72 73 74 3b 0a 20 |alue) ++|first;. |
|00000a70| 20 20 20 72 65 74 75 72 | 6e 20 66 69 72 73 74 3b | retur|n first;|
|00000a80| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00000a90| 61 73 73 20 49 6e 70 75 | 74 49 74 65 72 61 74 6f |ass Inpu|tIterato|
|00000aa0| 72 2c 20 63 6c 61 73 73 | 20 50 72 65 64 69 63 61 |r, class| Predica|
|00000ab0| 74 65 3e 0a 49 6e 70 75 | 74 49 74 65 72 61 74 6f |te>.Inpu|tIterato|
|00000ac0| 72 20 66 69 6e 64 5f 69 | 66 28 49 6e 70 75 74 49 |r find_i|f(InputI|
|00000ad0| 74 65 72 61 74 6f 72 20 | 66 69 72 73 74 2c 20 49 |terator |first, I|
|00000ae0| 6e 70 75 74 49 74 65 72 | 61 74 6f 72 20 6c 61 73 |nputIter|ator las|
|00000af0| 74 2c 0a 09 09 20 20 20 | 20 20 20 50 72 65 64 69 |t,... | Predi|
|00000b00| 63 61 74 65 20 70 72 65 | 64 29 20 7b 0a 20 20 20 |cate pre|d) {. |
|00000b10| 20 77 68 69 6c 65 20 28 | 66 69 72 73 74 20 21 3d | while (|first !=|
|00000b20| 20 6c 61 73 74 20 26 26 | 20 21 70 72 65 64 28 2a | last &&| !pred(*|
|00000b30| 66 69 72 73 74 29 29 20 | 2b 2b 66 69 72 73 74 3b |first)) |++first;|
|00000b40| 0a 20 20 20 20 72 65 74 | 75 72 6e 20 66 69 72 73 |. ret|urn firs|
|00000b50| 74 3b 0a 7d 0a 0a 74 65 | 6d 70 6c 61 74 65 20 3c |t;.}..te|mplate <|
|00000b60| 63 6c 61 73 73 20 46 6f | 72 77 61 72 64 49 74 65 |class Fo|rwardIte|
|00000b70| 72 61 74 6f 72 3e 0a 46 | 6f 72 77 61 72 64 49 74 |rator>.F|orwardIt|
|00000b80| 65 72 61 74 6f 72 20 61 | 64 6a 61 63 65 6e 74 5f |erator a|djacent_|
|00000b90| 66 69 6e 64 28 46 6f 72 | 77 61 72 64 49 74 65 72 |find(For|wardIter|
|00000ba0| 61 74 6f 72 20 66 69 72 | 73 74 2c 20 46 6f 72 77 |ator fir|st, Forw|
|00000bb0| 61 72 64 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |ardItera|tor last|
|00000bc0| 29 20 7b 0a 20 20 20 20 | 69 66 20 28 66 69 72 73 |) {. |if (firs|
|00000bd0| 74 20 3d 3d 20 6c 61 73 | 74 29 20 72 65 74 75 72 |t == las|t) retur|
|00000be0| 6e 20 6c 61 73 74 3b 0a | 20 20 20 20 46 6f 72 77 |n last;.| Forw|
|00000bf0| 61 72 64 49 74 65 72 61 | 74 6f 72 20 6e 65 78 74 |ardItera|tor next|
|00000c00| 20 3d 20 66 69 72 73 74 | 3b 0a 20 20 20 20 77 68 | = first|;. wh|
|00000c10| 69 6c 65 28 2b 2b 6e 65 | 78 74 20 21 3d 20 6c 61 |ile(++ne|xt != la|
|00000c20| 73 74 29 20 7b 0a 09 69 | 66 20 28 2a 66 69 72 73 |st) {..i|f (*firs|
|00000c30| 74 20 3d 3d 20 2a 6e 65 | 78 74 29 20 72 65 74 75 |t == *ne|xt) retu|
|00000c40| 72 6e 20 66 69 72 73 74 | 3b 0a 09 66 69 72 73 74 |rn first|;..first|
|00000c50| 20 3d 20 6e 65 78 74 3b | 0a 20 20 20 20 7d 0a 20 | = next;|. }. |
|00000c60| 20 20 20 72 65 74 75 72 | 6e 20 6c 61 73 74 3b 0a | retur|n last;.|
|00000c70| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00000c80| 73 73 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |ss Forwa|rdIterat|
|00000c90| 6f 72 2c 20 63 6c 61 73 | 73 20 42 69 6e 61 72 79 |or, clas|s Binary|
|00000ca0| 50 72 65 64 69 63 61 74 | 65 3e 0a 46 6f 72 77 61 |Predicat|e>.Forwa|
|00000cb0| 72 64 49 74 65 72 61 74 | 6f 72 20 61 64 6a 61 63 |rdIterat|or adjac|
|00000cc0| 65 6e 74 5f 66 69 6e 64 | 28 46 6f 72 77 61 72 64 |ent_find|(Forward|
|00000cd0| 49 74 65 72 61 74 6f 72 | 20 66 69 72 73 74 2c 20 |Iterator| first, |
|00000ce0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 20 |ForwardI|terator |
|00000cf0| 6c 61 73 74 2c 0a 09 09 | 09 20 20 20 20 20 20 42 |last,...|. B|
|00000d00| 69 6e 61 72 79 50 72 65 | 64 69 63 61 74 65 20 62 |inaryPre|dicate b|
|00000d10| 69 6e 61 72 79 5f 70 72 | 65 64 29 20 7b 0a 20 20 |inary_pr|ed) {. |
|00000d20| 20 20 69 66 20 28 66 69 | 72 73 74 20 3d 3d 20 6c | if (fi|rst == l|
|00000d30| 61 73 74 29 20 72 65 74 | 75 72 6e 20 6c 61 73 74 |ast) ret|urn last|
|00000d40| 3b 0a 20 20 20 20 46 6f | 72 77 61 72 64 49 74 65 |;. Fo|rwardIte|
|00000d50| 72 61 74 6f 72 20 6e 65 | 78 74 20 3d 20 66 69 72 |rator ne|xt = fir|
|00000d60| 73 74 3b 0a 20 20 20 20 | 77 68 69 6c 65 28 2b 2b |st;. |while(++|
|00000d70| 6e 65 78 74 20 21 3d 20 | 6c 61 73 74 29 20 7b 0a |next != |last) {.|
|00000d80| 09 69 66 20 28 62 69 6e | 61 72 79 5f 70 72 65 64 |.if (bin|ary_pred|
|00000d90| 28 2a 66 69 72 73 74 2c | 20 2a 6e 65 78 74 29 29 |(*first,| *next))|
|00000da0| 20 72 65 74 75 72 6e 20 | 66 69 72 73 74 3b 0a 09 | return |first;..|
|00000db0| 66 69 72 73 74 20 3d 20 | 6e 65 78 74 3b 0a 20 20 |first = |next;. |
|00000dc0| 20 20 7d 0a 20 20 20 20 | 72 65 74 75 72 6e 20 6c | }. |return l|
|00000dd0| 61 73 74 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |ast;.}..|template|
|00000de0| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00000df0| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 54 2c 20 |rator, c|lass T, |
|00000e00| 63 6c 61 73 73 20 53 69 | 7a 65 3e 0a 76 6f 69 64 |class Si|ze>.void|
|00000e10| 20 63 6f 75 6e 74 28 49 | 6e 70 75 74 49 74 65 72 | count(I|nputIter|
|00000e20| 61 74 6f 72 20 66 69 72 | 73 74 2c 20 49 6e 70 75 |ator fir|st, Inpu|
|00000e30| 74 49 74 65 72 61 74 6f | 72 20 6c 61 73 74 2c 20 |tIterato|r last, |
|00000e40| 63 6f 6e 73 74 20 54 26 | 20 76 61 6c 75 65 2c 0a |const T&| value,.|
|00000e50| 09 20 20 20 53 69 7a 65 | 26 20 6e 29 20 7b 0a 20 |. Size|& n) {. |
|00000e60| 20 20 20 77 68 69 6c 65 | 20 28 66 69 72 73 74 20 | while| (first |
|00000e70| 21 3d 20 6c 61 73 74 29 | 20 0a 09 69 66 20 28 2a |!= last)| ..if (*|
|00000e80| 66 69 72 73 74 2b 2b 20 | 3d 3d 20 76 61 6c 75 65 |first++ |== value|
|00000e90| 29 20 2b 2b 6e 3b 0a 7d | 0a 0a 74 65 6d 70 6c 61 |) ++n;.}|..templa|
|00000ea0| 74 65 20 3c 63 6c 61 73 | 73 20 49 6e 70 75 74 49 |te <clas|s InputI|
|00000eb0| 74 65 72 61 74 6f 72 2c | 20 63 6c 61 73 73 20 50 |terator,| class P|
|00000ec0| 72 65 64 69 63 61 74 65 | 2c 20 63 6c 61 73 73 20 |redicate|, class |
|00000ed0| 53 69 7a 65 3e 0a 76 6f | 69 64 20 63 6f 75 6e 74 |Size>.vo|id count|
|00000ee0| 5f 69 66 28 49 6e 70 75 | 74 49 74 65 72 61 74 6f |_if(Inpu|tIterato|
|00000ef0| 72 20 66 69 72 73 74 2c | 20 49 6e 70 75 74 49 74 |r first,| InputIt|
|00000f00| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 20 50 72 65 |erator l|ast, Pre|
|00000f10| 64 69 63 61 74 65 20 70 | 72 65 64 2c 0a 09 20 20 |dicate p|red,.. |
|00000f20| 20 20 20 20 53 69 7a 65 | 26 20 6e 29 20 7b 0a 20 | Size|& n) {. |
|00000f30| 20 20 20 77 68 69 6c 65 | 20 28 66 69 72 73 74 20 | while| (first |
|00000f40| 21 3d 20 6c 61 73 74 29 | 0a 09 69 66 20 28 70 72 |!= last)|..if (pr|
|00000f50| 65 64 28 2a 66 69 72 73 | 74 2b 2b 29 29 20 2b 2b |ed(*firs|t++)) ++|
|00000f60| 6e 3b 0a 7d 0a 0a 74 65 | 6d 70 6c 61 74 65 20 3c |n;.}..te|mplate <|
|00000f70| 63 6c 61 73 73 20 46 6f | 72 77 61 72 64 49 74 65 |class Fo|rwardIte|
|00000f80| 72 61 74 6f 72 31 2c 20 | 63 6c 61 73 73 20 46 6f |rator1, |class Fo|
|00000f90| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 32 2c 20 |rwardIte|rator2, |
|00000fa0| 63 6c 61 73 73 20 44 69 | 73 74 61 6e 63 65 31 2c |class Di|stance1,|
|00000fb0| 0a 09 20 20 63 6c 61 73 | 73 20 44 69 73 74 61 6e |.. clas|s Distan|
|00000fc0| 63 65 32 3e 0a 46 6f 72 | 77 61 72 64 49 74 65 72 |ce2>.For|wardIter|
|00000fd0| 61 74 6f 72 31 20 5f 5f | 73 65 61 72 63 68 28 46 |ator1 __|search(F|
|00000fe0| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 31 20 |orwardIt|erator1 |
|00000ff0| 66 69 72 73 74 31 2c 20 | 46 6f 72 77 61 72 64 49 |first1, |ForwardI|
|00001000| 74 65 72 61 74 6f 72 31 | 20 6c 61 73 74 31 2c 0a |terator1| last1,.|
|00001010| 09 09 09 20 20 46 6f 72 | 77 61 72 64 49 74 65 72 |... For|wardIter|
|00001020| 61 74 6f 72 32 20 66 69 | 72 73 74 32 2c 20 46 6f |ator2 fi|rst2, Fo|
|00001030| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 32 20 6c |rwardIte|rator2 l|
|00001040| 61 73 74 32 2c 0a 09 09 | 09 20 20 44 69 73 74 61 |ast2,...|. Dista|
|00001050| 6e 63 65 31 2a 2c 20 44 | 69 73 74 61 6e 63 65 32 |nce1*, D|istance2|
|00001060| 2a 29 20 7b 0a 20 20 20 | 20 44 69 73 74 61 6e 63 |*) {. | Distanc|
|00001070| 65 31 20 64 31 20 3d 20 | 30 3b 0a 20 20 20 20 64 |e1 d1 = |0;. d|
|00001080| 69 73 74 61 6e 63 65 28 | 66 69 72 73 74 31 2c 20 |istance(|first1, |
|00001090| 6c 61 73 74 31 2c 20 64 | 31 29 3b 0a 20 20 20 20 |last1, d|1);. |
|000010a0| 44 69 73 74 61 6e 63 65 | 32 20 64 32 20 3d 20 30 |Distance|2 d2 = 0|
|000010b0| 3b 0a 20 20 20 20 64 69 | 73 74 61 6e 63 65 28 66 |;. di|stance(f|
|000010c0| 69 72 73 74 32 2c 20 6c | 61 73 74 32 2c 20 64 32 |irst2, l|ast2, d2|
|000010d0| 29 3b 0a 0a 20 20 20 20 | 69 66 20 28 64 31 20 3c |);.. |if (d1 <|
|000010e0| 20 64 32 29 20 72 65 74 | 75 72 6e 20 6c 61 73 74 | d2) ret|urn last|
|000010f0| 31 3b 0a 0a 20 20 20 20 | 46 6f 72 77 61 72 64 49 |1;.. |ForwardI|
|00001100| 74 65 72 61 74 6f 72 31 | 20 63 75 72 72 65 6e 74 |terator1| current|
|00001110| 31 20 3d 20 66 69 72 73 | 74 31 3b 0a 20 20 20 20 |1 = firs|t1;. |
|00001120| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 32 |ForwardI|terator2|
|00001130| 20 63 75 72 72 65 6e 74 | 32 20 3d 20 66 69 72 73 | current|2 = firs|
|00001140| 74 32 3b 0a 0a 20 20 20 | 20 77 68 69 6c 65 20 28 |t2;.. | while (|
|00001150| 63 75 72 72 65 6e 74 32 | 20 21 3d 20 6c 61 73 74 |current2| != last|
|00001160| 32 29 0a 09 69 66 20 28 | 2a 63 75 72 72 65 6e 74 |2)..if (|*current|
|00001170| 31 2b 2b 20 21 3d 20 2a | 63 75 72 72 65 6e 74 32 |1++ != *|current2|
|00001180| 2b 2b 29 0a 09 20 20 20 | 20 69 66 20 28 64 31 2d |++).. | if (d1-|
|00001190| 2d 20 3d 3d 20 64 32 29 | 0a 09 09 72 65 74 75 72 |- == d2)|...retur|
|000011a0| 6e 20 6c 61 73 74 31 3b | 0a 09 20 20 20 20 65 6c |n last1;|.. el|
|000011b0| 73 65 20 7b 0a 09 09 63 | 75 72 72 65 6e 74 31 20 |se {...c|urrent1 |
|000011c0| 3d 20 2b 2b 66 69 72 73 | 74 31 3b 0a 09 09 63 75 |= ++firs|t1;...cu|
|000011d0| 72 72 65 6e 74 32 20 3d | 20 66 69 72 73 74 32 3b |rrent2 =| first2;|
|000011e0| 0a 09 20 20 20 20 7d 0a | 20 20 20 20 72 65 74 75 |.. }.| retu|
|000011f0| 72 6e 20 28 63 75 72 72 | 65 6e 74 32 20 3d 3d 20 |rn (curr|ent2 == |
|00001200| 6c 61 73 74 32 29 20 3f | 20 66 69 72 73 74 31 20 |last2) ?| first1 |
|00001210| 3a 20 6c 61 73 74 31 3b | 0a 7d 0a 0a 74 65 6d 70 |: last1;|.}..temp|
|00001220| 6c 61 74 65 20 3c 63 6c | 61 73 73 20 46 6f 72 77 |late <cl|ass Forw|
|00001230| 61 72 64 49 74 65 72 61 | 74 6f 72 31 2c 20 63 6c |ardItera|tor1, cl|
|00001240| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|00001250| 74 6f 72 32 3e 0a 69 6e | 6c 69 6e 65 20 46 6f 72 |tor2>.in|line For|
|00001260| 77 61 72 64 49 74 65 72 | 61 74 6f 72 31 20 73 65 |wardIter|ator1 se|
|00001270| 61 72 63 68 28 46 6f 72 | 77 61 72 64 49 74 65 72 |arch(For|wardIter|
|00001280| 61 74 6f 72 31 20 66 69 | 72 73 74 31 2c 20 46 6f |ator1 fi|rst1, Fo|
|00001290| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 31 20 6c |rwardIte|rator1 l|
|000012a0| 61 73 74 31 2c 0a 09 09 | 09 20 20 20 20 20 20 20 |ast1,...|. |
|000012b0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 32 |ForwardI|terator2|
|000012c0| 20 66 69 72 73 74 32 2c | 20 46 6f 72 77 61 72 64 | first2,| Forward|
|000012d0| 49 74 65 72 61 74 6f 72 | 32 20 6c 61 73 74 32 29 |Iterator|2 last2)|
|000012e0| 0a 7b 0a 20 20 20 20 72 | 65 74 75 72 6e 20 5f 5f |.{. r|eturn __|
|000012f0| 73 65 61 72 63 68 28 66 | 69 72 73 74 31 2c 20 6c |search(f|irst1, l|
|00001300| 61 73 74 31 2c 20 66 69 | 72 73 74 32 2c 20 6c 61 |ast1, fi|rst2, la|
|00001310| 73 74 32 2c 20 64 69 73 | 74 61 6e 63 65 5f 74 79 |st2, dis|tance_ty|
|00001320| 70 65 28 66 69 72 73 74 | 31 29 2c 0a 09 09 20 20 |pe(first|1),... |
|00001330| 20 20 64 69 73 74 61 6e | 63 65 5f 74 79 70 65 28 | distan|ce_type(|
|00001340| 66 69 72 73 74 32 29 29 | 3b 0a 7d 0a 0a 74 65 6d |first2))|;.}..tem|
|00001350| 70 6c 61 74 65 20 3c 63 | 6c 61 73 73 20 46 6f 72 |plate <c|lass For|
|00001360| 77 61 72 64 49 74 65 72 | 61 74 6f 72 31 2c 20 63 |wardIter|ator1, c|
|00001370| 6c 61 73 73 20 46 6f 72 | 77 61 72 64 49 74 65 72 |lass For|wardIter|
|00001380| 61 74 6f 72 32 2c 0a 09 | 20 20 63 6c 61 73 73 20 |ator2,..| class |
|00001390| 42 69 6e 61 72 79 50 72 | 65 64 69 63 61 74 65 2c |BinaryPr|edicate,|
|000013a0| 20 63 6c 61 73 73 20 44 | 69 73 74 61 6e 63 65 31 | class D|istance1|
|000013b0| 2c 20 63 6c 61 73 73 20 | 44 69 73 74 61 6e 63 65 |, class |Distance|
|000013c0| 32 3e 0a 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |2>.Forwa|rdIterat|
|000013d0| 6f 72 31 20 5f 5f 73 65 | 61 72 63 68 28 46 6f 72 |or1 __se|arch(For|
|000013e0| 77 61 72 64 49 74 65 72 | 61 74 6f 72 31 20 66 69 |wardIter|ator1 fi|
|000013f0| 72 73 74 31 2c 20 46 6f | 72 77 61 72 64 49 74 65 |rst1, Fo|rwardIte|
|00001400| 72 61 74 6f 72 31 20 6c | 61 73 74 31 2c 0a 09 09 |rator1 l|ast1,...|
|00001410| 09 20 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |. Forwa|rdIterat|
|00001420| 6f 72 32 20 66 69 72 73 | 74 32 2c 20 46 6f 72 77 |or2 firs|t2, Forw|
|00001430| 61 72 64 49 74 65 72 61 | 74 6f 72 32 20 6c 61 73 |ardItera|tor2 las|
|00001440| 74 32 2c 0a 09 09 09 20 | 20 42 69 6e 61 72 79 50 |t2,.... | BinaryP|
|00001450| 72 65 64 69 63 61 74 65 | 20 62 69 6e 61 72 79 5f |redicate| binary_|
|00001460| 70 72 65 64 2c 20 44 69 | 73 74 61 6e 63 65 31 2a |pred, Di|stance1*|
|00001470| 2c 20 44 69 73 74 61 6e | 63 65 32 2a 29 20 7b 0a |, Distan|ce2*) {.|
|00001480| 20 20 20 20 44 69 73 74 | 61 6e 63 65 31 20 64 31 | Dist|ance1 d1|
|00001490| 20 3d 20 30 3b 0a 20 20 | 20 20 64 69 73 74 61 6e | = 0;. | distan|
|000014a0| 63 65 28 66 69 72 73 74 | 31 2c 20 6c 61 73 74 31 |ce(first|1, last1|
|000014b0| 2c 20 64 31 29 3b 0a 20 | 20 20 20 44 69 73 74 61 |, d1);. | Dista|
|000014c0| 6e 63 65 32 20 64 32 20 | 3d 20 30 3b 0a 20 20 20 |nce2 d2 |= 0;. |
|000014d0| 20 64 69 73 74 61 6e 63 | 65 28 66 69 72 73 74 32 | distanc|e(first2|
|000014e0| 2c 20 6c 61 73 74 32 2c | 20 64 32 29 3b 0a 0a 20 |, last2,| d2);.. |
|000014f0| 20 20 20 69 66 20 28 64 | 31 20 3c 20 64 32 29 20 | if (d|1 < d2) |
|00001500| 72 65 74 75 72 6e 20 6c | 61 73 74 31 3b 0a 0a 20 |return l|ast1;.. |
|00001510| 20 20 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 | Forwa|rdIterat|
|00001520| 6f 72 31 20 63 75 72 72 | 65 6e 74 31 20 3d 20 66 |or1 curr|ent1 = f|
|00001530| 69 72 73 74 31 3b 0a 20 | 20 20 20 46 6f 72 77 61 |irst1;. | Forwa|
|00001540| 72 64 49 74 65 72 61 74 | 6f 72 32 20 63 75 72 72 |rdIterat|or2 curr|
|00001550| 65 6e 74 32 20 3d 20 66 | 69 72 73 74 32 3b 0a 0a |ent2 = f|irst2;..|
|00001560| 20 20 20 20 77 68 69 6c | 65 20 28 63 75 72 72 65 | whil|e (curre|
|00001570| 6e 74 32 20 21 3d 20 6c | 61 73 74 32 29 0a 09 69 |nt2 != l|ast2)..i|
|00001580| 66 20 28 21 62 69 6e 61 | 72 79 5f 70 72 65 64 28 |f (!bina|ry_pred(|
|00001590| 2a 63 75 72 72 65 6e 74 | 31 2b 2b 2c 20 2a 63 75 |*current|1++, *cu|
|000015a0| 72 72 65 6e 74 32 2b 2b | 29 29 0a 09 20 20 20 20 |rrent2++|)).. |
|000015b0| 69 66 20 28 64 31 2d 2d | 20 3d 3d 20 64 32 29 0a |if (d1--| == d2).|
|000015c0| 09 09 72 65 74 75 72 6e | 20 6c 61 73 74 31 3b 0a |..return| last1;.|
|000015d0| 09 20 20 20 20 65 6c 73 | 65 20 7b 0a 09 09 63 75 |. els|e {...cu|
|000015e0| 72 72 65 6e 74 31 20 3d | 20 2b 2b 66 69 72 73 74 |rrent1 =| ++first|
|000015f0| 31 3b 0a 09 09 63 75 72 | 72 65 6e 74 32 20 3d 20 |1;...cur|rent2 = |
|00001600| 66 69 72 73 74 32 3b 0a | 09 20 20 20 20 7d 0a 20 |first2;.|. }. |
|00001610| 20 20 20 72 65 74 75 72 | 6e 20 28 63 75 72 72 65 | retur|n (curre|
|00001620| 6e 74 32 20 3d 3d 20 6c | 61 73 74 32 29 20 3f 20 |nt2 == l|ast2) ? |
|00001630| 66 69 72 73 74 31 20 3a | 20 6c 61 73 74 31 3b 0a |first1 :| last1;.|
|00001640| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00001650| 73 73 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |ss Forwa|rdIterat|
|00001660| 6f 72 31 2c 20 63 6c 61 | 73 73 20 46 6f 72 77 61 |or1, cla|ss Forwa|
|00001670| 72 64 49 74 65 72 61 74 | 6f 72 32 2c 0a 09 20 20 |rdIterat|or2,.. |
|00001680| 63 6c 61 73 73 20 42 69 | 6e 61 72 79 50 72 65 64 |class Bi|naryPred|
|00001690| 69 63 61 74 65 3e 0a 69 | 6e 6c 69 6e 65 20 46 6f |icate>.i|nline Fo|
|000016a0| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 31 20 73 |rwardIte|rator1 s|
|000016b0| 65 61 72 63 68 28 46 6f | 72 77 61 72 64 49 74 65 |earch(Fo|rwardIte|
|000016c0| 72 61 74 6f 72 31 20 66 | 69 72 73 74 31 2c 20 46 |rator1 f|irst1, F|
|000016d0| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 31 20 |orwardIt|erator1 |
|000016e0| 6c 61 73 74 31 2c 0a 09 | 09 09 20 20 20 20 20 20 |last1,..|.. |
|000016f0| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|00001700| 32 20 66 69 72 73 74 32 | 2c 20 46 6f 72 77 61 72 |2 first2|, Forwar|
|00001710| 64 49 74 65 72 61 74 6f | 72 32 20 6c 61 73 74 32 |dIterato|r2 last2|
|00001720| 2c 0a 09 09 09 20 20 20 | 20 20 20 20 42 69 6e 61 |,.... | Bina|
|00001730| 72 79 50 72 65 64 69 63 | 61 74 65 20 62 69 6e 61 |ryPredic|ate bina|
|00001740| 72 79 5f 70 72 65 64 29 | 20 7b 0a 20 20 20 20 72 |ry_pred)| {. r|
|00001750| 65 74 75 72 6e 20 5f 5f | 73 65 61 72 63 68 28 66 |eturn __|search(f|
|00001760| 69 72 73 74 31 2c 20 6c | 61 73 74 31 2c 20 66 69 |irst1, l|ast1, fi|
|00001770| 72 73 74 32 2c 20 6c 61 | 73 74 32 2c 20 62 69 6e |rst2, la|st2, bin|
|00001780| 61 72 79 5f 70 72 65 64 | 2c 0a 09 09 20 20 20 20 |ary_pred|,... |
|00001790| 64 69 73 74 61 6e 63 65 | 5f 74 79 70 65 28 66 69 |distance|_type(fi|
|000017a0| 72 73 74 31 29 2c 20 64 | 69 73 74 61 6e 63 65 5f |rst1), d|istance_|
|000017b0| 74 79 70 65 28 66 69 72 | 73 74 32 29 29 3b 0a 7d |type(fir|st2));.}|
|000017c0| 0a 0a 74 65 6d 70 6c 61 | 74 65 20 3c 63 6c 61 73 |..templa|te <clas|
|000017d0| 73 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f |s Forwar|dIterato|
|000017e0| 72 31 2c 20 63 6c 61 73 | 73 20 46 6f 72 77 61 72 |r1, clas|s Forwar|
|000017f0| 64 49 74 65 72 61 74 6f | 72 32 3e 0a 46 6f 72 77 |dIterato|r2>.Forw|
|00001800| 61 72 64 49 74 65 72 61 | 74 6f 72 32 20 73 77 61 |ardItera|tor2 swa|
|00001810| 70 5f 72 61 6e 67 65 73 | 28 46 6f 72 77 61 72 64 |p_ranges|(Forward|
|00001820| 49 74 65 72 61 74 6f 72 | 31 20 66 69 72 73 74 31 |Iterator|1 first1|
|00001830| 2c 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f |, Forwar|dIterato|
|00001840| 72 31 20 6c 61 73 74 31 | 2c 0a 09 09 09 20 20 20 |r1 last1|,.... |
|00001850| 20 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f | Forwar|dIterato|
|00001860| 72 32 20 66 69 72 73 74 | 32 29 20 7b 0a 20 20 20 |r2 first|2) {. |
|00001870| 20 77 68 69 6c 65 20 28 | 66 69 72 73 74 31 20 21 | while (|first1 !|
|00001880| 3d 20 6c 61 73 74 31 29 | 20 69 74 65 72 5f 73 77 |= last1)| iter_sw|
|00001890| 61 70 28 66 69 72 73 74 | 31 2b 2b 2c 20 66 69 72 |ap(first|1++, fir|
|000018a0| 73 74 32 2b 2b 29 3b 0a | 20 20 20 20 72 65 74 75 |st2++);.| retu|
|000018b0| 72 6e 20 66 69 72 73 74 | 32 3b 0a 7d 0a 0a 74 65 |rn first|2;.}..te|
|000018c0| 6d 70 6c 61 74 65 20 3c | 63 6c 61 73 73 20 49 6e |mplate <|class In|
|000018d0| 70 75 74 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |putItera|tor, cla|
|000018e0| 73 73 20 4f 75 74 70 75 | 74 49 74 65 72 61 74 6f |ss Outpu|tIterato|
|000018f0| 72 2c 20 63 6c 61 73 73 | 20 55 6e 61 72 79 4f 70 |r, class| UnaryOp|
|00001900| 65 72 61 74 69 6f 6e 3e | 0a 4f 75 74 70 75 74 49 |eration>|.OutputI|
|00001910| 74 65 72 61 74 6f 72 20 | 74 72 61 6e 73 66 6f 72 |terator |transfor|
|00001920| 6d 28 49 6e 70 75 74 49 | 74 65 72 61 74 6f 72 20 |m(InputI|terator |
|00001930| 66 69 72 73 74 2c 20 49 | 6e 70 75 74 49 74 65 72 |first, I|nputIter|
|00001940| 61 74 6f 72 20 6c 61 73 | 74 2c 0a 09 09 09 20 4f |ator las|t,.... O|
|00001950| 75 74 70 75 74 49 74 65 | 72 61 74 6f 72 20 72 65 |utputIte|rator re|
|00001960| 73 75 6c 74 2c 20 55 6e | 61 72 79 4f 70 65 72 61 |sult, Un|aryOpera|
|00001970| 74 69 6f 6e 20 6f 70 29 | 20 7b 0a 20 20 20 20 77 |tion op)| {. w|
|00001980| 68 69 6c 65 20 28 66 69 | 72 73 74 20 21 3d 20 6c |hile (fi|rst != l|
|00001990| 61 73 74 29 20 2a 72 65 | 73 75 6c 74 2b 2b 20 3d |ast) *re|sult++ =|
|000019a0| 20 6f 70 28 2a 66 69 72 | 73 74 2b 2b 29 3b 0a 20 | op(*fir|st++);. |
|000019b0| 20 20 20 72 65 74 75 72 | 6e 20 72 65 73 75 6c 74 | retur|n result|
|000019c0| 3b 0a 7d 0a 0a 74 65 6d | 70 6c 61 74 65 20 3c 63 |;.}..tem|plate <c|
|000019d0| 6c 61 73 73 20 49 6e 70 | 75 74 49 74 65 72 61 74 |lass Inp|utIterat|
|000019e0| 6f 72 31 2c 20 63 6c 61 | 73 73 20 49 6e 70 75 74 |or1, cla|ss Input|
|000019f0| 49 74 65 72 61 74 6f 72 | 32 2c 20 63 6c 61 73 73 |Iterator|2, class|
|00001a00| 20 4f 75 74 70 75 74 49 | 74 65 72 61 74 6f 72 2c | OutputI|terator,|
|00001a10| 0a 09 20 20 63 6c 61 73 | 73 20 42 69 6e 61 72 79 |.. clas|s Binary|
|00001a20| 4f 70 65 72 61 74 69 6f | 6e 3e 0a 4f 75 74 70 75 |Operatio|n>.Outpu|
|00001a30| 74 49 74 65 72 61 74 6f | 72 20 74 72 61 6e 73 66 |tIterato|r transf|
|00001a40| 6f 72 6d 28 49 6e 70 75 | 74 49 74 65 72 61 74 6f |orm(Inpu|tIterato|
|00001a50| 72 31 20 66 69 72 73 74 | 31 2c 20 49 6e 70 75 74 |r1 first|1, Input|
|00001a60| 49 74 65 72 61 74 6f 72 | 31 20 6c 61 73 74 31 2c |Iterator|1 last1,|
|00001a70| 0a 09 09 09 20 49 6e 70 | 75 74 49 74 65 72 61 74 |.... Inp|utIterat|
|00001a80| 6f 72 32 20 66 69 72 73 | 74 32 2c 20 4f 75 74 70 |or2 firs|t2, Outp|
|00001a90| 75 74 49 74 65 72 61 74 | 6f 72 20 72 65 73 75 6c |utIterat|or resul|
|00001aa0| 74 2c 0a 09 09 09 20 42 | 69 6e 61 72 79 4f 70 65 |t,.... B|inaryOpe|
|00001ab0| 72 61 74 69 6f 6e 20 62 | 69 6e 61 72 79 5f 6f 70 |ration b|inary_op|
|00001ac0| 29 20 7b 0a 20 20 20 20 | 77 68 69 6c 65 20 28 66 |) {. |while (f|
|00001ad0| 69 72 73 74 31 20 21 3d | 20 6c 61 73 74 31 29 20 |irst1 !=| last1) |
|00001ae0| 2a 72 65 73 75 6c 74 2b | 2b 20 3d 20 62 69 6e 61 |*result+|+ = bina|
|00001af0| 72 79 5f 6f 70 28 2a 66 | 69 72 73 74 31 2b 2b 2c |ry_op(*f|irst1++,|
|00001b00| 20 2a 66 69 72 73 74 32 | 2b 2b 29 3b 0a 20 20 20 | *first2|++);. |
|00001b10| 20 72 65 74 75 72 6e 20 | 72 65 73 75 6c 74 3b 0a | return |result;.|
|00001b20| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00001b30| 73 73 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |ss Forwa|rdIterat|
|00001b40| 6f 72 2c 20 63 6c 61 73 | 73 20 54 3e 0a 76 6f 69 |or, clas|s T>.voi|
|00001b50| 64 20 72 65 70 6c 61 63 | 65 28 46 6f 72 77 61 72 |d replac|e(Forwar|
|00001b60| 64 49 74 65 72 61 74 6f | 72 20 66 69 72 73 74 2c |dIterato|r first,|
|00001b70| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|00001b80| 20 6c 61 73 74 2c 20 63 | 6f 6e 73 74 20 54 26 20 | last, c|onst T& |
|00001b90| 6f 6c 64 5f 76 61 6c 75 | 65 2c 0a 09 20 20 20 20 |old_valu|e,.. |
|00001ba0| 20 63 6f 6e 73 74 20 54 | 26 20 6e 65 77 5f 76 61 | const T|& new_va|
|00001bb0| 6c 75 65 29 20 7b 0a 20 | 20 20 20 77 68 69 6c 65 |lue) {. | while|
|00001bc0| 20 28 66 69 72 73 74 20 | 21 3d 20 6c 61 73 74 29 | (first |!= last)|
|00001bd0| 20 7b 0a 09 69 66 20 28 | 2a 66 69 72 73 74 20 3d | {..if (|*first =|
|00001be0| 3d 20 6f 6c 64 5f 76 61 | 6c 75 65 29 20 2a 66 69 |= old_va|lue) *fi|
|00001bf0| 72 73 74 20 3d 20 6e 65 | 77 5f 76 61 6c 75 65 3b |rst = ne|w_value;|
|00001c00| 0a 09 2b 2b 66 69 72 73 | 74 3b 0a 20 20 20 20 7d |..++firs|t;. }|
|00001c10| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00001c20| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|00001c30| 74 6f 72 2c 20 63 6c 61 | 73 73 20 50 72 65 64 69 |tor, cla|ss Predi|
|00001c40| 63 61 74 65 2c 20 63 6c | 61 73 73 20 54 3e 0a 76 |cate, cl|ass T>.v|
|00001c50| 6f 69 64 20 72 65 70 6c | 61 63 65 5f 69 66 28 46 |oid repl|ace_if(F|
|00001c60| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 20 66 |orwardIt|erator f|
|00001c70| 69 72 73 74 2c 20 46 6f | 72 77 61 72 64 49 74 65 |irst, Fo|rwardIte|
|00001c80| 72 61 74 6f 72 20 6c 61 | 73 74 2c 20 50 72 65 64 |rator la|st, Pred|
|00001c90| 69 63 61 74 65 20 70 72 | 65 64 2c 0a 09 09 63 6f |icate pr|ed,...co|
|00001ca0| 6e 73 74 20 54 26 20 6e | 65 77 5f 76 61 6c 75 65 |nst T& n|ew_value|
|00001cb0| 29 20 7b 0a 20 20 20 20 | 77 68 69 6c 65 20 28 66 |) {. |while (f|
|00001cc0| 69 72 73 74 20 21 3d 20 | 6c 61 73 74 29 20 7b 0a |irst != |last) {.|
|00001cd0| 09 69 66 20 28 70 72 65 | 64 28 2a 66 69 72 73 74 |.if (pre|d(*first|
|00001ce0| 29 29 20 2a 66 69 72 73 | 74 20 3d 20 6e 65 77 5f |)) *firs|t = new_|
|00001cf0| 76 61 6c 75 65 3b 0a 09 | 2b 2b 66 69 72 73 74 3b |value;..|++first;|
|00001d00| 0a 20 20 20 20 7d 0a 7d | 0a 0a 74 65 6d 70 6c 61 |. }.}|..templa|
|00001d10| 74 65 20 3c 63 6c 61 73 | 73 20 49 6e 70 75 74 49 |te <clas|s InputI|
|00001d20| 74 65 72 61 74 6f 72 2c | 20 63 6c 61 73 73 20 4f |terator,| class O|
|00001d30| 75 74 70 75 74 49 74 65 | 72 61 74 6f 72 2c 20 63 |utputIte|rator, c|
|00001d40| 6c 61 73 73 20 54 3e 0a | 4f 75 74 70 75 74 49 74 |lass T>.|OutputIt|
|00001d50| 65 72 61 74 6f 72 20 72 | 65 70 6c 61 63 65 5f 63 |erator r|eplace_c|
|00001d60| 6f 70 79 28 49 6e 70 75 | 74 49 74 65 72 61 74 6f |opy(Inpu|tIterato|
|00001d70| 72 20 66 69 72 73 74 2c | 20 49 6e 70 75 74 49 74 |r first,| InputIt|
|00001d80| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 0a 09 09 09 |erator l|ast,....|
|00001d90| 20 20 20 20 4f 75 74 70 | 75 74 49 74 65 72 61 74 | Outp|utIterat|
|00001da0| 6f 72 20 72 65 73 75 6c | 74 2c 20 63 6f 6e 73 74 |or resul|t, const|
|00001db0| 20 54 26 20 6f 6c 64 5f | 76 61 6c 75 65 2c 0a 09 | T& old_|value,..|
|00001dc0| 09 09 20 20 20 20 63 6f | 6e 73 74 20 54 26 20 6e |.. co|nst T& n|
|00001dd0| 65 77 5f 76 61 6c 75 65 | 29 20 7b 0a 20 20 20 20 |ew_value|) {. |
|00001de0| 77 68 69 6c 65 20 28 66 | 69 72 73 74 20 21 3d 20 |while (f|irst != |
|00001df0| 6c 61 73 74 29 20 7b 0a | 09 2a 72 65 73 75 6c 74 |last) {.|.*result|
|00001e00| 2b 2b 20 3d 20 2a 66 69 | 72 73 74 20 3d 3d 20 6f |++ = *fi|rst == o|
|00001e10| 6c 64 5f 76 61 6c 75 65 | 20 3f 20 6e 65 77 5f 76 |ld_value| ? new_v|
|00001e20| 61 6c 75 65 20 3a 20 2a | 66 69 72 73 74 3b 0a 09 |alue : *|first;..|
|00001e30| 2b 2b 66 69 72 73 74 3b | 0a 20 20 20 20 7d 0a 20 |++first;|. }. |
|00001e40| 20 20 20 72 65 74 75 72 | 6e 20 72 65 73 75 6c 74 | retur|n result|
|00001e50| 3b 0a 7d 0a 0a 74 65 6d | 70 6c 61 74 65 20 3c 63 |;.}..tem|plate <c|
|00001e60| 6c 61 73 73 20 49 74 65 | 72 61 74 6f 72 2c 20 63 |lass Ite|rator, c|
|00001e70| 6c 61 73 73 20 4f 75 74 | 70 75 74 49 74 65 72 61 |lass Out|putItera|
|00001e80| 74 6f 72 2c 20 63 6c 61 | 73 73 20 50 72 65 64 69 |tor, cla|ss Predi|
|00001e90| 63 61 74 65 2c 20 63 6c | 61 73 73 20 54 3e 0a 4f |cate, cl|ass T>.O|
|00001ea0| 75 74 70 75 74 49 74 65 | 72 61 74 6f 72 20 72 65 |utputIte|rator re|
|00001eb0| 70 6c 61 63 65 5f 63 6f | 70 79 5f 69 66 28 49 74 |place_co|py_if(It|
|00001ec0| 65 72 61 74 6f 72 20 66 | 69 72 73 74 2c 20 49 74 |erator f|irst, It|
|00001ed0| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 0a 09 09 09 |erator l|ast,....|
|00001ee0| 20 20 20 20 20 20 20 4f | 75 74 70 75 74 49 74 65 | O|utputIte|
|00001ef0| 72 61 74 6f 72 20 72 65 | 73 75 6c 74 2c 20 50 72 |rator re|sult, Pr|
|00001f00| 65 64 69 63 61 74 65 20 | 70 72 65 64 2c 0a 09 09 |edicate |pred,...|
|00001f10| 09 20 20 20 20 20 20 20 | 63 6f 6e 73 74 20 54 26 |. |const T&|
|00001f20| 20 6e 65 77 5f 76 61 6c | 75 65 29 20 7b 0a 20 20 | new_val|ue) {. |
|00001f30| 20 20 77 68 69 6c 65 20 | 28 66 69 72 73 74 20 21 | while |(first !|
|00001f40| 3d 20 6c 61 73 74 29 20 | 7b 0a 09 2a 72 65 73 75 |= last) |{..*resu|
|00001f50| 6c 74 2b 2b 20 3d 20 70 | 72 65 64 28 2a 66 69 72 |lt++ = p|red(*fir|
|00001f60| 73 74 29 20 3f 20 6e 65 | 77 5f 76 61 6c 75 65 20 |st) ? ne|w_value |
|00001f70| 3a 20 2a 66 69 72 73 74 | 3b 0a 09 2b 2b 66 69 72 |: *first|;..++fir|
|00001f80| 73 74 3b 0a 20 20 20 20 | 7d 0a 20 20 20 20 72 65 |st;. |}. re|
|00001f90| 74 75 72 6e 20 72 65 73 | 75 6c 74 3b 0a 7d 0a 0a |turn res|ult;.}..|
|00001fa0| 74 65 6d 70 6c 61 74 65 | 20 3c 63 6c 61 73 73 20 |template| <class |
|00001fb0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 2c |ForwardI|terator,|
|00001fc0| 20 63 6c 61 73 73 20 47 | 65 6e 65 72 61 74 6f 72 | class G|enerator|
|00001fd0| 3e 0a 76 6f 69 64 20 67 | 65 6e 65 72 61 74 65 28 |>.void g|enerate(|
|00001fe0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 20 |ForwardI|terator |
|00001ff0| 66 69 72 73 74 2c 20 46 | 6f 72 77 61 72 64 49 74 |first, F|orwardIt|
|00002000| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 20 47 65 6e |erator l|ast, Gen|
|00002010| 65 72 61 74 6f 72 20 67 | 65 6e 29 20 7b 0a 20 20 |erator g|en) {. |
|00002020| 20 20 77 68 69 6c 65 20 | 28 66 69 72 73 74 20 21 | while |(first !|
|00002030| 3d 20 6c 61 73 74 29 20 | 2a 66 69 72 73 74 2b 2b |= last) |*first++|
|00002040| 20 3d 20 67 65 6e 28 29 | 3b 0a 7d 0a 0a 74 65 6d | = gen()|;.}..tem|
|00002050| 70 6c 61 74 65 20 3c 63 | 6c 61 73 73 20 4f 75 74 |plate <c|lass Out|
|00002060| 70 75 74 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |putItera|tor, cla|
|00002070| 73 73 20 53 69 7a 65 2c | 20 63 6c 61 73 73 20 47 |ss Size,| class G|
|00002080| 65 6e 65 72 61 74 6f 72 | 3e 0a 4f 75 74 70 75 74 |enerator|>.Output|
|00002090| 49 74 65 72 61 74 6f 72 | 20 67 65 6e 65 72 61 74 |Iterator| generat|
|000020a0| 65 5f 6e 28 4f 75 74 70 | 75 74 49 74 65 72 61 74 |e_n(Outp|utIterat|
|000020b0| 6f 72 20 66 69 72 73 74 | 2c 20 53 69 7a 65 20 6e |or first|, Size n|
|000020c0| 2c 20 47 65 6e 65 72 61 | 74 6f 72 20 67 65 6e 29 |, Genera|tor gen)|
|000020d0| 20 7b 0a 20 20 20 20 77 | 68 69 6c 65 20 28 6e 2d | {. w|hile (n-|
|000020e0| 2d 20 3e 20 30 29 20 2a | 66 69 72 73 74 2b 2b 20 |- > 0) *|first++ |
|000020f0| 3d 20 67 65 6e 28 29 3b | 0a 20 20 20 20 72 65 74 |= gen();|. ret|
|00002100| 75 72 6e 20 66 69 72 73 | 74 3b 0a 7d 0a 0a 74 65 |urn firs|t;.}..te|
|00002110| 6d 70 6c 61 74 65 20 3c | 63 6c 61 73 73 20 49 6e |mplate <|class In|
|00002120| 70 75 74 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |putItera|tor, cla|
|00002130| 73 73 20 4f 75 74 70 75 | 74 49 74 65 72 61 74 6f |ss Outpu|tIterato|
|00002140| 72 2c 20 63 6c 61 73 73 | 20 54 3e 0a 4f 75 74 70 |r, class| T>.Outp|
|00002150| 75 74 49 74 65 72 61 74 | 6f 72 20 72 65 6d 6f 76 |utIterat|or remov|
|00002160| 65 5f 63 6f 70 79 28 49 | 6e 70 75 74 49 74 65 72 |e_copy(I|nputIter|
|00002170| 61 74 6f 72 20 66 69 72 | 73 74 2c 20 49 6e 70 75 |ator fir|st, Inpu|
|00002180| 74 49 74 65 72 61 74 6f | 72 20 6c 61 73 74 2c 0a |tIterato|r last,.|
|00002190| 09 09 09 20 20 20 4f 75 | 74 70 75 74 49 74 65 72 |... Ou|tputIter|
|000021a0| 61 74 6f 72 20 72 65 73 | 75 6c 74 2c 20 63 6f 6e |ator res|ult, con|
|000021b0| 73 74 20 54 26 20 76 61 | 6c 75 65 29 20 7b 0a 20 |st T& va|lue) {. |
|000021c0| 20 20 20 77 68 69 6c 65 | 20 28 66 69 72 73 74 20 | while| (first |
|000021d0| 21 3d 20 6c 61 73 74 29 | 20 7b 0a 09 69 66 20 28 |!= last)| {..if (|
|000021e0| 2a 66 69 72 73 74 20 21 | 3d 20 76 61 6c 75 65 29 |*first !|= value)|
|000021f0| 20 2a 72 65 73 75 6c 74 | 2b 2b 20 3d 20 2a 66 69 | *result|++ = *fi|
|00002200| 72 73 74 3b 0a 09 2b 2b | 66 69 72 73 74 3b 0a 20 |rst;..++|first;. |
|00002210| 20 20 20 7d 0a 20 20 20 | 20 72 65 74 75 72 6e 20 | }. | return |
|00002220| 72 65 73 75 6c 74 3b 0a | 7d 0a 0a 74 65 6d 70 6c |result;.|}..templ|
|00002230| 61 74 65 20 3c 63 6c 61 | 73 73 20 49 6e 70 75 74 |ate <cla|ss Input|
|00002240| 49 74 65 72 61 74 6f 72 | 2c 20 63 6c 61 73 73 20 |Iterator|, class |
|00002250| 4f 75 74 70 75 74 49 74 | 65 72 61 74 6f 72 2c 20 |OutputIt|erator, |
|00002260| 63 6c 61 73 73 20 50 72 | 65 64 69 63 61 74 65 3e |class Pr|edicate>|
|00002270| 0a 4f 75 74 70 75 74 49 | 74 65 72 61 74 6f 72 20 |.OutputI|terator |
|00002280| 72 65 6d 6f 76 65 5f 63 | 6f 70 79 5f 69 66 28 49 |remove_c|opy_if(I|
|00002290| 6e 70 75 74 49 74 65 72 | 61 74 6f 72 20 66 69 72 |nputIter|ator fir|
|000022a0| 73 74 2c 20 49 6e 70 75 | 74 49 74 65 72 61 74 6f |st, Inpu|tIterato|
|000022b0| 72 20 6c 61 73 74 2c 0a | 09 09 09 20 20 20 20 20 |r last,.|... |
|000022c0| 20 4f 75 74 70 75 74 49 | 74 65 72 61 74 6f 72 20 | OutputI|terator |
|000022d0| 72 65 73 75 6c 74 2c 20 | 50 72 65 64 69 63 61 74 |result, |Predicat|
|000022e0| 65 20 70 72 65 64 29 20 | 7b 0a 20 20 20 20 77 68 |e pred) |{. wh|
|000022f0| 69 6c 65 20 28 66 69 72 | 73 74 20 21 3d 20 6c 61 |ile (fir|st != la|
|00002300| 73 74 29 20 7b 0a 09 69 | 66 20 28 21 70 72 65 64 |st) {..i|f (!pred|
|00002310| 28 2a 66 69 72 73 74 29 | 29 20 2a 72 65 73 75 6c |(*first)|) *resul|
|00002320| 74 2b 2b 20 3d 20 2a 66 | 69 72 73 74 3b 0a 09 2b |t++ = *f|irst;..+|
|00002330| 2b 66 69 72 73 74 3b 0a | 20 20 20 20 7d 0a 20 20 |+first;.| }. |
|00002340| 20 20 72 65 74 75 72 6e | 20 72 65 73 75 6c 74 3b | return| result;|
|00002350| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00002360| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|00002370| 74 6f 72 2c 20 63 6c 61 | 73 73 20 54 3e 0a 46 6f |tor, cla|ss T>.Fo|
|00002380| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 20 72 65 |rwardIte|rator re|
|00002390| 6d 6f 76 65 28 46 6f 72 | 77 61 72 64 49 74 65 72 |move(For|wardIter|
|000023a0| 61 74 6f 72 20 66 69 72 | 73 74 2c 20 46 6f 72 77 |ator fir|st, Forw|
|000023b0| 61 72 64 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |ardItera|tor last|
|000023c0| 2c 0a 09 09 20 20 20 20 | 20 20 20 63 6f 6e 73 74 |,... | const|
|000023d0| 20 54 26 20 76 61 6c 75 | 65 29 20 7b 0a 20 20 20 | T& valu|e) {. |
|000023e0| 20 66 69 72 73 74 20 3d | 20 66 69 6e 64 28 66 69 | first =| find(fi|
|000023f0| 72 73 74 2c 20 6c 61 73 | 74 2c 20 76 61 6c 75 65 |rst, las|t, value|
|00002400| 29 3b 0a 20 20 20 20 46 | 6f 72 77 61 72 64 49 74 |);. F|orwardIt|
|00002410| 65 72 61 74 6f 72 20 6e | 65 78 74 20 3d 20 66 69 |erator n|ext = fi|
|00002420| 72 73 74 3b 0a 20 20 20 | 20 72 65 74 75 72 6e 20 |rst;. | return |
|00002430| 66 69 72 73 74 20 3d 3d | 20 6c 61 73 74 20 3f 20 |first ==| last ? |
|00002440| 66 69 72 73 74 20 3a 20 | 72 65 6d 6f 76 65 5f 63 |first : |remove_c|
|00002450| 6f 70 79 28 2b 2b 6e 65 | 78 74 2c 20 6c 61 73 74 |opy(++ne|xt, last|
|00002460| 2c 20 66 69 72 73 74 2c | 20 76 61 6c 75 65 29 3b |, first,| value);|
|00002470| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00002480| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|00002490| 74 6f 72 2c 20 63 6c 61 | 73 73 20 50 72 65 64 69 |tor, cla|ss Predi|
|000024a0| 63 61 74 65 3e 0a 46 6f | 72 77 61 72 64 49 74 65 |cate>.Fo|rwardIte|
|000024b0| 72 61 74 6f 72 20 72 65 | 6d 6f 76 65 5f 69 66 28 |rator re|move_if(|
|000024c0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 20 |ForwardI|terator |
|000024d0| 66 69 72 73 74 2c 20 46 | 6f 72 77 61 72 64 49 74 |first, F|orwardIt|
|000024e0| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 0a 09 09 09 |erator l|ast,....|
|000024f0| 20 20 50 72 65 64 69 63 | 61 74 65 20 70 72 65 64 | Predic|ate pred|
|00002500| 29 20 7b 0a 20 20 20 20 | 66 69 72 73 74 20 3d 20 |) {. |first = |
|00002510| 66 69 6e 64 5f 69 66 28 | 66 69 72 73 74 2c 20 6c |find_if(|first, l|
|00002520| 61 73 74 2c 20 70 72 65 | 64 29 3b 0a 20 20 20 20 |ast, pre|d);. |
|00002530| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 20 |ForwardI|terator |
|00002540| 6e 65 78 74 20 3d 20 66 | 69 72 73 74 3b 0a 20 20 |next = f|irst;. |
|00002550| 20 20 72 65 74 75 72 6e | 20 66 69 72 73 74 20 3d | return| first =|
|00002560| 3d 20 6c 61 73 74 20 3f | 20 66 69 72 73 74 20 3a |= last ?| first :|
|00002570| 20 72 65 6d 6f 76 65 5f | 63 6f 70 79 5f 69 66 28 | remove_|copy_if(|
|00002580| 2b 2b 6e 65 78 74 2c 20 | 6c 61 73 74 2c 20 66 69 |++next, |last, fi|
|00002590| 72 73 74 2c 20 70 72 65 | 64 29 3b 0a 7d 0a 0a 74 |rst, pre|d);.}..t|
|000025a0| 65 6d 70 6c 61 74 65 20 | 3c 63 6c 61 73 73 20 49 |emplate |<class I|
|000025b0| 6e 70 75 74 49 74 65 72 | 61 74 6f 72 2c 20 63 6c |nputIter|ator, cl|
|000025c0| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|000025d0| 74 6f 72 3e 0a 46 6f 72 | 77 61 72 64 49 74 65 72 |tor>.For|wardIter|
|000025e0| 61 74 6f 72 20 5f 5f 75 | 6e 69 71 75 65 5f 63 6f |ator __u|nique_co|
|000025f0| 70 79 28 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |py(Input|Iterator|
|00002600| 20 66 69 72 73 74 2c 20 | 49 6e 70 75 74 49 74 65 | first, |InputIte|
|00002610| 72 61 74 6f 72 20 6c 61 | 73 74 2c 0a 09 09 09 20 |rator la|st,.... |
|00002620| 20 20 20 20 20 46 6f 72 | 77 61 72 64 49 74 65 72 | For|wardIter|
|00002630| 61 74 6f 72 20 72 65 73 | 75 6c 74 2c 20 66 6f 72 |ator res|ult, for|
|00002640| 77 61 72 64 5f 69 74 65 | 72 61 74 6f 72 5f 74 61 |ward_ite|rator_ta|
|00002650| 67 29 20 7b 0a 20 20 20 | 20 2a 72 65 73 75 6c 74 |g) {. | *result|
|00002660| 20 3d 20 2a 66 69 72 73 | 74 3b 0a 20 20 20 20 77 | = *firs|t;. w|
|00002670| 68 69 6c 65 20 28 2b 2b | 66 69 72 73 74 20 21 3d |hile (++|first !=|
|00002680| 20 6c 61 73 74 29 0a 20 | 20 20 20 20 20 20 20 69 | last). | i|
|00002690| 66 20 28 2a 72 65 73 75 | 6c 74 20 21 3d 20 2a 66 |f (*resu|lt != *f|
|000026a0| 69 72 73 74 29 20 2a 2b | 2b 72 65 73 75 6c 74 20 |irst) *+|+result |
|000026b0| 3d 20 2a 66 69 72 73 74 | 3b 0a 20 20 20 20 72 65 |= *first|;. re|
|000026c0| 74 75 72 6e 20 2b 2b 72 | 65 73 75 6c 74 3b 0a 7d |turn ++r|esult;.}|
|000026d0| 0a 0a 74 65 6d 70 6c 61 | 74 65 20 3c 63 6c 61 73 |..templa|te <clas|
|000026e0| 73 20 49 6e 70 75 74 49 | 74 65 72 61 74 6f 72 2c |s InputI|terator,|
|000026f0| 20 63 6c 61 73 73 20 42 | 69 64 69 72 65 63 74 69 | class B|idirecti|
|00002700| 6f 6e 61 6c 49 74 65 72 | 61 74 6f 72 3e 0a 69 6e |onalIter|ator>.in|
|00002710| 6c 69 6e 65 20 42 69 64 | 69 72 65 63 74 69 6f 6e |line Bid|irection|
|00002720| 61 6c 49 74 65 72 61 74 | 6f 72 20 5f 5f 75 6e 69 |alIterat|or __uni|
|00002730| 71 75 65 5f 63 6f 70 79 | 28 49 6e 70 75 74 49 74 |que_copy|(InputIt|
|00002740| 65 72 61 74 6f 72 20 66 | 69 72 73 74 2c 20 0a 09 |erator f|irst, ..|
|00002750| 09 09 09 09 20 20 20 49 | 6e 70 75 74 49 74 65 72 |.... I|nputIter|
|00002760| 61 74 6f 72 20 6c 61 73 | 74 2c 0a 09 09 09 20 20 |ator las|t,.... |
|00002770| 20 20 20 20 20 20 20 20 | 20 20 09 20 20 20 42 69 | | . Bi|
|00002780| 64 69 72 65 63 74 69 6f | 6e 61 6c 49 74 65 72 61 |directio|nalItera|
|00002790| 74 6f 72 20 72 65 73 75 | 6c 74 2c 20 0a 09 09 09 |tor resu|lt, ....|
|000027a0| 09 20 20 20 20 09 20 20 | 20 62 69 64 69 72 65 63 |. . | bidirec|
|000027b0| 74 69 6f 6e 61 6c 5f 69 | 74 65 72 61 74 6f 72 5f |tional_i|terator_|
|000027c0| 74 61 67 29 20 7b 0a 20 | 20 20 20 72 65 74 75 72 |tag) {. | retur|
|000027d0| 6e 20 5f 5f 75 6e 69 71 | 75 65 5f 63 6f 70 79 28 |n __uniq|ue_copy(|
|000027e0| 66 69 72 73 74 2c 20 6c | 61 73 74 2c 20 72 65 73 |first, l|ast, res|
|000027f0| 75 6c 74 2c 20 66 6f 72 | 77 61 72 64 5f 69 74 65 |ult, for|ward_ite|
|00002800| 72 61 74 6f 72 5f 74 61 | 67 28 29 29 3b 0a 7d 0a |rator_ta|g());.}.|
|00002810| 0a 74 65 6d 70 6c 61 74 | 65 20 3c 63 6c 61 73 73 |.templat|e <class|
|00002820| 20 49 6e 70 75 74 49 74 | 65 72 61 74 6f 72 2c 20 | InputIt|erator, |
|00002830| 63 6c 61 73 73 20 52 61 | 6e 64 6f 6d 41 63 63 65 |class Ra|ndomAcce|
|00002840| 73 73 49 74 65 72 61 74 | 6f 72 3e 0a 69 6e 6c 69 |ssIterat|or>.inli|
|00002850| 6e 65 20 52 61 6e 64 6f | 6d 41 63 63 65 73 73 49 |ne Rando|mAccessI|
|00002860| 74 65 72 61 74 6f 72 20 | 5f 5f 75 6e 69 71 75 65 |terator |__unique|
|00002870| 5f 63 6f 70 79 28 49 6e | 70 75 74 49 74 65 72 61 |_copy(In|putItera|
|00002880| 74 6f 72 20 66 69 72 73 | 74 2c 20 0a 09 09 09 09 |tor firs|t, .....|
|00002890| 09 20 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |. Input|Iterator|
|000028a0| 20 6c 61 73 74 2c 0a 09 | 09 09 20 20 20 20 20 20 | last,..|.. |
|000028b0| 20 20 20 20 20 09 20 20 | 52 61 6e 64 6f 6d 41 63 | . |RandomAc|
|000028c0| 63 65 73 73 49 74 65 72 | 61 74 6f 72 20 72 65 73 |cessIter|ator res|
|000028d0| 75 6c 74 2c 20 0a 09 09 | 09 09 20 20 20 09 20 20 |ult, ...|.. . |
|000028e0| 72 61 6e 64 6f 6d 5f 61 | 63 63 65 73 73 5f 69 74 |random_a|ccess_it|
|000028f0| 65 72 61 74 6f 72 5f 74 | 61 67 29 20 7b 0a 20 20 |erator_t|ag) {. |
|00002900| 20 20 72 65 74 75 72 6e | 20 5f 5f 75 6e 69 71 75 | return| __uniqu|
|00002910| 65 5f 63 6f 70 79 28 66 | 69 72 73 74 2c 20 6c 61 |e_copy(f|irst, la|
|00002920| 73 74 2c 20 72 65 73 75 | 6c 74 2c 20 66 6f 72 77 |st, resu|lt, forw|
|00002930| 61 72 64 5f 69 74 65 72 | 61 74 6f 72 5f 74 61 67 |ard_iter|ator_tag|
|00002940| 28 29 29 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |());.}..|template|
|00002950| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00002960| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 4f 75 74 |rator, c|lass Out|
|00002970| 70 75 74 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |putItera|tor, cla|
|00002980| 73 73 20 54 3e 0a 4f 75 | 74 70 75 74 49 74 65 72 |ss T>.Ou|tputIter|
|00002990| 61 74 6f 72 20 5f 5f 75 | 6e 69 71 75 65 5f 63 6f |ator __u|nique_co|
|000029a0| 70 79 28 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |py(Input|Iterator|
|000029b0| 20 66 69 72 73 74 2c 20 | 49 6e 70 75 74 49 74 65 | first, |InputIte|
|000029c0| 72 61 74 6f 72 20 6c 61 | 73 74 2c 0a 09 09 09 20 |rator la|st,.... |
|000029d0| 20 20 20 20 4f 75 74 70 | 75 74 49 74 65 72 61 74 | Outp|utIterat|
|000029e0| 6f 72 20 72 65 73 75 6c | 74 2c 20 54 2a 29 20 7b |or resul|t, T*) {|
|000029f0| 0a 20 20 20 20 54 20 76 | 61 6c 75 65 20 3d 20 2a |. T v|alue = *|
|00002a00| 66 69 72 73 74 3b 0a 20 | 20 20 20 2a 72 65 73 75 |first;. | *resu|
|00002a10| 6c 74 20 3d 20 76 61 6c | 75 65 3b 0a 20 20 20 20 |lt = val|ue;. |
|00002a20| 77 68 69 6c 65 20 28 2b | 2b 66 69 72 73 74 20 21 |while (+|+first !|
|00002a30| 3d 20 6c 61 73 74 29 0a | 09 69 66 20 28 76 61 6c |= last).|.if (val|
|00002a40| 75 65 20 21 3d 20 2a 66 | 69 72 73 74 29 20 7b 0a |ue != *f|irst) {.|
|00002a50| 09 20 20 20 20 76 61 6c | 75 65 20 3d 20 2a 66 69 |. val|ue = *fi|
|00002a60| 72 73 74 3b 0a 09 20 20 | 20 20 2a 2b 2b 72 65 73 |rst;.. | *++res|
|00002a70| 75 6c 74 20 3d 20 76 61 | 6c 75 65 3b 0a 09 7d 0a |ult = va|lue;..}.|
|00002a80| 20 20 20 20 72 65 74 75 | 72 6e 20 2b 2b 72 65 73 | retu|rn ++res|
|00002a90| 75 6c 74 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |ult;.}..|template|
|00002aa0| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00002ab0| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 4f 75 74 |rator, c|lass Out|
|00002ac0| 70 75 74 49 74 65 72 61 | 74 6f 72 3e 0a 69 6e 6c |putItera|tor>.inl|
|00002ad0| 69 6e 65 20 4f 75 74 70 | 75 74 49 74 65 72 61 74 |ine Outp|utIterat|
|00002ae0| 6f 72 20 5f 5f 75 6e 69 | 71 75 65 5f 63 6f 70 79 |or __uni|que_copy|
|00002af0| 28 49 6e 70 75 74 49 74 | 65 72 61 74 6f 72 20 66 |(InputIt|erator f|
|00002b00| 69 72 73 74 2c 20 49 6e | 70 75 74 49 74 65 72 61 |irst, In|putItera|
|00002b10| 74 6f 72 20 6c 61 73 74 | 2c 0a 20 20 20 20 20 20 |tor last|,. |
|00002b20| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002b30| 20 20 20 20 20 20 20 09 | 20 20 20 20 4f 75 74 70 | .| Outp|
|00002b40| 75 74 49 74 65 72 61 74 | 6f 72 20 72 65 73 75 6c |utIterat|or resul|
|00002b50| 74 2c 20 0a 09 09 09 09 | 20 20 20 20 6f 75 74 70 |t, .....| outp|
|00002b60| 75 74 5f 69 74 65 72 61 | 74 6f 72 5f 74 61 67 29 |ut_itera|tor_tag)|
|00002b70| 20 7b 0a 20 20 20 20 72 | 65 74 75 72 6e 20 5f 5f | {. r|eturn __|
|00002b80| 75 6e 69 71 75 65 5f 63 | 6f 70 79 28 66 69 72 73 |unique_c|opy(firs|
|00002b90| 74 2c 20 6c 61 73 74 2c | 20 72 65 73 75 6c 74 2c |t, last,| result,|
|00002ba0| 20 76 61 6c 75 65 5f 74 | 79 70 65 28 66 69 72 73 | value_t|ype(firs|
|00002bb0| 74 29 29 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |t));.}..|template|
|00002bc0| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00002bd0| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 4f 75 74 |rator, c|lass Out|
|00002be0| 70 75 74 49 74 65 72 61 | 74 6f 72 3e 0a 69 6e 6c |putItera|tor>.inl|
|00002bf0| 69 6e 65 20 4f 75 74 70 | 75 74 49 74 65 72 61 74 |ine Outp|utIterat|
|00002c00| 6f 72 20 75 6e 69 71 75 | 65 5f 63 6f 70 79 28 49 |or uniqu|e_copy(I|
|00002c10| 6e 70 75 74 49 74 65 72 | 61 74 6f 72 20 66 69 72 |nputIter|ator fir|
|00002c20| 73 74 2c 20 49 6e 70 75 | 74 49 74 65 72 61 74 6f |st, Inpu|tIterato|
|00002c30| 72 20 6c 61 73 74 2c 0a | 09 09 09 20 20 20 09 20 |r last,.|... . |
|00002c40| 20 4f 75 74 70 75 74 49 | 74 65 72 61 74 6f 72 20 | OutputI|terator |
|00002c50| 72 65 73 75 6c 74 29 20 | 7b 0a 20 20 20 20 69 66 |result) |{. if|
|00002c60| 20 28 66 69 72 73 74 20 | 3d 3d 20 6c 61 73 74 29 | (first |== last)|
|00002c70| 20 72 65 74 75 72 6e 20 | 72 65 73 75 6c 74 3b 0a | return |result;.|
|00002c80| 20 20 20 20 72 65 74 75 | 72 6e 20 5f 5f 75 6e 69 | retu|rn __uni|
|00002c90| 71 75 65 5f 63 6f 70 79 | 28 66 69 72 73 74 2c 20 |que_copy|(first, |
|00002ca0| 6c 61 73 74 2c 20 72 65 | 73 75 6c 74 2c 20 69 74 |last, re|sult, it|
|00002cb0| 65 72 61 74 6f 72 5f 63 | 61 74 65 67 6f 72 79 28 |erator_c|ategory(|
|00002cc0| 72 65 73 75 6c 74 29 29 | 3b 0a 7d 0a 74 65 6d 70 |result))|;.}.temp|
|00002cd0| 6c 61 74 65 20 3c 63 6c | 61 73 73 20 49 6e 70 75 |late <cl|ass Inpu|
|00002ce0| 74 49 74 65 72 61 74 6f | 72 2c 20 63 6c 61 73 73 |tIterato|r, class|
|00002cf0| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|00002d00| 2c 20 63 6c 61 73 73 20 | 42 69 6e 61 72 79 50 72 |, class |BinaryPr|
|00002d10| 65 64 69 63 61 74 65 3e | 0a 46 6f 72 77 61 72 64 |edicate>|.Forward|
|00002d20| 49 74 65 72 61 74 6f 72 | 20 5f 5f 75 6e 69 71 75 |Iterator| __uniqu|
|00002d30| 65 5f 63 6f 70 79 28 49 | 6e 70 75 74 49 74 65 72 |e_copy(I|nputIter|
|00002d40| 61 74 6f 72 20 66 69 72 | 73 74 2c 20 49 6e 70 75 |ator fir|st, Inpu|
|00002d50| 74 49 74 65 72 61 74 6f | 72 20 6c 61 73 74 2c 0a |tIterato|r last,.|
|00002d60| 09 09 09 20 20 20 20 20 | 20 46 6f 72 77 61 72 64 |... | Forward|
|00002d70| 49 74 65 72 61 74 6f 72 | 20 72 65 73 75 6c 74 2c |Iterator| result,|
|00002d80| 20 0a 09 09 09 20 20 20 | 20 20 20 42 69 6e 61 72 | .... | Binar|
|00002d90| 79 50 72 65 64 69 63 61 | 74 65 20 62 69 6e 61 72 |yPredica|te binar|
|00002da0| 79 5f 70 72 65 64 2c 0a | 09 09 09 20 20 20 20 20 |y_pred,.|... |
|00002db0| 20 66 6f 72 77 61 72 64 | 5f 69 74 65 72 61 74 6f | forward|_iterato|
|00002dc0| 72 5f 74 61 67 29 20 7b | 0a 20 20 20 20 2a 72 65 |r_tag) {|. *re|
|00002dd0| 73 75 6c 74 20 3d 20 2a | 66 69 72 73 74 3b 0a 20 |sult = *|first;. |
|00002de0| 20 20 20 77 68 69 6c 65 | 20 28 2b 2b 66 69 72 73 | while| (++firs|
|00002df0| 74 20 21 3d 20 6c 61 73 | 74 29 0a 20 20 20 20 20 |t != las|t). |
|00002e00| 20 20 20 69 66 20 28 21 | 62 69 6e 61 72 79 5f 70 | if (!|binary_p|
|00002e10| 72 65 64 28 2a 72 65 73 | 75 6c 74 2c 20 2a 66 69 |red(*res|ult, *fi|
|00002e20| 72 73 74 29 29 20 2a 2b | 2b 72 65 73 75 6c 74 20 |rst)) *+|+result |
|00002e30| 3d 20 2a 66 69 72 73 74 | 3b 0a 20 20 20 20 72 65 |= *first|;. re|
|00002e40| 74 75 72 6e 20 2b 2b 72 | 65 73 75 6c 74 3b 0a 7d |turn ++r|esult;.}|
|00002e50| 0a 0a 74 65 6d 70 6c 61 | 74 65 20 3c 63 6c 61 73 |..templa|te <clas|
|00002e60| 73 20 49 6e 70 75 74 49 | 74 65 72 61 74 6f 72 2c |s InputI|terator,|
|00002e70| 20 63 6c 61 73 73 20 42 | 69 64 69 72 65 63 74 69 | class B|idirecti|
|00002e80| 6f 6e 61 6c 49 74 65 72 | 61 74 6f 72 2c 0a 20 20 |onalIter|ator,. |
|00002e90| 20 20 20 20 20 20 20 20 | 63 6c 61 73 73 20 42 69 | |class Bi|
|00002ea0| 6e 61 72 79 50 72 65 64 | 69 63 61 74 65 3e 0a 69 |naryPred|icate>.i|
|00002eb0| 6e 6c 69 6e 65 20 42 69 | 64 69 72 65 63 74 69 6f |nline Bi|directio|
|00002ec0| 6e 61 6c 49 74 65 72 61 | 74 6f 72 20 5f 5f 75 6e |nalItera|tor __un|
|00002ed0| 69 71 75 65 5f 63 6f 70 | 79 28 49 6e 70 75 74 49 |ique_cop|y(InputI|
|00002ee0| 74 65 72 61 74 6f 72 20 | 66 69 72 73 74 2c 20 0a |terator |first, .|
|00002ef0| 09 09 09 09 09 20 20 20 | 49 6e 70 75 74 49 74 65 |..... |InputIte|
|00002f00| 72 61 74 6f 72 20 6c 61 | 73 74 2c 0a 09 09 09 20 |rator la|st,.... |
|00002f10| 20 20 20 20 20 20 20 20 | 20 20 20 09 20 20 20 42 | | . B|
|00002f20| 69 64 69 72 65 63 74 69 | 6f 6e 61 6c 49 74 65 72 |idirecti|onalIter|
|00002f30| 61 74 6f 72 20 72 65 73 | 75 6c 74 2c 20 0a 09 09 |ator res|ult, ...|
|00002f40| 09 09 09 20 20 20 42 69 | 6e 61 72 79 50 72 65 64 |... Bi|naryPred|
|00002f50| 69 63 61 74 65 20 62 69 | 6e 61 72 79 5f 70 72 65 |icate bi|nary_pre|
|00002f60| 64 2c 0a 09 09 09 09 20 | 20 20 20 09 20 20 20 62 |d,..... | . b|
|00002f70| 69 64 69 72 65 63 74 69 | 6f 6e 61 6c 5f 69 74 65 |idirecti|onal_ite|
|00002f80| 72 61 74 6f 72 5f 74 61 | 67 29 20 7b 0a 20 20 20 |rator_ta|g) {. |
|00002f90| 20 72 65 74 75 72 6e 20 | 5f 5f 75 6e 69 71 75 65 | return |__unique|
|00002fa0| 5f 63 6f 70 79 28 66 69 | 72 73 74 2c 20 6c 61 73 |_copy(fi|rst, las|
|00002fb0| 74 2c 20 72 65 73 75 6c | 74 2c 20 62 69 6e 61 72 |t, resul|t, binar|
|00002fc0| 79 5f 70 72 65 64 2c 0a | 09 09 09 20 66 6f 72 77 |y_pred,.|... forw|
|00002fd0| 61 72 64 5f 69 74 65 72 | 61 74 6f 72 5f 74 61 67 |ard_iter|ator_tag|
|00002fe0| 28 29 29 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |());.}..|template|
|00002ff0| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00003000| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 52 61 6e |rator, c|lass Ran|
|00003010| 64 6f 6d 41 63 63 65 73 | 73 49 74 65 72 61 74 6f |domAcces|sIterato|
|00003020| 72 2c 0a 20 20 20 20 20 | 20 20 20 20 20 63 6c 61 |r,. | cla|
|00003030| 73 73 20 42 69 6e 61 72 | 79 50 72 65 64 69 63 61 |ss Binar|yPredica|
|00003040| 74 65 3e 0a 69 6e 6c 69 | 6e 65 20 52 61 6e 64 6f |te>.inli|ne Rando|
|00003050| 6d 41 63 63 65 73 73 49 | 74 65 72 61 74 6f 72 20 |mAccessI|terator |
|00003060| 5f 5f 75 6e 69 71 75 65 | 5f 63 6f 70 79 28 49 6e |__unique|_copy(In|
|00003070| 70 75 74 49 74 65 72 61 | 74 6f 72 20 66 69 72 73 |putItera|tor firs|
|00003080| 74 2c 20 0a 09 09 09 09 | 09 20 20 49 6e 70 75 74 |t, .....|. Input|
|00003090| 49 74 65 72 61 74 6f 72 | 20 6c 61 73 74 2c 0a 09 |Iterator| last,..|
|000030a0| 09 09 20 20 20 20 20 20 | 20 20 20 20 20 09 20 20 |.. | . |
|000030b0| 52 61 6e 64 6f 6d 41 63 | 63 65 73 73 49 74 65 72 |RandomAc|cessIter|
|000030c0| 61 74 6f 72 20 72 65 73 | 75 6c 74 2c 20 0a 09 09 |ator res|ult, ...|
|000030d0| 09 09 09 20 20 42 69 6e | 61 72 79 50 72 65 64 69 |... Bin|aryPredi|
|000030e0| 63 61 74 65 20 62 69 6e | 61 72 79 5f 70 72 65 64 |cate bin|ary_pred|
|000030f0| 2c 0a 09 09 09 09 20 20 | 20 09 20 20 72 61 6e 64 |,..... | . rand|
|00003100| 6f 6d 5f 61 63 63 65 73 | 73 5f 69 74 65 72 61 74 |om_acces|s_iterat|
|00003110| 6f 72 5f 74 61 67 29 20 | 7b 0a 20 20 20 20 72 65 |or_tag) |{. re|
|00003120| 74 75 72 6e 20 5f 5f 75 | 6e 69 71 75 65 5f 63 6f |turn __u|nique_co|
|00003130| 70 79 28 66 69 72 73 74 | 2c 20 6c 61 73 74 2c 20 |py(first|, last, |
|00003140| 72 65 73 75 6c 74 2c 20 | 62 69 6e 61 72 79 5f 70 |result, |binary_p|
|00003150| 72 65 64 2c 20 0a 09 09 | 09 20 66 6f 72 77 61 72 |red, ...|. forwar|
|00003160| 64 5f 69 74 65 72 61 74 | 6f 72 5f 74 61 67 28 29 |d_iterat|or_tag()|
|00003170| 29 3b 0a 7d 0a 0a 74 65 | 6d 70 6c 61 74 65 20 3c |);.}..te|mplate <|
|00003180| 63 6c 61 73 73 20 49 6e | 70 75 74 49 74 65 72 61 |class In|putItera|
|00003190| 74 6f 72 2c 20 63 6c 61 | 73 73 20 4f 75 74 70 75 |tor, cla|ss Outpu|
|000031a0| 74 49 74 65 72 61 74 6f | 72 2c 20 63 6c 61 73 73 |tIterato|r, class|
|000031b0| 20 42 69 6e 61 72 79 50 | 72 65 64 69 63 61 74 65 | BinaryP|redicate|
|000031c0| 2c 0a 20 20 20 20 20 20 | 20 20 20 20 63 6c 61 73 |,. | clas|
|000031d0| 73 20 54 3e 0a 4f 75 74 | 70 75 74 49 74 65 72 61 |s T>.Out|putItera|
|000031e0| 74 6f 72 20 5f 5f 75 6e | 69 71 75 65 5f 63 6f 70 |tor __un|ique_cop|
|000031f0| 79 28 49 6e 70 75 74 49 | 74 65 72 61 74 6f 72 20 |y(InputI|terator |
|00003200| 66 69 72 73 74 2c 20 49 | 6e 70 75 74 49 74 65 72 |first, I|nputIter|
|00003210| 61 74 6f 72 20 6c 61 73 | 74 2c 0a 09 09 09 20 20 |ator las|t,.... |
|00003220| 20 20 20 4f 75 74 70 75 | 74 49 74 65 72 61 74 6f | Outpu|tIterato|
|00003230| 72 20 72 65 73 75 6c 74 | 2c 0a 09 09 09 20 20 20 |r result|,.... |
|00003240| 20 20 42 69 6e 61 72 79 | 50 72 65 64 69 63 61 74 | Binary|Predicat|
|00003250| 65 20 62 69 6e 61 72 79 | 5f 70 72 65 64 2c 20 54 |e binary|_pred, T|
|00003260| 2a 29 20 7b 0a 20 20 20 | 20 54 20 76 61 6c 75 65 |*) {. | T value|
|00003270| 20 3d 20 2a 66 69 72 73 | 74 3b 0a 20 20 20 20 2a | = *firs|t;. *|
|00003280| 72 65 73 75 6c 74 20 3d | 20 76 61 6c 75 65 3b 0a |result =| value;.|
|00003290| 20 20 20 20 77 68 69 6c | 65 20 28 2b 2b 66 69 72 | whil|e (++fir|
|000032a0| 73 74 20 21 3d 20 6c 61 | 73 74 29 0a 09 69 66 20 |st != la|st)..if |
|000032b0| 28 21 62 69 6e 61 72 79 | 5f 70 72 65 64 28 76 61 |(!binary|_pred(va|
|000032c0| 6c 75 65 2c 20 2a 66 69 | 72 73 74 29 29 20 7b 0a |lue, *fi|rst)) {.|
|000032d0| 09 20 20 20 20 76 61 6c | 75 65 20 3d 20 2a 66 69 |. val|ue = *fi|
|000032e0| 72 73 74 3b 0a 09 20 20 | 20 20 2a 2b 2b 72 65 73 |rst;.. | *++res|
|000032f0| 75 6c 74 20 3d 20 76 61 | 6c 75 65 3b 0a 09 7d 0a |ult = va|lue;..}.|
|00003300| 20 20 20 20 72 65 74 75 | 72 6e 20 2b 2b 72 65 73 | retu|rn ++res|
|00003310| 75 6c 74 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |ult;.}..|template|
|00003320| 20 3c 63 6c 61 73 73 20 | 49 6e 70 75 74 49 74 65 | <class |InputIte|
|00003330| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 4f 75 74 |rator, c|lass Out|
|00003340| 70 75 74 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |putItera|tor, cla|
|00003350| 73 73 20 42 69 6e 61 72 | 79 50 72 65 64 69 63 61 |ss Binar|yPredica|
|00003360| 74 65 3e 0a 69 6e 6c 69 | 6e 65 20 4f 75 74 70 75 |te>.inli|ne Outpu|
|00003370| 74 49 74 65 72 61 74 6f | 72 20 5f 5f 75 6e 69 71 |tIterato|r __uniq|
|00003380| 75 65 5f 63 6f 70 79 28 | 49 6e 70 75 74 49 74 65 |ue_copy(|InputIte|
|00003390| 72 61 74 6f 72 20 66 69 | 72 73 74 2c 20 49 6e 70 |rator fi|rst, Inp|
|000033a0| 75 74 49 74 65 72 61 74 | 6f 72 20 6c 61 73 74 2c |utIterat|or last,|
|000033b0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|000033c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 09 20 | | . |
|000033d0| 20 20 20 4f 75 74 70 75 | 74 49 74 65 72 61 74 6f | Outpu|tIterato|
|000033e0| 72 20 72 65 73 75 6c 74 | 2c 0a 09 09 09 09 20 20 |r result|,..... |
|000033f0| 20 20 42 69 6e 61 72 79 | 50 72 65 64 69 63 61 74 | Binary|Predicat|
|00003400| 65 20 62 69 6e 61 72 79 | 5f 70 72 65 64 2c 0a 09 |e binary|_pred,..|
|00003410| 09 09 09 20 20 20 20 6f | 75 74 70 75 74 5f 69 74 |... o|utput_it|
|00003420| 65 72 61 74 6f 72 5f 74 | 61 67 29 20 7b 0a 20 20 |erator_t|ag) {. |
|00003430| 20 20 72 65 74 75 72 6e | 20 5f 5f 75 6e 69 71 75 | return| __uniqu|
|00003440| 65 5f 63 6f 70 79 28 66 | 69 72 73 74 2c 20 6c 61 |e_copy(f|irst, la|
|00003450| 73 74 2c 20 72 65 73 75 | 6c 74 2c 20 62 69 6e 61 |st, resu|lt, bina|
|00003460| 72 79 5f 70 72 65 64 2c | 20 76 61 6c 75 65 5f 74 |ry_pred,| value_t|
|00003470| 79 70 65 28 66 69 72 73 | 74 29 29 3b 0a 7d 0a 0a |ype(firs|t));.}..|
|00003480| 74 65 6d 70 6c 61 74 65 | 20 3c 63 6c 61 73 73 20 |template| <class |
|00003490| 49 6e 70 75 74 49 74 65 | 72 61 74 6f 72 2c 20 63 |InputIte|rator, c|
|000034a0| 6c 61 73 73 20 4f 75 74 | 70 75 74 49 74 65 72 61 |lass Out|putItera|
|000034b0| 74 6f 72 2c 20 63 6c 61 | 73 73 20 42 69 6e 61 72 |tor, cla|ss Binar|
|000034c0| 79 50 72 65 64 69 63 61 | 74 65 3e 0a 69 6e 6c 69 |yPredica|te>.inli|
|000034d0| 6e 65 20 4f 75 74 70 75 | 74 49 74 65 72 61 74 6f |ne Outpu|tIterato|
|000034e0| 72 20 75 6e 69 71 75 65 | 5f 63 6f 70 79 28 49 6e |r unique|_copy(In|
|000034f0| 70 75 74 49 74 65 72 61 | 74 6f 72 20 66 69 72 73 |putItera|tor firs|
|00003500| 74 2c 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |t, Input|Iterator|
|00003510| 20 6c 61 73 74 2c 0a 09 | 09 09 20 20 20 09 20 20 | last,..|.. . |
|00003520| 4f 75 74 70 75 74 49 74 | 65 72 61 74 6f 72 20 72 |OutputIt|erator r|
|00003530| 65 73 75 6c 74 2c 0a 09 | 09 09 09 20 20 42 69 6e |esult,..|... Bin|
|00003540| 61 72 79 50 72 65 64 69 | 63 61 74 65 20 62 69 6e |aryPredi|cate bin|
|00003550| 61 72 79 5f 70 72 65 64 | 29 20 7b 0a 20 20 20 20 |ary_pred|) {. |
|00003560| 69 66 20 28 66 69 72 73 | 74 20 3d 3d 20 6c 61 73 |if (firs|t == las|
|00003570| 74 29 20 72 65 74 75 72 | 6e 20 72 65 73 75 6c 74 |t) retur|n result|
|00003580| 3b 0a 20 20 20 20 72 65 | 74 75 72 6e 20 5f 5f 75 |;. re|turn __u|
|00003590| 6e 69 71 75 65 5f 63 6f | 70 79 28 66 69 72 73 74 |nique_co|py(first|
|000035a0| 2c 20 6c 61 73 74 2c 20 | 72 65 73 75 6c 74 2c 20 |, last, |result, |
|000035b0| 62 69 6e 61 72 79 5f 70 | 72 65 64 2c 0a 09 09 09 |binary_p|red,....|
|000035c0| 20 69 74 65 72 61 74 6f | 72 5f 63 61 74 65 67 6f | iterato|r_catego|
|000035d0| 72 79 28 72 65 73 75 6c | 74 29 29 3b 0a 7d 0a 0a |ry(resul|t));.}..|
|000035e0| 74 65 6d 70 6c 61 74 65 | 20 3c 63 6c 61 73 73 20 |template| <class |
|000035f0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 3e |ForwardI|terator>|
|00003600| 0a 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 |.Forward|Iterator|
|00003610| 20 75 6e 69 71 75 65 28 | 46 6f 72 77 61 72 64 49 | unique(|ForwardI|
|00003620| 74 65 72 61 74 6f 72 20 | 66 69 72 73 74 2c 20 46 |terator |first, F|
|00003630| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 20 6c |orwardIt|erator l|
|00003640| 61 73 74 29 20 7b 0a 20 | 20 20 20 66 69 72 73 74 |ast) {. | first|
|00003650| 20 3d 20 61 64 6a 61 63 | 65 6e 74 5f 66 69 6e 64 | = adjac|ent_find|
|00003660| 28 66 69 72 73 74 2c 20 | 6c 61 73 74 29 3b 0a 20 |(first, |last);. |
|00003670| 20 20 20 72 65 74 75 72 | 6e 20 75 6e 69 71 75 65 | retur|n unique|
|00003680| 5f 63 6f 70 79 28 66 69 | 72 73 74 2c 20 6c 61 73 |_copy(fi|rst, las|
|00003690| 74 2c 20 66 69 72 73 74 | 29 3b 0a 7d 0a 0a 74 65 |t, first|);.}..te|
|000036a0| 6d 70 6c 61 74 65 20 3c | 63 6c 61 73 73 20 46 6f |mplate <|class Fo|
|000036b0| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 2c 20 63 |rwardIte|rator, c|
|000036c0| 6c 61 73 73 20 42 69 6e | 61 72 79 50 72 65 64 69 |lass Bin|aryPredi|
|000036d0| 63 61 74 65 3e 0a 46 6f | 72 77 61 72 64 49 74 65 |cate>.Fo|rwardIte|
|000036e0| 72 61 74 6f 72 20 75 6e | 69 71 75 65 28 46 6f 72 |rator un|ique(For|
|000036f0| 77 61 72 64 49 74 65 72 | 61 74 6f 72 20 66 69 72 |wardIter|ator fir|
|00003700| 73 74 2c 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |st, Forw|ardItera|
|00003710| 74 6f 72 20 6c 61 73 74 | 2c 0a 09 09 20 20 20 20 |tor last|,... |
|00003720| 20 20 20 42 69 6e 61 72 | 79 50 72 65 64 69 63 61 | Binar|yPredica|
|00003730| 74 65 20 62 69 6e 61 72 | 79 5f 70 72 65 64 29 20 |te binar|y_pred) |
|00003740| 7b 0a 20 20 20 20 66 69 | 72 73 74 20 3d 20 61 64 |{. fi|rst = ad|
|00003750| 6a 61 63 65 6e 74 5f 66 | 69 6e 64 28 66 69 72 73 |jacent_f|ind(firs|
|00003760| 74 2c 20 6c 61 73 74 2c | 20 62 69 6e 61 72 79 5f |t, last,| binary_|
|00003770| 70 72 65 64 29 3b 0a 20 | 20 20 20 72 65 74 75 72 |pred);. | retur|
|00003780| 6e 20 75 6e 69 71 75 65 | 5f 63 6f 70 79 28 66 69 |n unique|_copy(fi|
|00003790| 72 73 74 2c 20 6c 61 73 | 74 2c 20 66 69 72 73 74 |rst, las|t, first|
|000037a0| 2c 20 62 69 6e 61 72 79 | 5f 70 72 65 64 29 3b 0a |, binary|_pred);.|
|000037b0| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|000037c0| 73 73 20 42 69 64 69 72 | 65 63 74 69 6f 6e 61 6c |ss Bidir|ectional|
|000037d0| 49 74 65 72 61 74 6f 72 | 3e 0a 76 6f 69 64 20 5f |Iterator|>.void _|
|000037e0| 5f 72 65 76 65 72 73 65 | 28 42 69 64 69 72 65 63 |_reverse|(Bidirec|
|000037f0| 74 69 6f 6e 61 6c 49 74 | 65 72 61 74 6f 72 20 66 |tionalIt|erator f|
|00003800| 69 72 73 74 2c 20 42 69 | 64 69 72 65 63 74 69 6f |irst, Bi|directio|
|00003810| 6e 61 6c 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |nalItera|tor last|
|00003820| 2c 20 0a 09 20 20 20 20 | 20 20 20 62 69 64 69 72 |, .. | bidir|
|00003830| 65 63 74 69 6f 6e 61 6c | 5f 69 74 65 72 61 74 6f |ectional|_iterato|
|00003840| 72 5f 74 61 67 29 20 7b | 0a 20 20 20 20 77 68 69 |r_tag) {|. whi|
|00003850| 6c 65 20 28 74 72 75 65 | 29 0a 20 20 20 20 20 20 |le (true|). |
|00003860| 20 20 69 66 20 28 66 69 | 72 73 74 20 3d 3d 20 6c | if (fi|rst == l|
|00003870| 61 73 74 20 7c 7c 20 66 | 69 72 73 74 20 3d 3d 20 |ast || f|irst == |
|00003880| 2d 2d 6c 61 73 74 29 0a | 09 20 20 20 20 72 65 74 |--last).|. ret|
|00003890| 75 72 6e 3b 0a 20 20 20 | 20 20 20 20 20 65 6c 73 |urn;. | els|
|000038a0| 65 0a 09 20 20 20 20 69 | 74 65 72 5f 73 77 61 70 |e.. i|ter_swap|
|000038b0| 28 66 69 72 73 74 2b 2b | 2c 20 6c 61 73 74 29 3b |(first++|, last);|
|000038c0| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|000038d0| 61 73 73 20 52 61 6e 64 | 6f 6d 41 63 63 65 73 73 |ass Rand|omAccess|
|000038e0| 49 74 65 72 61 74 6f 72 | 3e 0a 76 6f 69 64 20 5f |Iterator|>.void _|
|000038f0| 5f 72 65 76 65 72 73 65 | 28 52 61 6e 64 6f 6d 41 |_reverse|(RandomA|
|00003900| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 20 66 69 |ccessIte|rator fi|
|00003910| 72 73 74 2c 20 52 61 6e | 64 6f 6d 41 63 63 65 73 |rst, Ran|domAcces|
|00003920| 73 49 74 65 72 61 74 6f | 72 20 6c 61 73 74 2c 0a |sIterato|r last,.|
|00003930| 09 20 20 20 20 20 20 20 | 72 61 6e 64 6f 6d 5f 61 |. |random_a|
|00003940| 63 63 65 73 73 5f 69 74 | 65 72 61 74 6f 72 5f 74 |ccess_it|erator_t|
|00003950| 61 67 29 20 7b 0a 20 20 | 20 20 77 68 69 6c 65 20 |ag) {. | while |
|00003960| 28 66 69 72 73 74 20 3c | 20 6c 61 73 74 29 20 69 |(first <| last) i|
|00003970| 74 65 72 5f 73 77 61 70 | 28 66 69 72 73 74 2b 2b |ter_swap|(first++|
|00003980| 2c 20 2d 2d 6c 61 73 74 | 29 3b 0a 7d 0a 0a 74 65 |, --last|);.}..te|
|00003990| 6d 70 6c 61 74 65 20 3c | 63 6c 61 73 73 20 42 69 |mplate <|class Bi|
|000039a0| 64 69 72 65 63 74 69 6f | 6e 61 6c 49 74 65 72 61 |directio|nalItera|
|000039b0| 74 6f 72 3e 0a 69 6e 6c | 69 6e 65 20 76 6f 69 64 |tor>.inl|ine void|
|000039c0| 20 72 65 76 65 72 73 65 | 28 42 69 64 69 72 65 63 | reverse|(Bidirec|
|000039d0| 74 69 6f 6e 61 6c 49 74 | 65 72 61 74 6f 72 20 66 |tionalIt|erator f|
|000039e0| 69 72 73 74 2c 20 42 69 | 64 69 72 65 63 74 69 6f |irst, Bi|directio|
|000039f0| 6e 61 6c 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |nalItera|tor last|
|00003a00| 29 20 7b 0a 20 20 20 20 | 5f 5f 72 65 76 65 72 73 |) {. |__revers|
|00003a10| 65 28 66 69 72 73 74 2c | 20 6c 61 73 74 2c 20 69 |e(first,| last, i|
|00003a20| 74 65 72 61 74 6f 72 5f | 63 61 74 65 67 6f 72 79 |terator_|category|
|00003a30| 28 66 69 72 73 74 29 29 | 3b 0a 7d 0a 0a 74 65 6d |(first))|;.}..tem|
|00003a40| 70 6c 61 74 65 20 3c 63 | 6c 61 73 73 20 42 69 64 |plate <c|lass Bid|
|00003a50| 69 72 65 63 74 69 6f 6e | 61 6c 49 74 65 72 61 74 |irection|alIterat|
|00003a60| 6f 72 2c 20 63 6c 61 73 | 73 20 4f 75 74 70 75 74 |or, clas|s Output|
|00003a70| 49 74 65 72 61 74 6f 72 | 3e 0a 4f 75 74 70 75 74 |Iterator|>.Output|
|00003a80| 49 74 65 72 61 74 6f 72 | 20 72 65 76 65 72 73 65 |Iterator| reverse|
|00003a90| 5f 63 6f 70 79 28 42 69 | 64 69 72 65 63 74 69 6f |_copy(Bi|directio|
|00003aa0| 6e 61 6c 49 74 65 72 61 | 74 6f 72 20 66 69 72 73 |nalItera|tor firs|
|00003ab0| 74 2c 0a 09 09 09 20 20 | 20 20 42 69 64 69 72 65 |t,.... | Bidire|
|00003ac0| 63 74 69 6f 6e 61 6c 49 | 74 65 72 61 74 6f 72 20 |ctionalI|terator |
|00003ad0| 6c 61 73 74 2c 0a 09 09 | 09 20 20 20 20 4f 75 74 |last,...|. Out|
|00003ae0| 70 75 74 49 74 65 72 61 | 74 6f 72 20 72 65 73 75 |putItera|tor resu|
|00003af0| 6c 74 29 20 7b 0a 20 20 | 20 20 77 68 69 6c 65 20 |lt) {. | while |
|00003b00| 28 66 69 72 73 74 20 21 | 3d 20 6c 61 73 74 29 20 |(first !|= last) |
|00003b10| 2a 72 65 73 75 6c 74 2b | 2b 20 3d 20 2a 2d 2d 6c |*result+|+ = *--l|
|00003b20| 61 73 74 3b 0a 20 20 20 | 20 72 65 74 75 72 6e 20 |ast;. | return |
|00003b30| 72 65 73 75 6c 74 3b 0a | 7d 0a 0a 74 65 6d 70 6c |result;.|}..templ|
|00003b40| 61 74 65 20 3c 63 6c 61 | 73 73 20 46 6f 72 77 61 |ate <cla|ss Forwa|
|00003b50| 72 64 49 74 65 72 61 74 | 6f 72 2c 20 63 6c 61 73 |rdIterat|or, clas|
|00003b60| 73 20 44 69 73 74 61 6e | 63 65 3e 0a 76 6f 69 64 |s Distan|ce>.void|
|00003b70| 20 5f 5f 72 6f 74 61 74 | 65 28 46 6f 72 77 61 72 | __rotat|e(Forwar|
|00003b80| 64 49 74 65 72 61 74 6f | 72 20 66 69 72 73 74 2c |dIterato|r first,|
|00003b90| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|00003ba0| 20 6d 69 64 64 6c 65 2c | 0a 09 20 20 20 20 20 20 | middle,|.. |
|00003bb0| 46 6f 72 77 61 72 64 49 | 74 65 72 61 74 6f 72 20 |ForwardI|terator |
|00003bc0| 6c 61 73 74 2c 20 44 69 | 73 74 61 6e 63 65 2a 2c |last, Di|stance*,|
|00003bd0| 20 66 6f 72 77 61 72 64 | 5f 69 74 65 72 61 74 6f | forward|_iterato|
|00003be0| 72 5f 74 61 67 29 20 7b | 0a 20 20 20 20 66 6f 72 |r_tag) {|. for|
|00003bf0| 20 28 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f | (Forwar|dIterato|
|00003c00| 72 20 69 20 3d 20 6d 69 | 64 64 6c 65 3b 20 3b 29 |r i = mi|ddle; ;)|
|00003c10| 20 7b 0a 09 69 74 65 72 | 5f 73 77 61 70 28 66 69 | {..iter|_swap(fi|
|00003c20| 72 73 74 2b 2b 2c 20 69 | 2b 2b 29 3b 0a 09 69 66 |rst++, i|++);..if|
|00003c30| 20 28 66 69 72 73 74 20 | 3d 3d 20 6d 69 64 64 6c | (first |== middl|
|00003c40| 65 29 20 7b 0a 09 20 20 | 20 20 69 66 20 28 69 20 |e) {.. | if (i |
|00003c50| 3d 3d 20 6c 61 73 74 29 | 20 72 65 74 75 72 6e 3b |== last)| return;|
|00003c60| 0a 09 20 20 20 20 6d 69 | 64 64 6c 65 20 3d 20 69 |.. mi|ddle = i|
|00003c70| 3b 0a 09 7d 20 65 6c 73 | 65 20 69 66 20 28 69 20 |;..} els|e if (i |
|00003c80| 3d 3d 20 6c 61 73 74 29 | 0a 09 20 20 20 20 69 20 |== last)|.. i |
|00003c90| 3d 20 6d 69 64 64 6c 65 | 3b 0a 20 20 20 20 7d 0a |= middle|;. }.|
|00003ca0| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00003cb0| 73 73 20 42 69 64 69 72 | 65 63 74 69 6f 6e 61 6c |ss Bidir|ectional|
|00003cc0| 49 74 65 72 61 74 6f 72 | 2c 20 63 6c 61 73 73 20 |Iterator|, class |
|00003cd0| 44 69 73 74 61 6e 63 65 | 3e 0a 76 6f 69 64 20 5f |Distance|>.void _|
|00003ce0| 5f 72 6f 74 61 74 65 28 | 42 69 64 69 72 65 63 74 |_rotate(|Bidirect|
|00003cf0| 69 6f 6e 61 6c 49 74 65 | 72 61 74 6f 72 20 66 69 |ionalIte|rator fi|
|00003d00| 72 73 74 2c 20 42 69 64 | 69 72 65 63 74 69 6f 6e |rst, Bid|irection|
|00003d10| 61 6c 49 74 65 72 61 74 | 6f 72 20 6d 69 64 64 6c |alIterat|or middl|
|00003d20| 65 2c 0a 09 20 20 20 20 | 20 20 42 69 64 69 72 65 |e,.. | Bidire|
|00003d30| 63 74 69 6f 6e 61 6c 49 | 74 65 72 61 74 6f 72 20 |ctionalI|terator |
|00003d40| 6c 61 73 74 2c 20 44 69 | 73 74 61 6e 63 65 2a 2c |last, Di|stance*,|
|00003d50| 0a 09 20 20 20 20 20 20 | 62 69 64 69 72 65 63 74 |.. |bidirect|
|00003d60| 69 6f 6e 61 6c 5f 69 74 | 65 72 61 74 6f 72 5f 74 |ional_it|erator_t|
|00003d70| 61 67 29 20 7b 0a 20 20 | 20 20 72 65 76 65 72 73 |ag) {. | revers|
|00003d80| 65 28 66 69 72 73 74 2c | 20 6d 69 64 64 6c 65 29 |e(first,| middle)|
|00003d90| 3b 0a 20 20 20 20 72 65 | 76 65 72 73 65 28 6d 69 |;. re|verse(mi|
|00003da0| 64 64 6c 65 2c 20 6c 61 | 73 74 29 3b 0a 20 20 20 |ddle, la|st);. |
|00003db0| 20 72 65 76 65 72 73 65 | 28 66 69 72 73 74 2c 20 | reverse|(first, |
|00003dc0| 6c 61 73 74 29 3b 0a 7d | 0a 0a 74 65 6d 70 6c 61 |last);.}|..templa|
|00003dd0| 74 65 20 3c 63 6c 61 73 | 73 20 45 75 63 6c 69 64 |te <clas|s Euclid|
|00003de0| 65 61 6e 52 69 6e 67 45 | 6c 65 6d 65 6e 74 3e 0a |eanRingE|lement>.|
|00003df0| 45 75 63 6c 69 64 65 61 | 6e 52 69 6e 67 45 6c 65 |Euclidea|nRingEle|
|00003e00| 6d 65 6e 74 20 5f 5f 67 | 63 64 28 45 75 63 6c 69 |ment __g|cd(Eucli|
|00003e10| 64 65 61 6e 52 69 6e 67 | 45 6c 65 6d 65 6e 74 20 |deanRing|Element |
|00003e20| 6d 2c 20 45 75 63 6c 69 | 64 65 61 6e 52 69 6e 67 |m, Eucli|deanRing|
|00003e30| 45 6c 65 6d 65 6e 74 20 | 6e 29 0a 7b 0a 20 20 20 |Element |n).{. |
|00003e40| 20 77 68 69 6c 65 20 28 | 6e 20 21 3d 20 30 29 20 | while (|n != 0) |
|00003e50| 7b 0a 09 45 75 63 6c 69 | 64 65 61 6e 52 69 6e 67 |{..Eucli|deanRing|
|00003e60| 45 6c 65 6d 65 6e 74 20 | 74 20 3d 20 6d 20 25 20 |Element |t = m % |
|00003e70| 6e 3b 0a 09 6d 20 3d 20 | 6e 3b 0a 09 6e 20 3d 20 |n;..m = |n;..n = |
|00003e80| 74 3b 0a 20 20 20 20 7d | 0a 20 20 20 20 72 65 74 |t;. }|. ret|
|00003e90| 75 72 6e 20 6d 3b 0a 7d | 0a 0a 74 65 6d 70 6c 61 |urn m;.}|..templa|
|00003ea0| 74 65 20 3c 63 6c 61 73 | 73 20 52 61 6e 64 6f 6d |te <clas|s Random|
|00003eb0| 41 63 63 65 73 73 49 74 | 65 72 61 74 6f 72 2c 20 |AccessIt|erator, |
|00003ec0| 63 6c 61 73 73 20 44 69 | 73 74 61 6e 63 65 2c 20 |class Di|stance, |
|00003ed0| 63 6c 61 73 73 20 54 3e | 0a 76 6f 69 64 20 5f 5f |class T>|.void __|
|00003ee0| 72 6f 74 61 74 65 5f 63 | 79 63 6c 65 28 52 61 6e |rotate_c|ycle(Ran|
|00003ef0| 64 6f 6d 41 63 63 65 73 | 73 49 74 65 72 61 74 6f |domAcces|sIterato|
|00003f00| 72 20 66 69 72 73 74 2c | 20 52 61 6e 64 6f 6d 41 |r first,| RandomA|
|00003f10| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 20 6c 61 |ccessIte|rator la|
|00003f20| 73 74 2c 0a 09 09 20 20 | 20 20 52 61 6e 64 6f 6d |st,... | Random|
|00003f30| 41 63 63 65 73 73 49 74 | 65 72 61 74 6f 72 20 69 |AccessIt|erator i|
|00003f40| 6e 69 74 69 61 6c 2c 20 | 44 69 73 74 61 6e 63 65 |nitial, |Distance|
|00003f50| 20 73 68 69 66 74 2c 20 | 54 2a 29 20 7b 0a 20 20 | shift, |T*) {. |
|00003f60| 20 20 54 20 76 61 6c 75 | 65 20 3d 20 2a 69 6e 69 | T valu|e = *ini|
|00003f70| 74 69 61 6c 3b 0a 20 20 | 20 20 52 61 6e 64 6f 6d |tial;. | Random|
|00003f80| 41 63 63 65 73 73 49 74 | 65 72 61 74 6f 72 20 70 |AccessIt|erator p|
|00003f90| 74 72 31 20 3d 20 69 6e | 69 74 69 61 6c 3b 0a 20 |tr1 = in|itial;. |
|00003fa0| 20 20 20 52 61 6e 64 6f | 6d 41 63 63 65 73 73 49 | Rando|mAccessI|
|00003fb0| 74 65 72 61 74 6f 72 20 | 70 74 72 32 20 3d 20 70 |terator |ptr2 = p|
|00003fc0| 74 72 31 20 2b 20 73 68 | 69 66 74 3b 0a 20 20 20 |tr1 + sh|ift;. |
|00003fd0| 20 77 68 69 6c 65 20 28 | 70 74 72 32 20 21 3d 20 | while (|ptr2 != |
|00003fe0| 69 6e 69 74 69 61 6c 29 | 20 7b 0a 09 2a 70 74 72 |initial)| {..*ptr|
|00003ff0| 31 20 3d 20 2a 70 74 72 | 32 3b 0a 09 70 74 72 31 |1 = *ptr|2;..ptr1|
|00004000| 20 3d 20 70 74 72 32 3b | 0a 09 69 66 20 28 6c 61 | = ptr2;|..if (la|
|00004010| 73 74 20 2d 20 70 74 72 | 32 20 3e 20 73 68 69 66 |st - ptr|2 > shif|
|00004020| 74 29 0a 09 20 20 20 20 | 70 74 72 32 20 2b 3d 20 |t).. |ptr2 += |
|00004030| 73 68 69 66 74 3b 0a 09 | 65 6c 73 65 0a 09 20 20 |shift;..|else.. |
|00004040| 20 20 70 74 72 32 20 3d | 20 66 69 72 73 74 20 2b | ptr2 =| first +|
|00004050| 20 28 73 68 69 66 74 20 | 2d 20 28 6c 61 73 74 20 | (shift |- (last |
|00004060| 2d 20 70 74 72 32 29 29 | 3b 0a 20 20 20 20 7d 0a |- ptr2))|;. }.|
|00004070| 20 20 20 20 2a 70 74 72 | 31 20 3d 20 76 61 6c 75 | *ptr|1 = valu|
|00004080| 65 3b 0a 7d 0a 0a 74 65 | 6d 70 6c 61 74 65 20 3c |e;.}..te|mplate <|
|00004090| 63 6c 61 73 73 20 52 61 | 6e 64 6f 6d 41 63 63 65 |class Ra|ndomAcce|
|000040a0| 73 73 49 74 65 72 61 74 | 6f 72 2c 20 63 6c 61 73 |ssIterat|or, clas|
|000040b0| 73 20 44 69 73 74 61 6e | 63 65 3e 0a 76 6f 69 64 |s Distan|ce>.void|
|000040c0| 20 5f 5f 72 6f 74 61 74 | 65 28 52 61 6e 64 6f 6d | __rotat|e(Random|
|000040d0| 41 63 63 65 73 73 49 74 | 65 72 61 74 6f 72 20 66 |AccessIt|erator f|
|000040e0| 69 72 73 74 2c 20 52 61 | 6e 64 6f 6d 41 63 63 65 |irst, Ra|ndomAcce|
|000040f0| 73 73 49 74 65 72 61 74 | 6f 72 20 6d 69 64 64 6c |ssIterat|or middl|
|00004100| 65 2c 0a 09 20 20 20 20 | 20 20 52 61 6e 64 6f 6d |e,.. | Random|
|00004110| 41 63 63 65 73 73 49 74 | 65 72 61 74 6f 72 20 6c |AccessIt|erator l|
|00004120| 61 73 74 2c 20 44 69 73 | 74 61 6e 63 65 2a 2c 0a |ast, Dis|tance*,.|
|00004130| 09 20 20 20 20 20 20 72 | 61 6e 64 6f 6d 5f 61 63 |. r|andom_ac|
|00004140| 63 65 73 73 5f 69 74 65 | 72 61 74 6f 72 5f 74 61 |cess_ite|rator_ta|
|00004150| 67 29 20 7b 0a 20 20 20 | 20 44 69 73 74 61 6e 63 |g) {. | Distanc|
|00004160| 65 20 6e 20 3d 20 5f 5f | 67 63 64 28 6c 61 73 74 |e n = __|gcd(last|
|00004170| 20 2d 20 66 69 72 73 74 | 2c 20 6d 69 64 64 6c 65 | - first|, middle|
|00004180| 20 2d 20 66 69 72 73 74 | 29 3b 0a 20 20 20 20 77 | - first|);. w|
|00004190| 68 69 6c 65 20 28 6e 2d | 2d 29 0a 09 5f 5f 72 6f |hile (n-|-)..__ro|
|000041a0| 74 61 74 65 5f 63 79 63 | 6c 65 28 66 69 72 73 74 |tate_cyc|le(first|
|000041b0| 2c 20 6c 61 73 74 2c 20 | 66 69 72 73 74 20 2b 20 |, last, |first + |
|000041c0| 6e 2c 20 6d 69 64 64 6c | 65 20 2d 20 66 69 72 73 |n, middl|e - firs|
|000041d0| 74 2c 0a 09 09 20 20 20 | 20 20 20 20 76 61 6c 75 |t,... | valu|
|000041e0| 65 5f 74 79 70 65 28 66 | 69 72 73 74 29 29 3b 0a |e_type(f|irst));.|
|000041f0| 7d 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 |}..templ|ate <cla|
|00004200| 73 73 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |ss Forwa|rdIterat|
|00004210| 6f 72 3e 0a 69 6e 6c 69 | 6e 65 20 76 6f 69 64 20 |or>.inli|ne void |
|00004220| 72 6f 74 61 74 65 28 46 | 6f 72 77 61 72 64 49 74 |rotate(F|orwardIt|
|00004230| 65 72 61 74 6f 72 20 66 | 69 72 73 74 2c 20 46 6f |erator f|irst, Fo|
|00004240| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 20 6d 69 |rwardIte|rator mi|
|00004250| 64 64 6c 65 2c 0a 09 09 | 20 20 20 46 6f 72 77 61 |ddle,...| Forwa|
|00004260| 72 64 49 74 65 72 61 74 | 6f 72 20 6c 61 73 74 29 |rdIterat|or last)|
|00004270| 20 7b 0a 20 20 20 20 69 | 66 20 28 66 69 72 73 74 | {. i|f (first|
|00004280| 20 3d 3d 20 6d 69 64 64 | 6c 65 20 7c 7c 20 6d 69 | == midd|le || mi|
|00004290| 64 64 6c 65 20 3d 3d 20 | 6c 61 73 74 29 20 72 65 |ddle == |last) re|
|000042a0| 74 75 72 6e 3b 0a 20 20 | 20 20 5f 5f 72 6f 74 61 |turn;. | __rota|
|000042b0| 74 65 28 66 69 72 73 74 | 2c 20 6d 69 64 64 6c 65 |te(first|, middle|
|000042c0| 2c 20 6c 61 73 74 2c 20 | 64 69 73 74 61 6e 63 65 |, last, |distance|
|000042d0| 5f 74 79 70 65 28 66 69 | 72 73 74 29 2c 0a 09 20 |_type(fi|rst),.. |
|000042e0| 20 20 20 20 69 74 65 72 | 61 74 6f 72 5f 63 61 74 | iter|ator_cat|
|000042f0| 65 67 6f 72 79 28 66 69 | 72 73 74 29 29 3b 0a 7d |egory(fi|rst));.}|
|00004300| 0a 0a 74 65 6d 70 6c 61 | 74 65 20 3c 63 6c 61 73 |..templa|te <clas|
|00004310| 73 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f |s Forwar|dIterato|
|00004320| 72 2c 20 63 6c 61 73 73 | 20 4f 75 74 70 75 74 49 |r, class| OutputI|
|00004330| 74 65 72 61 74 6f 72 3e | 0a 4f 75 74 70 75 74 49 |terator>|.OutputI|
|00004340| 74 65 72 61 74 6f 72 20 | 72 6f 74 61 74 65 5f 63 |terator |rotate_c|
|00004350| 6f 70 79 28 46 6f 72 77 | 61 72 64 49 74 65 72 61 |opy(Forw|ardItera|
|00004360| 74 6f 72 20 66 69 72 73 | 74 2c 20 46 6f 72 77 61 |tor firs|t, Forwa|
|00004370| 72 64 49 74 65 72 61 74 | 6f 72 20 6d 69 64 64 6c |rdIterat|or middl|
|00004380| 65 2c 0a 09 09 09 20 20 | 20 46 6f 72 77 61 72 64 |e,.... | Forward|
|00004390| 49 74 65 72 61 74 6f 72 | 20 6c 61 73 74 2c 20 4f |Iterator| last, O|
|000043a0| 75 74 70 75 74 49 74 65 | 72 61 74 6f 72 20 72 65 |utputIte|rator re|
|000043b0| 73 75 6c 74 29 20 7b 0a | 20 20 20 20 72 65 74 75 |sult) {.| retu|
|000043c0| 72 6e 20 63 6f 70 79 28 | 66 69 72 73 74 2c 20 6d |rn copy(|first, m|
|000043d0| 69 64 64 6c 65 2c 20 63 | 6f 70 79 28 6d 69 64 64 |iddle, c|opy(midd|
|000043e0| 6c 65 2c 20 6c 61 73 74 | 2c 20 72 65 73 75 6c 74 |le, last|, result|
|000043f0| 29 29 3b 0a 7d 0a 0a 74 | 65 6d 70 6c 61 74 65 20 |));.}..t|emplate |
|00004400| 3c 63 6c 61 73 73 20 52 | 61 6e 64 6f 6d 41 63 63 |<class R|andomAcc|
|00004410| 65 73 73 49 74 65 72 61 | 74 6f 72 2c 20 63 6c 61 |essItera|tor, cla|
|00004420| 73 73 20 44 69 73 74 61 | 6e 63 65 3e 0a 76 6f 69 |ss Dista|nce>.voi|
|00004430| 64 20 5f 5f 72 61 6e 64 | 6f 6d 5f 73 68 75 66 66 |d __rand|om_shuff|
|00004440| 6c 65 28 52 61 6e 64 6f | 6d 41 63 63 65 73 73 49 |le(Rando|mAccessI|
|00004450| 74 65 72 61 74 6f 72 20 | 66 69 72 73 74 2c 20 52 |terator |first, R|
|00004460| 61 6e 64 6f 6d 41 63 63 | 65 73 73 49 74 65 72 61 |andomAcc|essItera|
|00004470| 74 6f 72 20 6c 61 73 74 | 2c 0a 09 09 20 20 20 20 |tor last|,... |
|00004480| 20 20 44 69 73 74 61 6e | 63 65 2a 29 20 7b 0a 20 | Distan|ce*) {. |
|00004490| 20 20 20 69 66 20 28 66 | 69 72 73 74 20 3d 3d 20 | if (f|irst == |
|000044a0| 6c 61 73 74 29 20 72 65 | 74 75 72 6e 3b 0a 20 20 |last) re|turn;. |
|000044b0| 20 20 66 6f 72 20 28 52 | 61 6e 64 6f 6d 41 63 63 | for (R|andomAcc|
|000044c0| 65 73 73 49 74 65 72 61 | 74 6f 72 20 69 20 3d 20 |essItera|tor i = |
|000044d0| 66 69 72 73 74 20 2b 20 | 31 3b 20 69 20 21 3d 20 |first + |1; i != |
|000044e0| 6c 61 73 74 3b 20 2b 2b | 69 29 20 0a 20 20 20 20 |last; ++|i) . |
|000044f0| 20 20 69 74 65 72 5f 73 | 77 61 70 28 69 2c 0a 23 | iter_s|wap(i,.#|
|00004500| 69 66 64 65 66 20 5f 5f | 53 54 4c 5f 4e 4f 5f 44 |ifdef __|STL_NO_D|
|00004510| 52 41 4e 44 34 38 0a 20 | 20 20 20 20 20 20 20 20 |RAND48. | |
|00004520| 20 20 20 20 20 20 20 66 | 69 72 73 74 20 2b 20 44 | f|irst + D|
|00004530| 69 73 74 61 6e 63 65 28 | 72 61 6e 64 28 29 20 25 |istance(|rand() %|
|00004540| 20 28 28 69 20 2d 20 66 | 69 72 73 74 29 20 2b 20 | ((i - f|irst) + |
|00004550| 31 29 29 29 3b 0a 23 65 | 6c 73 65 0a 20 20 20 20 |1)));.#e|lse. |
|00004560| 20 20 20 20 20 20 20 20 | 20 20 20 20 66 69 72 73 | | firs|
|00004570| 74 20 2b 20 44 69 73 74 | 61 6e 63 65 28 6c 72 61 |t + Dist|ance(lra|
|00004580| 6e 64 34 38 28 29 20 25 | 20 28 28 69 20 2d 20 66 |nd48() %| ((i - f|
|00004590| 69 72 73 74 29 20 2b 20 | 31 29 29 29 3b 0a 23 65 |irst) + |1)));.#e|
|000045a0| 6e 64 69 66 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |ndif.}..|template|
|000045b0| 20 3c 63 6c 61 73 73 20 | 52 61 6e 64 6f 6d 41 63 | <class |RandomAc|
|000045c0| 63 65 73 73 49 74 65 72 | 61 74 6f 72 3e 0a 69 6e |cessIter|ator>.in|
|000045d0| 6c 69 6e 65 20 76 6f 69 | 64 20 72 61 6e 64 6f 6d |line voi|d random|
|000045e0| 5f 73 68 75 66 66 6c 65 | 28 52 61 6e 64 6f 6d 41 |_shuffle|(RandomA|
|000045f0| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 20 66 69 |ccessIte|rator fi|
|00004600| 72 73 74 2c 0a 09 09 09 | 20 20 20 52 61 6e 64 6f |rst,....| Rando|
|00004610| 6d 41 63 63 65 73 73 49 | 74 65 72 61 74 6f 72 20 |mAccessI|terator |
|00004620| 6c 61 73 74 29 20 7b 0a | 20 20 20 20 5f 5f 72 61 |last) {.| __ra|
|00004630| 6e 64 6f 6d 5f 73 68 75 | 66 66 6c 65 28 66 69 72 |ndom_shu|ffle(fir|
|00004640| 73 74 2c 20 6c 61 73 74 | 2c 20 64 69 73 74 61 6e |st, last|, distan|
|00004650| 63 65 5f 74 79 70 65 28 | 66 69 72 73 74 29 29 3b |ce_type(|first));|
|00004660| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00004670| 61 73 73 20 52 61 6e 64 | 6f 6d 41 63 63 65 73 73 |ass Rand|omAccess|
|00004680| 49 74 65 72 61 74 6f 72 | 2c 20 63 6c 61 73 73 20 |Iterator|, class |
|00004690| 52 61 6e 64 6f 6d 4e 75 | 6d 62 65 72 47 65 6e 65 |RandomNu|mberGene|
|000046a0| 72 61 74 6f 72 3e 0a 76 | 6f 69 64 20 72 61 6e 64 |rator>.v|oid rand|
|000046b0| 6f 6d 5f 73 68 75 66 66 | 6c 65 28 52 61 6e 64 6f |om_shuff|le(Rando|
|000046c0| 6d 41 63 63 65 73 73 49 | 74 65 72 61 74 6f 72 20 |mAccessI|terator |
|000046d0| 66 69 72 73 74 2c 20 52 | 61 6e 64 6f 6d 41 63 63 |first, R|andomAcc|
|000046e0| 65 73 73 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |essItera|tor last|
|000046f0| 2c 0a 09 09 20 20 20 20 | 52 61 6e 64 6f 6d 4e 75 |,... |RandomNu|
|00004700| 6d 62 65 72 47 65 6e 65 | 72 61 74 6f 72 26 20 72 |mberGene|rator& r|
|00004710| 61 6e 64 29 20 7b 0a 20 | 20 20 20 69 66 20 28 66 |and) {. | if (f|
|00004720| 69 72 73 74 20 3d 3d 20 | 6c 61 73 74 29 20 72 65 |irst == |last) re|
|00004730| 74 75 72 6e 3b 0a 20 20 | 20 20 66 6f 72 20 28 52 |turn;. | for (R|
|00004740| 61 6e 64 6f 6d 41 63 63 | 65 73 73 49 74 65 72 61 |andomAcc|essItera|
|00004750| 74 6f 72 20 69 20 3d 20 | 66 69 72 73 74 20 2b 20 |tor i = |first + |
|00004760| 31 3b 20 69 20 21 3d 20 | 6c 61 73 74 3b 20 2b 2b |1; i != |last; ++|
|00004770| 69 29 0a 09 69 74 65 72 | 5f 73 77 61 70 28 69 2c |i)..iter|_swap(i,|
|00004780| 20 66 69 72 73 74 20 2b | 20 72 61 6e 64 28 28 69 | first +| rand((i|
|00004790| 20 2d 20 66 69 72 73 74 | 29 20 2b 20 31 29 29 3b | - first|) + 1));|
|000047a0| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|000047b0| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|000047c0| 74 6f 72 2c 20 63 6c 61 | 73 73 20 4f 75 74 70 75 |tor, cla|ss Outpu|
|000047d0| 74 49 74 65 72 61 74 6f | 72 2c 20 63 6c 61 73 73 |tIterato|r, class|
|000047e0| 20 44 69 73 74 61 6e 63 | 65 3e 0a 4f 75 74 70 75 | Distanc|e>.Outpu|
|000047f0| 74 49 74 65 72 61 74 6f | 72 20 72 61 6e 64 6f 6d |tIterato|r random|
|00004800| 5f 73 61 6d 70 6c 65 5f | 6e 28 46 6f 72 77 61 72 |_sample_|n(Forwar|
|00004810| 64 49 74 65 72 61 74 6f | 72 20 66 69 72 73 74 2c |dIterato|r first,|
|00004820| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|00004830| 20 6c 61 73 74 2c 0a 20 | 20 20 20 20 20 20 20 20 | last,. | |
|00004840| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004850| 20 20 20 20 20 20 4f 75 | 74 70 75 74 49 74 65 72 | Ou|tputIter|
|00004860| 61 74 6f 72 20 6f 75 74 | 2c 20 63 6f 6e 73 74 20 |ator out|, const |
|00004870| 44 69 73 74 61 6e 63 65 | 20 6e 29 0a 7b 0a 20 20 |Distance| n).{. |
|00004880| 44 69 73 74 61 6e 63 65 | 20 72 65 6d 61 69 6e 69 |Distance| remaini|
|00004890| 6e 67 20 3d 20 30 3b 0a | 20 20 64 69 73 74 61 6e |ng = 0;.| distan|
|000048a0| 63 65 28 66 69 72 73 74 | 2c 20 6c 61 73 74 2c 20 |ce(first|, last, |
|000048b0| 72 65 6d 61 69 6e 69 6e | 67 29 3b 0a 20 20 44 69 |remainin|g);. Di|
|000048c0| 73 74 61 6e 63 65 20 6d | 20 3d 20 6d 69 6e 28 6e |stance m| = min(n|
|000048d0| 2c 20 72 65 6d 61 69 6e | 69 6e 67 29 3b 0a 0a 20 |, remain|ing);.. |
|000048e0| 20 77 68 69 6c 65 20 28 | 6d 20 3e 20 30 29 20 7b | while (|m > 0) {|
|000048f0| 0a 23 69 66 64 65 66 20 | 5f 5f 53 54 4c 5f 4e 4f |.#ifdef |__STL_NO|
|00004900| 5f 44 52 41 4e 44 34 38 | 0a 20 20 20 20 69 66 20 |_DRAND48|. if |
|00004910| 28 72 61 6e 64 28 29 20 | 25 20 72 65 6d 61 69 6e |(rand() |% remain|
|00004920| 69 6e 67 20 3c 20 6d 29 | 20 7b 0a 23 65 6c 73 65 |ing < m)| {.#else|
|00004930| 0a 20 20 20 20 69 66 20 | 28 6c 72 61 6e 64 34 38 |. if |(lrand48|
|00004940| 28 29 20 25 20 72 65 6d | 61 69 6e 69 6e 67 20 3c |() % rem|aining <|
|00004950| 20 6d 29 20 7b 0a 23 65 | 6e 64 69 66 0a 20 20 20 | m) {.#e|ndif. |
|00004960| 20 20 20 2a 6f 75 74 2b | 2b 20 3d 20 2a 66 69 72 | *out+|+ = *fir|
|00004970| 73 74 3b 0a 20 20 20 20 | 20 20 2d 2d 6d 3b 0a 20 |st;. | --m;. |
|00004980| 20 20 20 7d 0a 0a 20 20 | 20 20 2d 2d 72 65 6d 61 | }.. | --rema|
|00004990| 69 6e 69 6e 67 3b 0a 20 | 20 20 20 2b 2b 66 69 72 |ining;. | ++fir|
|000049a0| 73 74 3b 0a 20 20 7d 0a | 20 20 72 65 74 75 72 6e |st;. }.| return|
|000049b0| 20 6f 75 74 3b 0a 7d 0a | 0a 74 65 6d 70 6c 61 74 | out;.}.|.templat|
|000049c0| 65 20 3c 63 6c 61 73 73 | 20 46 6f 72 77 61 72 64 |e <class| Forward|
|000049d0| 49 74 65 72 61 74 6f 72 | 2c 20 63 6c 61 73 73 20 |Iterator|, class |
|000049e0| 4f 75 74 70 75 74 49 74 | 65 72 61 74 6f 72 2c 20 |OutputIt|erator, |
|000049f0| 63 6c 61 73 73 20 44 69 | 73 74 61 6e 63 65 2c 0a |class Di|stance,.|
|00004a00| 20 20 20 20 20 20 20 20 | 20 20 63 6c 61 73 73 20 | | class |
|00004a10| 52 61 6e 64 6f 6d 4e 75 | 6d 62 65 72 47 65 6e 65 |RandomNu|mberGene|
|00004a20| 72 61 74 6f 72 3e 0a 4f | 75 74 70 75 74 49 74 65 |rator>.O|utputIte|
|00004a30| 72 61 74 6f 72 20 72 61 | 6e 64 6f 6d 5f 73 61 6d |rator ra|ndom_sam|
|00004a40| 70 6c 65 5f 6e 28 46 6f | 72 77 61 72 64 49 74 65 |ple_n(Fo|rwardIte|
|00004a50| 72 61 74 6f 72 20 66 69 | 72 73 74 2c 20 46 6f 72 |rator fi|rst, For|
|00004a60| 77 61 72 64 49 74 65 72 | 61 74 6f 72 20 6c 61 73 |wardIter|ator las|
|00004a70| 74 2c 0a 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |t,. | |
|00004a80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004a90| 20 20 4f 75 74 70 75 74 | 49 74 65 72 61 74 6f 72 | Output|Iterator|
|00004aa0| 20 6f 75 74 2c 20 63 6f | 6e 73 74 20 44 69 73 74 | out, co|nst Dist|
|00004ab0| 61 6e 63 65 20 6e 2c 0a | 20 20 20 20 20 20 20 20 |ance n,.| |
|00004ac0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004ad0| 20 20 20 20 20 20 20 52 | 61 6e 64 6f 6d 4e 75 6d | R|andomNum|
|00004ae0| 62 65 72 47 65 6e 65 72 | 61 74 6f 72 26 20 72 61 |berGener|ator& ra|
|00004af0| 6e 64 29 0a 7b 0a 20 20 | 44 69 73 74 61 6e 63 65 |nd).{. |Distance|
|00004b00| 20 72 65 6d 61 69 6e 69 | 6e 67 20 3d 20 30 3b 0a | remaini|ng = 0;.|
|00004b10| 20 20 64 69 73 74 61 6e | 63 65 28 66 69 72 73 74 | distan|ce(first|
|00004b20| 2c 20 6c 61 73 74 2c 20 | 72 65 6d 61 69 6e 69 6e |, last, |remainin|
|00004b30| 67 29 3b 0a 20 20 44 69 | 73 74 61 6e 63 65 20 6d |g);. Di|stance m|
|00004b40| 20 3d 20 6d 69 6e 28 6e | 2c 20 72 65 6d 61 69 6e | = min(n|, remain|
|00004b50| 69 6e 67 29 3b 0a 0a 20 | 20 77 68 69 6c 65 20 28 |ing);.. | while (|
|00004b60| 6d 20 3e 20 30 29 20 7b | 0a 20 20 20 20 69 66 20 |m > 0) {|. if |
|00004b70| 28 72 61 6e 64 28 72 65 | 6d 61 69 6e 69 6e 67 29 |(rand(re|maining)|
|00004b80| 20 3c 20 6d 29 20 7b 0a | 20 20 20 20 20 20 2a 6f | < m) {.| *o|
|00004b90| 75 74 2b 2b 20 3d 20 2a | 66 69 72 73 74 3b 0a 20 |ut++ = *|first;. |
|00004ba0| 20 20 20 20 20 2d 2d 6d | 3b 0a 20 20 20 20 7d 0a | --m|;. }.|
|00004bb0| 0a 20 20 20 20 2d 2d 72 | 65 6d 61 69 6e 69 6e 67 |. --r|emaining|
|00004bc0| 3b 0a 20 20 20 20 2b 2b | 66 69 72 73 74 3b 0a 20 |;. ++|first;. |
|00004bd0| 20 7d 0a 20 20 72 65 74 | 75 72 6e 20 6f 75 74 3b | }. ret|urn out;|
|00004be0| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00004bf0| 61 73 73 20 49 6e 70 75 | 74 49 74 65 72 61 74 6f |ass Inpu|tIterato|
|00004c00| 72 2c 20 63 6c 61 73 73 | 20 52 61 6e 64 6f 6d 41 |r, class| RandomA|
|00004c10| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 2c 20 63 |ccessIte|rator, c|
|00004c20| 6c 61 73 73 20 44 69 73 | 74 61 6e 63 65 3e 0a 52 |lass Dis|tance>.R|
|00004c30| 61 6e 64 6f 6d 41 63 63 | 65 73 73 49 74 65 72 61 |andomAcc|essItera|
|00004c40| 74 6f 72 20 5f 5f 72 61 | 6e 64 6f 6d 5f 73 61 6d |tor __ra|ndom_sam|
|00004c50| 70 6c 65 28 49 6e 70 75 | 74 49 74 65 72 61 74 6f |ple(Inpu|tIterato|
|00004c60| 72 20 66 69 72 73 74 2c | 20 49 6e 70 75 74 49 74 |r first,| InputIt|
|00004c70| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 0a 20 20 20 |erator l|ast,. |
|00004c80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004c90| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004ca0| 20 20 52 61 6e 64 6f 6d | 41 63 63 65 73 73 49 74 | Random|AccessIt|
|00004cb0| 65 72 61 74 6f 72 20 6f | 75 74 2c 0a 20 20 20 20 |erator o|ut,. |
|00004cc0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004cd0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004ce0| 20 63 6f 6e 73 74 20 44 | 69 73 74 61 6e 63 65 20 | const D|istance |
|00004cf0| 6e 29 0a 7b 0a 20 20 44 | 69 73 74 61 6e 63 65 20 |n).{. D|istance |
|00004d00| 6d 20 3d 20 30 3b 0a 20 | 20 44 69 73 74 61 6e 63 |m = 0;. | Distanc|
|00004d10| 65 20 74 20 3d 20 6e 3b | 0a 20 20 77 68 69 6c 65 |e t = n;|. while|
|00004d20| 20 28 66 69 72 73 74 20 | 21 3d 20 6c 61 73 74 20 | (first |!= last |
|00004d30| 26 26 20 6d 20 3c 20 6e | 29 20 0a 20 20 20 20 6f |&& m < n|) . o|
|00004d40| 75 74 5b 6d 2b 2b 5d 20 | 3d 20 2a 66 69 72 73 74 |ut[m++] |= *first|
|00004d50| 2b 2b 3b 0a 0a 20 20 77 | 68 69 6c 65 20 28 66 69 |++;.. w|hile (fi|
|00004d60| 72 73 74 20 21 3d 20 6c | 61 73 74 29 20 7b 0a 20 |rst != l|ast) {. |
|00004d70| 20 20 20 2b 2b 74 3b 0a | 23 69 66 64 65 66 20 5f | ++t;.|#ifdef _|
|00004d80| 5f 53 54 4c 5f 4e 4f 5f | 44 52 41 4e 44 34 38 0a |_STL_NO_|DRAND48.|
|00004d90| 20 20 20 20 44 69 73 74 | 61 6e 63 65 20 4d 20 3d | Dist|ance M =|
|00004da0| 20 72 61 6e 64 28 29 20 | 25 20 74 3b 0a 23 65 6c | rand() |% t;.#el|
|00004db0| 73 65 0a 20 20 20 20 44 | 69 73 74 61 6e 63 65 20 |se. D|istance |
|00004dc0| 4d 20 3d 20 6c 72 61 6e | 64 34 38 28 29 20 25 20 |M = lran|d48() % |
|00004dd0| 74 3b 0a 23 65 6e 64 69 | 66 0a 20 20 20 20 69 66 |t;.#endi|f. if|
|00004de0| 20 28 4d 20 3c 20 6e 29 | 0a 20 20 20 20 20 20 6f | (M < n)|. o|
|00004df0| 75 74 5b 4d 5d 20 3d 20 | 2a 66 69 72 73 74 3b 0a |ut[M] = |*first;.|
|00004e00| 20 20 20 20 2b 2b 66 69 | 72 73 74 3b 0a 20 20 7d | ++fi|rst;. }|
|00004e10| 0a 0a 20 20 72 65 74 75 | 72 6e 20 6f 75 74 20 2b |.. retu|rn out +|
|00004e20| 20 6d 3b 0a 7d 0a 0a 74 | 65 6d 70 6c 61 74 65 20 | m;.}..t|emplate |
|00004e30| 3c 63 6c 61 73 73 20 49 | 6e 70 75 74 49 74 65 72 |<class I|nputIter|
|00004e40| 61 74 6f 72 2c 20 63 6c | 61 73 73 20 52 61 6e 64 |ator, cl|ass Rand|
|00004e50| 6f 6d 41 63 63 65 73 73 | 49 74 65 72 61 74 6f 72 |omAccess|Iterator|
|00004e60| 2c 0a 20 20 20 20 20 20 | 20 20 20 20 63 6c 61 73 |,. | clas|
|00004e70| 73 20 52 61 6e 64 6f 6d | 4e 75 6d 62 65 72 47 65 |s Random|NumberGe|
|00004e80| 6e 65 72 61 74 6f 72 2c | 20 63 6c 61 73 73 20 44 |nerator,| class D|
|00004e90| 69 73 74 61 6e 63 65 3e | 0a 52 61 6e 64 6f 6d 41 |istance>|.RandomA|
|00004ea0| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 20 5f 5f |ccessIte|rator __|
|00004eb0| 72 61 6e 64 6f 6d 5f 73 | 61 6d 70 6c 65 28 49 6e |random_s|ample(In|
|00004ec0| 70 75 74 49 74 65 72 61 | 74 6f 72 20 66 69 72 73 |putItera|tor firs|
|00004ed0| 74 2c 20 49 6e 70 75 74 | 49 74 65 72 61 74 6f 72 |t, Input|Iterator|
|00004ee0| 20 6c 61 73 74 2c 0a 20 | 20 20 20 20 20 20 20 20 | last,. | |
|00004ef0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004f00| 20 20 20 20 20 20 20 20 | 20 20 20 20 52 61 6e 64 | | Rand|
|00004f10| 6f 6d 41 63 63 65 73 73 | 49 74 65 72 61 74 6f 72 |omAccess|Iterator|
|00004f20| 20 6f 75 74 2c 0a 20 20 | 20 20 20 20 20 20 20 20 | out,. | |
|00004f30| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004f40| 20 20 20 20 20 20 20 20 | 20 20 20 52 61 6e 64 6f | | Rando|
|00004f50| 6d 4e 75 6d 62 65 72 47 | 65 6e 65 72 61 74 6f 72 |mNumberG|enerator|
|00004f60| 26 20 72 61 6e 64 2c 0a | 20 20 20 20 20 20 20 20 |& rand,.| |
|00004f70| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004f80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 63 6f 6e | | con|
|00004f90| 73 74 20 44 69 73 74 61 | 6e 63 65 20 6e 29 0a 7b |st Dista|nce n).{|
|00004fa0| 0a 20 20 44 69 73 74 61 | 6e 63 65 20 6d 20 3d 20 |. Dista|nce m = |
|00004fb0| 30 3b 0a 20 20 44 69 73 | 74 61 6e 63 65 20 74 20 |0;. Dis|tance t |
|00004fc0| 3d 20 6e 3b 0a 20 20 77 | 68 69 6c 65 20 28 66 69 |= n;. w|hile (fi|
|00004fd0| 72 73 74 20 21 3d 20 6c | 61 73 74 20 26 26 20 6d |rst != l|ast && m|
|00004fe0| 20 3c 20 6e 29 20 0a 20 | 20 20 20 6f 75 74 5b 6d | < n) . | out[m|
|00004ff0| 2b 2b 5d 20 3d 20 2a 66 | 69 72 73 74 2b 2b 3b 0a |++] = *f|irst++;.|
|00005000| 0a 20 20 77 68 69 6c 65 | 20 28 66 69 72 73 74 20 |. while| (first |
|00005010| 21 3d 20 6c 61 73 74 29 | 20 7b 0a 20 20 20 20 2b |!= last)| {. +|
|00005020| 2b 74 3b 0a 20 20 20 20 | 44 69 73 74 61 6e 63 65 |+t;. |Distance|
|00005030| 20 4d 20 3d 20 72 61 6e | 64 28 74 29 3b 0a 20 20 | M = ran|d(t);. |
|00005040| 20 20 69 66 20 28 4d 20 | 3c 20 6e 29 0a 20 20 20 | if (M |< n). |
|00005050| 20 20 20 6f 75 74 5b 4d | 5d 20 3d 20 2a 66 69 72 | out[M|] = *fir|
|00005060| 73 74 3b 0a 20 20 20 20 | 2b 2b 66 69 72 73 74 3b |st;. |++first;|
|00005070| 0a 20 20 7d 0a 0a 20 20 | 72 65 74 75 72 6e 20 6f |. }.. |return o|
|00005080| 75 74 20 2b 20 6d 3b 0a | 7d 0a 0a 74 65 6d 70 6c |ut + m;.|}..templ|
|00005090| 61 74 65 20 3c 63 6c 61 | 73 73 20 49 6e 70 75 74 |ate <cla|ss Input|
|000050a0| 49 74 65 72 61 74 6f 72 | 2c 20 63 6c 61 73 73 20 |Iterator|, class |
|000050b0| 52 61 6e 64 6f 6d 41 63 | 63 65 73 73 49 74 65 72 |RandomAc|cessIter|
|000050c0| 61 74 6f 72 3e 0a 69 6e | 6c 69 6e 65 20 52 61 6e |ator>.in|line Ran|
|000050d0| 64 6f 6d 41 63 63 65 73 | 73 49 74 65 72 61 74 6f |domAcces|sIterato|
|000050e0| 72 0a 72 61 6e 64 6f 6d | 5f 73 61 6d 70 6c 65 28 |r.random|_sample(|
|000050f0| 49 6e 70 75 74 49 74 65 | 72 61 74 6f 72 20 66 69 |InputIte|rator fi|
|00005100| 72 73 74 2c 20 49 6e 70 | 75 74 49 74 65 72 61 74 |rst, Inp|utIterat|
|00005110| 6f 72 20 6c 61 73 74 2c | 0a 20 20 20 20 20 20 20 |or last,|. |
|00005120| 20 20 20 20 20 20 20 52 | 61 6e 64 6f 6d 41 63 63 | R|andomAcc|
|00005130| 65 73 73 49 74 65 72 61 | 74 6f 72 20 6f 75 74 5f |essItera|tor out_|
|00005140| 66 69 72 73 74 2c 20 52 | 61 6e 64 6f 6d 41 63 63 |first, R|andomAcc|
|00005150| 65 73 73 49 74 65 72 61 | 74 6f 72 20 6f 75 74 5f |essItera|tor out_|
|00005160| 6c 61 73 74 29 20 0a 7b | 0a 20 20 72 65 74 75 72 |last) .{|. retur|
|00005170| 6e 20 5f 5f 72 61 6e 64 | 6f 6d 5f 73 61 6d 70 6c |n __rand|om_sampl|
|00005180| 65 28 66 69 72 73 74 2c | 20 6c 61 73 74 2c 20 6f |e(first,| last, o|
|00005190| 75 74 5f 66 69 72 73 74 | 2c 20 6f 75 74 5f 6c 61 |ut_first|, out_la|
|000051a0| 73 74 20 2d 20 6f 75 74 | 5f 66 69 72 73 74 29 3b |st - out|_first);|
|000051b0| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|000051c0| 61 73 73 20 49 6e 70 75 | 74 49 74 65 72 61 74 6f |ass Inpu|tIterato|
|000051d0| 72 2c 20 63 6c 61 73 73 | 20 52 61 6e 64 6f 6d 41 |r, class| RandomA|
|000051e0| 63 63 65 73 73 49 74 65 | 72 61 74 6f 72 2c 20 0a |ccessIte|rator, .|
|000051f0| 20 20 20 20 20 20 20 20 | 20 20 63 6c 61 73 73 20 | | class |
|00005200| 52 61 6e 64 6f 6d 4e 75 | 6d 62 65 72 47 65 6e 65 |RandomNu|mberGene|
|00005210| 72 61 74 6f 72 3e 0a 69 | 6e 6c 69 6e 65 20 52 61 |rator>.i|nline Ra|
|00005220| 6e 64 6f 6d 41 63 63 65 | 73 73 49 74 65 72 61 74 |ndomAcce|ssIterat|
|00005230| 6f 72 0a 72 61 6e 64 6f | 6d 5f 73 61 6d 70 6c 65 |or.rando|m_sample|
|00005240| 28 49 6e 70 75 74 49 74 | 65 72 61 74 6f 72 20 66 |(InputIt|erator f|
|00005250| 69 72 73 74 2c 20 49 6e | 70 75 74 49 74 65 72 61 |irst, In|putItera|
|00005260| 74 6f 72 20 6c 61 73 74 | 2c 0a 20 20 20 20 20 20 |tor last|,. |
|00005270| 20 20 20 20 20 20 20 20 | 52 61 6e 64 6f 6d 41 63 | |RandomAc|
|00005280| 63 65 73 73 49 74 65 72 | 61 74 6f 72 20 6f 75 74 |cessIter|ator out|
|00005290| 5f 66 69 72 73 74 2c 20 | 52 61 6e 64 6f 6d 41 63 |_first, |RandomAc|
|000052a0| 63 65 73 73 49 74 65 72 | 61 74 6f 72 20 6f 75 74 |cessIter|ator out|
|000052b0| 5f 6c 61 73 74 2c 0a 20 | 20 20 20 20 20 20 20 20 |_last,. | |
|000052c0| 20 20 20 20 20 52 61 6e | 64 6f 6d 4e 75 6d 62 65 | Ran|domNumbe|
|000052d0| 72 47 65 6e 65 72 61 74 | 6f 72 26 20 72 61 6e 64 |rGenerat|or& rand|
|000052e0| 29 20 0a 7b 0a 20 20 72 | 65 74 75 72 6e 20 5f 5f |) .{. r|eturn __|
|000052f0| 72 61 6e 64 6f 6d 5f 73 | 61 6d 70 6c 65 28 66 69 |random_s|ample(fi|
|00005300| 72 73 74 2c 20 6c 61 73 | 74 2c 20 6f 75 74 5f 66 |rst, las|t, out_f|
|00005310| 69 72 73 74 2c 20 72 61 | 6e 64 2c 20 6f 75 74 5f |irst, ra|nd, out_|
|00005320| 6c 61 73 74 20 2d 20 6f | 75 74 5f 66 69 72 73 74 |last - o|ut_first|
|00005330| 29 3b 0a 7d 0a 0a 0a 0a | 74 65 6d 70 6c 61 74 65 |);.}....|template|
|00005340| 20 3c 63 6c 61 73 73 20 | 42 69 64 69 72 65 63 74 | <class |Bidirect|
|00005350| 69 6f 6e 61 6c 49 74 65 | 72 61 74 6f 72 2c 20 63 |ionalIte|rator, c|
|00005360| 6c 61 73 73 20 50 72 65 | 64 69 63 61 74 65 3e 0a |lass Pre|dicate>.|
|00005370| 42 69 64 69 72 65 63 74 | 69 6f 6e 61 6c 49 74 65 |Bidirect|ionalIte|
|00005380| 72 61 74 6f 72 20 70 61 | 72 74 69 74 69 6f 6e 28 |rator pa|rtition(|
|00005390| 42 69 64 69 72 65 63 74 | 69 6f 6e 61 6c 49 74 65 |Bidirect|ionalIte|
|000053a0| 72 61 74 6f 72 20 66 69 | 72 73 74 2c 0a 09 09 09 |rator fi|rst,....|
|000053b0| 09 42 69 64 69 72 65 63 | 74 69 6f 6e 61 6c 49 74 |.Bidirec|tionalIt|
|000053c0| 65 72 61 74 6f 72 20 6c | 61 73 74 2c 20 50 72 65 |erator l|ast, Pre|
|000053d0| 64 69 63 61 74 65 20 70 | 72 65 64 29 20 7b 0a 20 |dicate p|red) {. |
|000053e0| 20 20 20 77 68 69 6c 65 | 20 28 74 72 75 65 29 20 | while| (true) |
|000053f0| 7b 0a 09 77 68 69 6c 65 | 20 28 74 72 75 65 29 0a |{..while| (true).|
|00005400| 09 20 20 20 20 69 66 20 | 28 66 69 72 73 74 20 3d |. if |(first =|
|00005410| 3d 20 6c 61 73 74 29 0a | 09 09 72 65 74 75 72 6e |= last).|..return|
|00005420| 20 66 69 72 73 74 3b 0a | 09 20 20 20 20 65 6c 73 | first;.|. els|
|00005430| 65 20 69 66 20 28 70 72 | 65 64 28 2a 66 69 72 73 |e if (pr|ed(*firs|
|00005440| 74 29 29 0a 09 09 2b 2b | 66 69 72 73 74 3b 0a 09 |t))...++|first;..|
|00005450| 20 20 20 20 65 6c 73 65 | 0a 09 09 62 72 65 61 6b | else|...break|
|00005460| 3b 0a 09 2d 2d 6c 61 73 | 74 3b 0a 09 77 68 69 6c |;..--las|t;..whil|
|00005470| 65 20 28 74 72 75 65 29 | 0a 09 20 20 20 20 69 66 |e (true)|.. if|
|00005480| 20 28 66 69 72 73 74 20 | 3d 3d 20 6c 61 73 74 29 | (first |== last)|
|00005490| 0a 09 09 72 65 74 75 72 | 6e 20 66 69 72 73 74 3b |...retur|n first;|
|000054a0| 0a 09 20 20 20 20 65 6c | 73 65 20 69 66 20 28 21 |.. el|se if (!|
|000054b0| 70 72 65 64 28 2a 6c 61 | 73 74 29 29 0a 09 09 2d |pred(*la|st))...-|
|000054c0| 2d 6c 61 73 74 3b 0a 09 | 20 20 20 20 65 6c 73 65 |-last;..| else|
|000054d0| 0a 09 09 62 72 65 61 6b | 3b 0a 09 69 74 65 72 5f |...break|;..iter_|
|000054e0| 73 77 61 70 28 66 69 72 | 73 74 2c 20 6c 61 73 74 |swap(fir|st, last|
|000054f0| 29 3b 0a 09 2b 2b 66 69 | 72 73 74 3b 0a 20 20 20 |);..++fi|rst;. |
|00005500| 20 7d 0a 7d 0a 0a 74 65 | 6d 70 6c 61 74 65 20 3c | }.}..te|mplate <|
|00005510| 63 6c 61 73 73 20 46 6f | 72 77 61 72 64 49 74 65 |class Fo|rwardIte|
|00005520| 72 61 74 6f 72 2c 20 63 | 6c 61 73 73 20 50 72 65 |rator, c|lass Pre|
|00005530| 64 69 63 61 74 65 2c 20 | 63 6c 61 73 73 20 44 69 |dicate, |class Di|
|00005540| 73 74 61 6e 63 65 3e 0a | 46 6f 72 77 61 72 64 49 |stance>.|ForwardI|
|00005550| 74 65 72 61 74 6f 72 20 | 5f 5f 69 6e 70 6c 61 63 |terator |__inplac|
|00005560| 65 5f 73 74 61 62 6c 65 | 5f 70 61 72 74 69 74 69 |e_stable|_partiti|
|00005570| 6f 6e 28 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 |on(Forwa|rdIterat|
|00005580| 6f 72 20 66 69 72 73 74 | 2c 0a 09 09 09 09 09 20 |or first|,...... |
|00005590| 20 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f | Forwar|dIterato|
|000055a0| 72 20 6c 61 73 74 2c 0a | 09 09 09 09 09 20 20 20 |r last,.|..... |
|000055b0| 50 72 65 64 69 63 61 74 | 65 20 70 72 65 64 2c 20 |Predicat|e pred, |
|000055c0| 44 69 73 74 61 6e 63 65 | 20 6c 65 6e 29 20 7b 0a |Distance| len) {.|
|000055d0| 20 20 20 20 69 66 20 28 | 6c 65 6e 20 3d 3d 20 31 | if (|len == 1|
|000055e0| 29 20 72 65 74 75 72 6e | 20 70 72 65 64 28 2a 66 |) return| pred(*f|
|000055f0| 69 72 73 74 29 20 3f 20 | 6c 61 73 74 20 3a 20 66 |irst) ? |last : f|
|00005600| 69 72 73 74 3b 0a 20 20 | 20 20 46 6f 72 77 61 72 |irst;. | Forwar|
|00005610| 64 49 74 65 72 61 74 6f | 72 20 6d 69 64 64 6c 65 |dIterato|r middle|
|00005620| 20 3d 20 66 69 72 73 74 | 3b 0a 20 20 20 20 61 64 | = first|;. ad|
|00005630| 76 61 6e 63 65 28 6d 69 | 64 64 6c 65 2c 20 6c 65 |vance(mi|ddle, le|
|00005640| 6e 20 2f 20 32 29 3b 0a | 20 20 20 20 46 6f 72 77 |n / 2);.| Forw|
|00005650| 61 72 64 49 74 65 72 61 | 74 6f 72 20 0a 09 66 69 |ardItera|tor ..fi|
|00005660| 72 73 74 5f 63 75 74 20 | 3d 20 5f 5f 69 6e 70 6c |rst_cut |= __inpl|
|00005670| 61 63 65 5f 73 74 61 62 | 6c 65 5f 70 61 72 74 69 |ace_stab|le_parti|
|00005680| 74 69 6f 6e 28 66 69 72 | 73 74 2c 20 6d 69 64 64 |tion(fir|st, midd|
|00005690| 6c 65 2c 20 70 72 65 64 | 2c 20 6c 65 6e 20 2f 20 |le, pred|, len / |
|000056a0| 32 29 3b 0a 20 20 20 20 | 46 6f 72 77 61 72 64 49 |2);. |ForwardI|
|000056b0| 74 65 72 61 74 6f 72 20 | 0a 09 73 65 63 6f 6e 64 |terator |..second|
|000056c0| 5f 63 75 74 20 3d 20 5f | 5f 69 6e 70 6c 61 63 65 |_cut = _|_inplace|
|000056d0| 5f 73 74 61 62 6c 65 5f | 70 61 72 74 69 74 69 6f |_stable_|partitio|
|000056e0| 6e 28 6d 69 64 64 6c 65 | 2c 20 6c 61 73 74 2c 20 |n(middle|, last, |
|000056f0| 70 72 65 64 2c 0a 09 09 | 09 09 09 09 6c 65 6e 20 |pred,...|....len |
|00005700| 2d 20 6c 65 6e 20 2f 20 | 32 29 3b 0a 20 20 20 20 |- len / |2);. |
|00005710| 72 6f 74 61 74 65 28 66 | 69 72 73 74 5f 63 75 74 |rotate(f|irst_cut|
|00005720| 2c 20 6d 69 64 64 6c 65 | 2c 20 73 65 63 6f 6e 64 |, middle|, second|
|00005730| 5f 63 75 74 29 3b 0a 20 | 20 20 20 6c 65 6e 20 3d |_cut);. | len =|
|00005740| 20 30 3b 0a 20 20 20 20 | 64 69 73 74 61 6e 63 65 | 0;. |distance|
|00005750| 28 6d 69 64 64 6c 65 2c | 20 73 65 63 6f 6e 64 5f |(middle,| second_|
|00005760| 63 75 74 2c 20 6c 65 6e | 29 3b 0a 20 20 20 20 61 |cut, len|);. a|
|00005770| 64 76 61 6e 63 65 28 66 | 69 72 73 74 5f 63 75 74 |dvance(f|irst_cut|
|00005780| 2c 20 6c 65 6e 29 3b 0a | 20 20 20 20 72 65 74 75 |, len);.| retu|
|00005790| 72 6e 20 66 69 72 73 74 | 5f 63 75 74 3b 0a 7d 0a |rn first|_cut;.}.|
|000057a0| 0a 74 65 6d 70 6c 61 74 | 65 20 3c 63 6c 61 73 73 |.templat|e <class|
|000057b0| 20 46 6f 72 77 61 72 64 | 49 74 65 72 61 74 6f 72 | Forward|Iterator|
|000057c0| 2c 20 63 6c 61 73 73 20 | 50 6f 69 6e 74 65 72 2c |, class |Pointer,|
|000057d0| 20 63 6c 61 73 73 20 50 | 72 65 64 69 63 61 74 65 | class P|redicate|
|000057e0| 2c 0a 09 20 20 63 6c 61 | 73 73 20 44 69 73 74 61 |,.. cla|ss Dista|
|000057f0| 6e 63 65 2c 20 63 6c 61 | 73 73 20 54 3e 0a 46 6f |nce, cla|ss T>.Fo|
|00005800| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 20 5f 5f |rwardIte|rator __|
|00005810| 73 74 61 62 6c 65 5f 70 | 61 72 74 69 74 69 6f 6e |stable_p|artition|
|00005820| 5f 61 64 61 70 74 69 76 | 65 28 46 6f 72 77 61 72 |_adaptiv|e(Forwar|
|00005830| 64 49 74 65 72 61 74 6f | 72 20 66 69 72 73 74 2c |dIterato|r first,|
|00005840| 0a 09 09 09 09 09 20 20 | 20 20 46 6f 72 77 61 72 |...... | Forwar|
|00005850| 64 49 74 65 72 61 74 6f | 72 20 6c 61 73 74 2c 0a |dIterato|r last,.|
|00005860| 09 09 09 09 09 20 20 20 | 20 50 72 65 64 69 63 61 |..... | Predica|
|00005870| 74 65 20 70 72 65 64 2c | 20 44 69 73 74 61 6e 63 |te pred,| Distanc|
|00005880| 65 20 6c 65 6e 2c 0a 09 | 09 09 09 09 20 20 20 20 |e len,..|.... |
|00005890| 50 6f 69 6e 74 65 72 20 | 62 75 66 66 65 72 2c 0a |Pointer |buffer,.|
|000058a0| 09 09 09 09 09 20 20 20 | 20 44 69 73 74 61 6e 63 |..... | Distanc|
|000058b0| 65 20 62 75 66 66 65 72 | 5f 73 69 7a 65 2c 0a 09 |e buffer|_size,..|
|000058c0| 09 09 09 09 20 20 20 20 | 44 69 73 74 61 6e 63 65 |.... |Distance|
|000058d0| 26 20 66 69 6c 6c 5f 70 | 6f 69 6e 74 65 72 2c 20 |& fill_p|ointer, |
|000058e0| 54 2a 29 20 7b 0a 20 20 | 20 20 69 66 20 28 6c 65 |T*) {. | if (le|
|000058f0| 6e 20 3c 3d 20 62 75 66 | 66 65 72 5f 73 69 7a 65 |n <= buf|fer_size|
|00005900| 29 20 7b 0a 09 6c 65 6e | 20 3d 20 30 3b 0a 09 46 |) {..len| = 0;..F|
|00005910| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 20 72 |orwardIt|erator r|
|00005920| 65 73 75 6c 74 31 20 3d | 20 66 69 72 73 74 3b 0a |esult1 =| first;.|
|00005930| 09 50 6f 69 6e 74 65 72 | 20 72 65 73 75 6c 74 32 |.Pointer| result2|
|00005940| 20 3d 20 62 75 66 66 65 | 72 3b 0a 09 77 68 69 6c | = buffe|r;..whil|
|00005950| 65 20 28 66 69 72 73 74 | 20 21 3d 20 6c 61 73 74 |e (first| != last|
|00005960| 20 26 26 20 6c 65 6e 20 | 3c 20 66 69 6c 6c 5f 70 | && len |< fill_p|
|00005970| 6f 69 6e 74 65 72 29 0a | 09 20 20 20 20 69 66 20 |ointer).|. if |
|00005980| 28 70 72 65 64 28 2a 66 | 69 72 73 74 29 29 0a 09 |(pred(*f|irst))..|
|00005990| 09 2a 72 65 73 75 6c 74 | 31 2b 2b 20 3d 20 2a 66 |.*result|1++ = *f|
|000059a0| 69 72 73 74 2b 2b 3b 0a | 09 20 20 20 20 65 6c 73 |irst++;.|. els|
|000059b0| 65 20 7b 0a 09 09 2a 72 | 65 73 75 6c 74 32 2b 2b |e {...*r|esult2++|
|000059c0| 20 3d 20 2a 66 69 72 73 | 74 2b 2b 3b 0a 09 09 2b | = *firs|t++;...+|
|000059d0| 2b 6c 65 6e 3b 0a 09 20 | 20 20 20 7d 0a 09 69 66 |+len;.. | }..if|
|000059e0| 20 28 66 69 72 73 74 20 | 21 3d 20 6c 61 73 74 29 | (first |!= last)|
|000059f0| 20 7b 0a 09 20 20 20 20 | 72 61 77 5f 73 74 6f 72 | {.. |raw_stor|
|00005a00| 61 67 65 5f 69 74 65 72 | 61 74 6f 72 3c 50 6f 69 |age_iter|ator<Poi|
|00005a10| 6e 74 65 72 2c 20 54 3e | 20 72 65 73 75 6c 74 33 |nter, T>| result3|
|00005a20| 20 3d 20 72 65 73 75 6c | 74 32 3b 0a 09 20 20 20 | = resul|t2;.. |
|00005a30| 20 77 68 69 6c 65 20 28 | 66 69 72 73 74 20 21 3d | while (|first !=|
|00005a40| 20 6c 61 73 74 29 20 20 | 20 20 20 20 20 20 20 20 | last) | |
|00005a50| 20 0a 09 09 69 66 20 28 | 70 72 65 64 28 2a 66 69 | ...if (|pred(*fi|
|00005a60| 72 73 74 29 29 0a 09 09 | 20 20 20 20 2a 72 65 73 |rst))...| *res|
|00005a70| 75 6c 74 31 2b 2b 20 3d | 20 2a 66 69 72 73 74 2b |ult1++ =| *first+|
|00005a80| 2b 3b 0a 09 09 65 6c 73 | 65 20 7b 0a 09 09 20 20 |+;...els|e {... |
|00005a90| 20 20 2a 72 65 73 75 6c | 74 33 2b 2b 20 3d 20 2a | *resul|t3++ = *|
|00005aa0| 66 69 72 73 74 2b 2b 3b | 0a 09 09 20 20 20 20 2b |first++;|... +|
|00005ab0| 2b 6c 65 6e 3b 0a 09 09 | 7d 0a 09 20 20 20 20 66 |+len;...|}.. f|
|00005ac0| 69 6c 6c 5f 70 6f 69 6e | 74 65 72 20 3d 20 6c 65 |ill_poin|ter = le|
|00005ad0| 6e 3b 0a 09 7d 0a 09 63 | 6f 70 79 28 62 75 66 66 |n;..}..c|opy(buff|
|00005ae0| 65 72 2c 20 62 75 66 66 | 65 72 20 2b 20 6c 65 6e |er, buff|er + len|
|00005af0| 2c 20 72 65 73 75 6c 74 | 31 29 3b 0a 09 72 65 74 |, result|1);..ret|
|00005b00| 75 72 6e 20 72 65 73 75 | 6c 74 31 3b 0a 20 20 20 |urn resu|lt1;. |
|00005b10| 20 7d 0a 20 20 20 20 46 | 6f 72 77 61 72 64 49 74 | }. F|orwardIt|
|00005b20| 65 72 61 74 6f 72 20 6d | 69 64 64 6c 65 20 3d 20 |erator m|iddle = |
|00005b30| 66 69 72 73 74 3b 0a 20 | 20 20 20 61 64 76 61 6e |first;. | advan|
|00005b40| 63 65 28 6d 69 64 64 6c | 65 2c 20 6c 65 6e 20 2f |ce(middl|e, len /|
|00005b50| 20 32 29 3b 0a 20 20 20 | 20 46 6f 72 77 61 72 64 | 2);. | Forward|
|00005b60| 49 74 65 72 61 74 6f 72 | 20 66 69 72 73 74 5f 63 |Iterator| first_c|
|00005b70| 75 74 20 3d 20 5f 5f 73 | 74 61 62 6c 65 5f 70 61 |ut = __s|table_pa|
|00005b80| 72 74 69 74 69 6f 6e 5f | 61 64 61 70 74 69 76 65 |rtition_|adaptive|
|00005b90| 0a 09 28 66 69 72 73 74 | 2c 20 6d 69 64 64 6c 65 |..(first|, middle|
|00005ba0| 2c 20 70 72 65 64 2c 20 | 6c 65 6e 20 2f 20 32 2c |, pred, |len / 2,|
|00005bb0| 20 62 75 66 66 65 72 2c | 20 62 75 66 66 65 72 5f | buffer,| buffer_|
|00005bc0| 73 69 7a 65 2c 20 66 69 | 6c 6c 5f 70 6f 69 6e 74 |size, fi|ll_point|
|00005bd0| 65 72 2c 20 0a 09 20 28 | 54 2a 29 30 29 3b 0a 20 |er, .. (|T*)0);. |
|00005be0| 20 20 20 46 6f 72 77 61 | 72 64 49 74 65 72 61 74 | Forwa|rdIterat|
|00005bf0| 6f 72 20 73 65 63 6f 6e | 64 5f 63 75 74 20 3d 20 |or secon|d_cut = |
|00005c00| 5f 5f 73 74 61 62 6c 65 | 5f 70 61 72 74 69 74 69 |__stable|_partiti|
|00005c10| 6f 6e 5f 61 64 61 70 74 | 69 76 65 0a 09 28 6d 69 |on_adapt|ive..(mi|
|00005c20| 64 64 6c 65 2c 20 6c 61 | 73 74 2c 20 70 72 65 64 |ddle, la|st, pred|
|00005c30| 2c 20 6c 65 6e 20 2d 20 | 6c 65 6e 20 2f 20 32 2c |, len - |len / 2,|
|00005c40| 20 62 75 66 66 65 72 2c | 20 62 75 66 66 65 72 5f | buffer,| buffer_|
|00005c50| 73 69 7a 65 2c 20 0a 09 | 20 66 69 6c 6c 5f 70 6f |size, ..| fill_po|
|00005c60| 69 6e 74 65 72 2c 20 28 | 54 2a 29 30 29 3b 0a 20 |inter, (|T*)0);. |
|00005c70| 20 20 20 72 6f 74 61 74 | 65 28 66 69 72 73 74 5f | rotat|e(first_|
|00005c80| 63 75 74 2c 20 6d 69 64 | 64 6c 65 2c 20 73 65 63 |cut, mid|dle, sec|
|00005c90| 6f 6e 64 5f 63 75 74 29 | 3b 0a 20 20 20 20 6c 65 |ond_cut)|;. le|
|00005ca0| 6e 20 3d 20 30 3b 0a 20 | 20 20 20 64 69 73 74 61 |n = 0;. | dista|
|00005cb0| 6e 63 65 28 6d 69 64 64 | 6c 65 2c 20 73 65 63 6f |nce(midd|le, seco|
|00005cc0| 6e 64 5f 63 75 74 2c 20 | 6c 65 6e 29 3b 0a 20 20 |nd_cut, |len);. |
|00005cd0| 20 20 61 64 76 61 6e 63 | 65 28 66 69 72 73 74 5f | advanc|e(first_|
|00005ce0| 63 75 74 2c 20 6c 65 6e | 29 3b 0a 20 20 20 20 72 |cut, len|);. r|
|00005cf0| 65 74 75 72 6e 20 66 69 | 72 73 74 5f 63 75 74 3b |eturn fi|rst_cut;|
|00005d00| 0a 7d 0a 0a 74 65 6d 70 | 6c 61 74 65 20 3c 63 6c |.}..temp|late <cl|
|00005d10| 61 73 73 20 46 6f 72 77 | 61 72 64 49 74 65 72 61 |ass Forw|ardItera|
|00005d20| 74 6f 72 2c 20 63 6c 61 | 73 73 20 50 72 65 64 69 |tor, cla|ss Predi|
|00005d30| 63 61 74 65 2c 20 63 6c | 61 73 73 20 50 6f 69 6e |cate, cl|ass Poin|
|00005d40| 74 65 72 2c 0a 09 20 20 | 63 6c 61 73 73 20 44 69 |ter,.. |class Di|
|00005d50| 73 74 61 6e 63 65 3e 0a | 46 6f 72 77 61 72 64 49 |stance>.|ForwardI|
|00005d60| 74 65 72 61 74 6f 72 20 | 5f 5f 73 74 61 62 6c 65 |terator |__stable|
|00005d70| 5f 70 61 72 74 69 74 69 | 6f 6e 28 46 6f 72 77 61 |_partiti|on(Forwa|
|00005d80| 72 64 49 74 65 72 61 74 | 6f 72 20 66 69 72 73 74 |rdIterat|or first|
|00005d90| 2c 20 46 6f 72 77 61 72 | 64 49 74 65 72 61 74 6f |, Forwar|dIterato|
|00005da0| 72 20 6c 61 73 74 2c 0a | 09 09 09 09 20 20 20 50 |r last,.|.... P|
|00005db0| 72 65 64 69 63 61 74 65 | 20 70 72 65 64 2c 20 44 |redicate| pred, D|
|00005dc0| 69 73 74 61 6e 63 65 20 | 6c 65 6e 2c 0a 09 09 09 |istance |len,....|
|00005dd0| 09 20 20 20 70 61 69 72 | 3c 50 6f 69 6e 74 65 72 |. pair|<Pointer|
|00005de0| 2c 20 44 69 73 74 61 6e | 63 65 3e 20 70 29 20 7b |, Distan|ce> p) {|
|00005df0| 0a 20 20 20 20 69 66 20 | 28 70 2e 66 69 72 73 74 |. if |(p.first|
|00005e00| 20 3d 3d 20 30 29 0a 09 | 72 65 74 75 72 6e 20 5f | == 0)..|return _|
|00005e10| 5f 69 6e 70 6c 61 63 65 | 5f 73 74 61 62 6c 65 5f |_inplace|_stable_|
|00005e20| 70 61 72 74 69 74 69 6f | 6e 28 66 69 72 73 74 2c |partitio|n(first,|
|00005e30| 20 6c 61 73 74 2c 20 70 | 72 65 64 2c 20 6c 65 6e | last, p|red, len|
|00005e40| 29 3b 0a 20 20 20 20 44 | 69 73 74 61 6e 63 65 20 |);. D|istance |
|00005e50| 66 69 6c 6c 5f 70 6f 69 | 6e 74 65 72 20 3d 20 30 |fill_poi|nter = 0|
|00005e60| 3b 0a 20 20 20 20 46 6f | 72 77 61 72 64 49 74 65 |;. Fo|rwardIte|
|00005e70| 72 61 74 6f 72 20 72 65 | 73 75 6c 74 20 3d 20 0a |rator re|sult = .|
|00005e80| 09 5f 5f 73 74 61 62 6c | 65 5f 70 61 72 74 69 74 |.__stabl|e_partit|
|00005e90| 69 6f 6e 5f 61 64 61 70 | 74 69 76 65 28 66 69 72 |ion_adap|tive(fir|
|00005ea0| 73 74 2c 20 6c 61 73 74 | 2c 20 70 72 65 64 2c 20 |st, last|, pred, |
|00005eb0| 6c 65 6e 2c 20 70 2e 66 | 69 72 73 74 2c 20 70 2e |len, p.f|irst, p.|
|00005ec0| 73 65 63 6f 6e 64 2c 0a | 09 09 09 09 20 20 20 20 |second,.|.... |
|00005ed0| 66 69 6c 6c 5f 70 6f 69 | 6e 74 65 72 2c 20 76 61 |fill_poi|nter, va|
|00005ee0| 6c 75 65 5f 74 79 70 65 | 28 66 69 72 73 74 29 29 |lue_type|(first))|
|00005ef0| 3b 20 0a 20 20 20 20 64 | 65 73 74 72 6f 79 28 70 |; . d|estroy(p|
|00005f00| 2e 66 69 72 73 74 2c 20 | 70 2e 66 69 72 73 74 20 |.first, |p.first |
|00005f10| 2b 20 66 69 6c 6c 5f 70 | 6f 69 6e 74 65 72 29 3b |+ fill_p|ointer);|
|00005f20| 0a 20 20 20 20 72 65 74 | 75 72 6e 5f 74 65 6d 70 |. ret|urn_temp|
|00005f30| 6f 72 61 72 79 5f 62 75 | 66 66 65 72 28 70 2e 66 |orary_bu|ffer(p.f|
|00005f40| 69 72 73 74 29 3b 0a 20 | 20 20 20 72 65 74 75 72 |irst);. | retur|
|00005f50| 6e 20 72 65 73 75 6c 74 | 3b 0a 7d 0a 0a 74 65 6d |n result|;.}..tem|
|00005f60| 70 6c 61 74 65 20 3c 63 | 6c 61 73 73 20 46 6f 72 |plate <c|lass For|
|00005f70| 77 61 72 64 49 74 65 72 | 61 74 6f 72 2c 20 63 6c |wardIter|ator, cl|
|00005f80| 61 73 73 20 50 72 65 64 | 69 63 61 74 65 2c 20 63 |ass Pred|icate, c|
|00005f90| 6c 61 73 73 20 44 69 73 | 74 61 6e 63 65 3e 0a 69 |lass Dis|tance>.i|
|00005fa0| 6e 6c 69 6e 65 20 46 6f | 72 77 61 72 64 49 74 65 |nline Fo|rwardIte|
|00005fb0| 72 61 74 6f 72 20 5f 5f | 73 74 61 62 6c 65 5f 70 |rator __|stable_p|
|00005fc0| 61 72 74 69 74 69 6f 6e | 5f 61 75 78 28 46 6f 72 |artition|_aux(For|
|00005fd0| 77 61 72 64 49 74 65 72 | 61 74 6f 72 20 66 69 72 |wardIter|ator fir|
|00005fe0| 73 74 2c 0a 09 09 09 09 | 09 20 20 20 20 20 20 46 |st,.....|. F|
|00005ff0| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 20 6c |orwardIt|erator l|
|00006000| 61 73 74 2c 20 0a 09 09 | 09 09 09 20 20 20 20 20 |ast, ...|... |
|00006010| 20 50 72 65 64 69 63 61 | 74 65 20 70 72 65 64 2c | Predica|te pred,|
|00006020| 20 44 69 73 74 61 6e 63 | 65 2a 29 20 7b 0a 20 20 | Distanc|e*) {. |
|00006030| 20 20 44 69 73 74 61 6e | 63 65 20 6c 65 6e 20 3d | Distan|ce len =|
|00006040| 20 30 3b 0a 20 20 20 20 | 64 69 73 74 61 6e 63 65 | 0;. |distance|
|00006050| 28 66 69 72 73 74 2c 20 | 6c 61 73 74 2c 20 6c 65 |(first, |last, le|
|00006060| 6e 29 3b 0a 20 20 20 20 | 72 65 74 75 72 6e 20 5f |n);. |return _|
|00006070| 5f 73 74 61 62 6c 65 5f | 70 61 72 74 69 74 69 6f |_stable_|partitio|
|00006080| 6e 28 66 69 72 73 74 2c | 20 6c 61 73 74 2c 20 70 |n(first,| last, p|
|00006090| 72 65 64 2c 20 6c 65 6e | 2c 0a 09 09 09 20 20 20 |red, len|,.... |
|000060a0| 20 20 20 67 65 74 5f 74 | 65 6d 70 6f 72 61 72 79 | get_t|emporary|
|000060b0| 5f 62 75 66 66 65 72 28 | 6c 65 6e 2c 20 76 61 6c |_buffer(|len, val|
|000060c0| 75 65 5f 74 79 70 65 28 | 66 69 72 73 74 29 29 29 |ue_type(|first)))|
|000060d0| 3b 0a 7d 0a 0a 74 65 6d | 70 6c 61 74 65 20 3c 63 |;.}..tem|plate <c|
|000060e0| 6c 61 73 73 20 46 6f 72 | 77 61 72 64 49 74 65 72 |lass For|wardIter|
|000060f0| 61 74 6f 72 2c 20 63 6c | 61 73 73 20 50 72 65 64 |ator, cl|ass Pred|
|00006100| 69 63 61 74 65 3e 0a 69 | 6e 6c 69 6e 65 20 46 6f |icate>.i|nline Fo|
|00006110| 72 77 61 72 64 49 74 65 | 72 61 74 6f 72 20 73 74 |rwardIte|rator st|
|00006120| 61 62 6c 65 5f 70 61 72 | 74 69 74 69 6f 6e 28 46 |able_par|tition(F|
|00006130| 6f 72 77 61 72 64 49 74 | 65 72 61 74 6f 72 20 66 |orwardIt|erator f|
|00006140| 69 72 73 74 2c 0a 09 09 | 09 09 09 46 6f 72 77 61 |irst,...|...Forwa|
|00006150| 72 64 49 74 65 72 61 74 | 6f 72 20 6c 61 73 74 2c |rdIterat|or last,|
|00006160| 20 0a 09 09 09 09 09 50 | 72 65 64 69 63 61 74 65 | ......P|redicate|
|00006170| 20 70 72 65 64 29 20 7b | 0a 20 20 20 20 72 65 74 | pred) {|. ret|
|00006180| 75 72 6e 20 5f 5f 73 74 | 61 62 6c 65 5f 70 61 72 |urn __st|able_par|
|00006190| 74 69 74 69 6f 6e 5f 61 | 75 78 28 66 69 72 73 74 |tition_a|ux(first|
|000061a0| 2c 20 6c 61 73 74 2c 20 | 70 72 65 64 2c 20 64 69 |, last, |pred, di|
|000061b0| 73 74 61 6e 63 65 5f 74 | 79 70 65 28 66 69 72 73 |stance_t|ype(firs|
|000061c0| 74 29 29 3b 0a 7d 0a 0a | 74 65 6d 70 6c 61 74 65 |t));.}..|template|
|000061d0| 20 3c 63 6c 61 73 73 20 | 52 61 6e 64 6f 6d 41 63 | <class |RandomAc|
|000061e0| 63 65 73 73 49 74 65 72 | 61 74 6f 72 2c 20 63 6c |cessIter|ator, cl|
|000061f0| 61 73 73 20 54 3e 0a 52 | 61 6e 64 6f 6d 41 63 63 |ass T>.R|andomAcc|
|00006200| 65 73 73 49 74 65 72 61 | 74 6f 72 20 5f 5f 75 6e |essItera|tor __un|
|00006210| 67 75 61 72 64 65 64 5f | 70 61 72 74 69 74 69 6f |guarded_|partitio|
|00006220| 6e 28 52 61 6e 64 6f 6d | 41 63 63 65 73 73 49 74 |n(Random|AccessIt|
|00006230| 65 72 61 74 6f 72 20 66 | 69 72 73 74 2c 20 0a 09 |erator f|irst, ..|
|00006240| 09 09 09 09 20 20 20 52 | 61 6e 64 6f 6d 41 63 63 |.... R|andomAcc|
|00006250| 65 73 73 49 74 65 72 61 | 74 6f 72 20 6c 61 73 74 |essItera|tor last|
|00006260| 2c 20 0a 09 09 09 09 09 | 20 20 20 54 20 70 69 76 |, ......| T piv|
|00006270| 6f 74 29 20 7b 0a 20 20 | 20 20 77 68 69 6c 65 20 |ot) {. | while |
|00006280| 28 31 29 20 7b 0a 09 77 | 68 69 6c 65 20 28 2a 66 |(1) {..w|hile (*f|
|00006290| 69 72 73 74 20 3c 20 70 | 69 76 6f 74 29 20 2b 2b |irst < p|ivot) ++|
|000062a0| 66 69 72 73 74 3b 0a 09 | 2d 2d 6c 61 73 74 3b 0a |first;..|--last;.|
|000062b0| 09 77 68 69 6c 65 20 28 | 70 69 76 6f 74 20 3c 20 |.while (|pivot < |
|000062c0| 2a 6c 61 73 74 29 20 2d | 2d 6c 61 73 74 3b 0a 09 |*last) -|-last;..|
|000062d0| 69 66 20 28 21 28 66 69 | 72 73 74 20 3c 20 6c 61 |if (!(fi|rst < la|
|000062e0| 73 74 29 29 20 72 65 74 | 75 72 6e 20 66 69 72 73 |st)) ret|urn firs|
|000062f0| 74 3b 0a 09 69 74 65 72 | 5f 73 77 61 70 28 66 69 |t;..iter|_swap(fi|
|00006300| 72 73 74 2c 20 6c 61 73 | 74 29 3b 0a 09 2b 2b 66 |rst, las|t);..++f|
|00006310| 69 72 73 74 3b 0a 20 20 | 20 20 7d 0a 7d 20 20 20 |irst;. | }.} |
|00006320| 20 0a 0a 74 65 6d 70 6c | 61 74 65 20 3c 63 6c 61 | ..templ|ate <cla|
|00006330| 73 73 20 52 61 6e 64 6f | 6d 41 63 63 65 73 73 49 |ss Rando|mAccessI|
|00006340| 74 65 72 61 74 6f 72 2c | 20 63 6c 61 73 73 20 54 |terator,| class T|
|00006350| 2c 20 63 6c 61 73 73 20 | 43 6f 6d 70 61 72 65 3e |, class |Compare>|
|00006360| 0a 52 61 6e 64 6f 6d 41 | 63 63 65 73 73 49 74 65 |.RandomA|ccessIte|
|00006370| 72 61 74 6f 72 20 5f 5f | 75 6e 67 75 61 72 64 65 |rator __|unguarde|
|00006380| 64 5f 70 61 72 74 69 74 | 69 6f 6e 28 52 61 6e 64 |d_partit|ion(Rand|
|00006390| 6f 6d 41 63 63 65 73 73 | 49 74 65 72 61 74 6f 72 |omAccess|Iterator|
|000063a0| 20 66 69 72 73 74 2c 20 | 0a 09 09 09 09 09 20 20 | first, |...... |
|000063b0| 20 52 61 6e 64 6f 6d 41 | 63 63 65 73 73 49 74 65 | RandomA|ccessIte|
|000063c0| 72 61 74 6f 72 20 6c 61 | 73 74 2c 20 0a 09 09 09 |rator la|st, ....|
|000063d0| 09 09 20 20 20 54 20 70 | 69 76 6f 74 2c 20 43 6f |.. T p|ivot, Co|
|000063e0| 6d 70 61 72 65 20 63 6f | 6d 70 29 20 7b 0a 20 20 |mpare co|mp) {. |
|000063f0| 20 20 77 68 69 6c 65 20 | 28 31 29 20 7b 0a 09 77 | while |(1) {..w|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.