Home | History | Annotate | Download | only in alg.is_permutation
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <algorithm>
     11 
     12 // template<class ForwardIterator1, class ForwardIterator2>
     13 //   bool
     14 //   is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
     15 //                  ForwardIterator2 first2);
     16 
     17 #include <algorithm>
     18 #include <cassert>
     19 
     20 #include "test_iterators.h"
     21 
     22 #if _LIBCPP_STD_VER > 11
     23 #define HAS_FOUR_ITERATOR_VERSION
     24 #endif
     25 
     26 int main()
     27 {
     28     {
     29         const int ia[] = {0};
     30         const int ib[] = {0};
     31         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     32         assert(std::is_permutation(forward_iterator<const int*>(ia),
     33                                    forward_iterator<const int*>(ia + 0),
     34                                    forward_iterator<const int*>(ib)) == true);
     35 #ifdef HAS_FOUR_ITERATOR_VERSION
     36         assert(std::is_permutation(forward_iterator<const int*>(ia),
     37                                    forward_iterator<const int*>(ia + 0),
     38                                    forward_iterator<const int*>(ib),
     39                                    forward_iterator<const int*>(ib + 0)) == true);
     40 #endif
     41         assert(std::is_permutation(forward_iterator<const int*>(ia),
     42                                    forward_iterator<const int*>(ia + sa),
     43                                    forward_iterator<const int*>(ib)) == true);
     44 #ifdef HAS_FOUR_ITERATOR_VERSION
     45         assert(std::is_permutation(forward_iterator<const int*>(ia),
     46                                    forward_iterator<const int*>(ia + sa),
     47                                    forward_iterator<const int*>(ib),
     48                                    forward_iterator<const int*>(ib + sa)) == true);
     49         assert(std::is_permutation(forward_iterator<const int*>(ia),
     50                                    forward_iterator<const int*>(ia + sa),
     51                                    forward_iterator<const int*>(ib),
     52                                    forward_iterator<const int*>(ib + sa - 1)) == false);
     53 #endif
     54     }
     55     {
     56         const int ia[] = {0};
     57         const int ib[] = {1};
     58         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     59         assert(std::is_permutation(forward_iterator<const int*>(ia),
     60                                    forward_iterator<const int*>(ia + sa),
     61                                    forward_iterator<const int*>(ib)) == false);
     62 #ifdef HAS_FOUR_ITERATOR_VERSION
     63         assert(std::is_permutation(forward_iterator<const int*>(ia),
     64                                    forward_iterator<const int*>(ia + sa),
     65                                    forward_iterator<const int*>(ib),
     66                                    forward_iterator<const int*>(ib + sa)) == false);
     67 #endif
     68     }
     69 
     70     {
     71         const int ia[] = {0, 0};
     72         const int ib[] = {0, 0};
     73         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     74         assert(std::is_permutation(forward_iterator<const int*>(ia),
     75                                    forward_iterator<const int*>(ia + sa),
     76                                    forward_iterator<const int*>(ib)) == true);
     77 #ifdef HAS_FOUR_ITERATOR_VERSION
     78         assert(std::is_permutation(forward_iterator<const int*>(ia),
     79                                    forward_iterator<const int*>(ia + sa),
     80                                    forward_iterator<const int*>(ib),
     81                                    forward_iterator<const int*>(ib + sa)) == true);
     82         assert(std::is_permutation(forward_iterator<const int*>(ia),
     83                                    forward_iterator<const int*>(ia + sa),
     84                                    forward_iterator<const int*>(ib),
     85                                    forward_iterator<const int*>(ib + sa - 1)) == false);
     86 #endif
     87     }
     88     {
     89         const int ia[] = {0, 0};
     90         const int ib[] = {0, 1};
     91         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     92         assert(std::is_permutation(forward_iterator<const int*>(ia),
     93                                    forward_iterator<const int*>(ia + sa),
     94                                    forward_iterator<const int*>(ib)) == false);
     95 #ifdef HAS_FOUR_ITERATOR_VERSION
     96         assert(std::is_permutation(forward_iterator<const int*>(ia),
     97                                    forward_iterator<const int*>(ia + sa),
     98                                    forward_iterator<const int*>(ib),
     99                                    forward_iterator<const int*>(ib + sa)) == false);
    100 #endif
    101     }
    102     {
    103         const int ia[] = {0, 0};
    104         const int ib[] = {1, 0};
    105         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    106         assert(std::is_permutation(forward_iterator<const int*>(ia),
    107                                    forward_iterator<const int*>(ia + sa),
    108                                    forward_iterator<const int*>(ib)) == false);
    109 #ifdef HAS_FOUR_ITERATOR_VERSION
    110         assert(std::is_permutation(forward_iterator<const int*>(ia),
    111                                    forward_iterator<const int*>(ia + sa),
    112                                    forward_iterator<const int*>(ib),
    113                                    forward_iterator<const int*>(ib + sa)) == false);
    114 #endif
    115     }
    116     {
    117         const int ia[] = {0, 0};
    118         const int ib[] = {1, 1};
    119         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    120         assert(std::is_permutation(forward_iterator<const int*>(ia),
    121                                    forward_iterator<const int*>(ia + sa),
    122                                    forward_iterator<const int*>(ib)) == false);
    123 #ifdef HAS_FOUR_ITERATOR_VERSION
    124         assert(std::is_permutation(forward_iterator<const int*>(ia),
    125                                    forward_iterator<const int*>(ia + sa),
    126                                    forward_iterator<const int*>(ib),
    127                                    forward_iterator<const int*>(ib + sa)) == false);
    128 #endif
    129     }
    130     {
    131         const int ia[] = {0, 1};
    132         const int ib[] = {0, 0};
    133         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    134         assert(std::is_permutation(forward_iterator<const int*>(ia),
    135                                    forward_iterator<const int*>(ia + sa),
    136                                    forward_iterator<const int*>(ib)) == false);
    137 #ifdef HAS_FOUR_ITERATOR_VERSION
    138         assert(std::is_permutation(forward_iterator<const int*>(ia),
    139                                    forward_iterator<const int*>(ia + sa),
    140                                    forward_iterator<const int*>(ib),
    141                                    forward_iterator<const int*>(ib + sa)) == false);
    142 #endif
    143     }
    144     {
    145         const int ia[] = {0, 1};
    146         const int ib[] = {0, 1};
    147         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    148         assert(std::is_permutation(forward_iterator<const int*>(ia),
    149                                    forward_iterator<const int*>(ia + sa),
    150                                    forward_iterator<const int*>(ib)) == true);
    151 #ifdef HAS_FOUR_ITERATOR_VERSION
    152         assert(std::is_permutation(forward_iterator<const int*>(ia),
    153                                    forward_iterator<const int*>(ia + sa),
    154                                    forward_iterator<const int*>(ib),
    155                                    forward_iterator<const int*>(ib + sa)) == true);
    156         assert(std::is_permutation(forward_iterator<const int*>(ia),
    157                                    forward_iterator<const int*>(ia + sa),
    158                                    forward_iterator<const int*>(ib),
    159                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    160 #endif
    161     }
    162     {
    163         const int ia[] = {0, 1};
    164         const int ib[] = {1, 0};
    165         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    166         assert(std::is_permutation(forward_iterator<const int*>(ia),
    167                                    forward_iterator<const int*>(ia + sa),
    168                                    forward_iterator<const int*>(ib)) == true);
    169 #ifdef HAS_FOUR_ITERATOR_VERSION
    170         assert(std::is_permutation(forward_iterator<const int*>(ia),
    171                                    forward_iterator<const int*>(ia + sa),
    172                                    forward_iterator<const int*>(ib),
    173                                    forward_iterator<const int*>(ib + sa)) == true);
    174 #endif
    175     }
    176     {
    177         const int ia[] = {0, 1};
    178         const int ib[] = {1, 1};
    179         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    180         assert(std::is_permutation(forward_iterator<const int*>(ia),
    181                                    forward_iterator<const int*>(ia + sa),
    182                                    forward_iterator<const int*>(ib)) == false);
    183 #ifdef HAS_FOUR_ITERATOR_VERSION
    184         assert(std::is_permutation(forward_iterator<const int*>(ia),
    185                                    forward_iterator<const int*>(ia + sa),
    186                                    forward_iterator<const int*>(ib),
    187                                    forward_iterator<const int*>(ib + sa)) == false);
    188 #endif
    189     }
    190     {
    191         const int ia[] = {1, 0};
    192         const int ib[] = {0, 0};
    193         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    194         assert(std::is_permutation(forward_iterator<const int*>(ia),
    195                                    forward_iterator<const int*>(ia + sa),
    196                                    forward_iterator<const int*>(ib)) == false);
    197 #ifdef HAS_FOUR_ITERATOR_VERSION
    198         assert(std::is_permutation(forward_iterator<const int*>(ia),
    199                                    forward_iterator<const int*>(ia + sa),
    200                                    forward_iterator<const int*>(ib),
    201                                    forward_iterator<const int*>(ib + sa)) == false);
    202 #endif
    203     }
    204     {
    205         const int ia[] = {1, 0};
    206         const int ib[] = {0, 1};
    207         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    208         assert(std::is_permutation(forward_iterator<const int*>(ia),
    209                                    forward_iterator<const int*>(ia + sa),
    210                                    forward_iterator<const int*>(ib)) == true);
    211 #ifdef HAS_FOUR_ITERATOR_VERSION
    212         assert(std::is_permutation(forward_iterator<const int*>(ia),
    213                                    forward_iterator<const int*>(ia + sa),
    214                                    forward_iterator<const int*>(ib),
    215                                    forward_iterator<const int*>(ib + sa)) == true);
    216 #endif
    217     }
    218     {
    219         const int ia[] = {1, 0};
    220         const int ib[] = {1, 0};
    221         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    222         assert(std::is_permutation(forward_iterator<const int*>(ia),
    223                                    forward_iterator<const int*>(ia + sa),
    224                                    forward_iterator<const int*>(ib)) == true);
    225 #ifdef HAS_FOUR_ITERATOR_VERSION
    226         assert(std::is_permutation(forward_iterator<const int*>(ia),
    227                                    forward_iterator<const int*>(ia + sa),
    228                                    forward_iterator<const int*>(ib),
    229                                    forward_iterator<const int*>(ib + sa)) == true);
    230 #endif
    231     }
    232     {
    233         const int ia[] = {1, 0};
    234         const int ib[] = {1, 1};
    235         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    236         assert(std::is_permutation(forward_iterator<const int*>(ia),
    237                                    forward_iterator<const int*>(ia + sa),
    238                                    forward_iterator<const int*>(ib)) == false);
    239 #ifdef HAS_FOUR_ITERATOR_VERSION
    240         assert(std::is_permutation(forward_iterator<const int*>(ia),
    241                                    forward_iterator<const int*>(ia + sa),
    242                                    forward_iterator<const int*>(ib),
    243                                    forward_iterator<const int*>(ib + sa)) == false);
    244 #endif
    245     }
    246     {
    247         const int ia[] = {1, 1};
    248         const int ib[] = {0, 0};
    249         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    250         assert(std::is_permutation(forward_iterator<const int*>(ia),
    251                                    forward_iterator<const int*>(ia + sa),
    252                                    forward_iterator<const int*>(ib)) == false);
    253 #ifdef HAS_FOUR_ITERATOR_VERSION
    254         assert(std::is_permutation(forward_iterator<const int*>(ia),
    255                                    forward_iterator<const int*>(ia + sa),
    256                                    forward_iterator<const int*>(ib),
    257                                    forward_iterator<const int*>(ib + sa)) == false);
    258 #endif
    259     }
    260     {
    261         const int ia[] = {1, 1};
    262         const int ib[] = {0, 1};
    263         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    264         assert(std::is_permutation(forward_iterator<const int*>(ia),
    265                                    forward_iterator<const int*>(ia + sa),
    266                                    forward_iterator<const int*>(ib)) == false);
    267 #ifdef HAS_FOUR_ITERATOR_VERSION
    268         assert(std::is_permutation(forward_iterator<const int*>(ia),
    269                                    forward_iterator<const int*>(ia + sa),
    270                                    forward_iterator<const int*>(ib),
    271                                    forward_iterator<const int*>(ib + sa)) == false);
    272 #endif
    273     }
    274     {
    275         const int ia[] = {1, 1};
    276         const int ib[] = {1, 0};
    277         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    278         assert(std::is_permutation(forward_iterator<const int*>(ia),
    279                                    forward_iterator<const int*>(ia + sa),
    280                                    forward_iterator<const int*>(ib)) == false);
    281 #ifdef HAS_FOUR_ITERATOR_VERSION
    282         assert(std::is_permutation(forward_iterator<const int*>(ia),
    283                                    forward_iterator<const int*>(ia + sa),
    284                                    forward_iterator<const int*>(ib),
    285                                    forward_iterator<const int*>(ib + sa)) == false);
    286 #endif
    287     }
    288     {
    289         const int ia[] = {1, 1};
    290         const int ib[] = {1, 1};
    291         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    292         assert(std::is_permutation(forward_iterator<const int*>(ia),
    293                                    forward_iterator<const int*>(ia + sa),
    294                                    forward_iterator<const int*>(ib)) == true);
    295 #ifdef HAS_FOUR_ITERATOR_VERSION
    296         assert(std::is_permutation(forward_iterator<const int*>(ia),
    297                                    forward_iterator<const int*>(ia + sa),
    298                                    forward_iterator<const int*>(ib),
    299                                    forward_iterator<const int*>(ib + sa)) == true);
    300 #endif
    301     }
    302 
    303     {
    304         const int ia[] = {0, 0, 0};
    305         const int ib[] = {1, 0, 0};
    306         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    307         assert(std::is_permutation(forward_iterator<const int*>(ia),
    308                                    forward_iterator<const int*>(ia + sa),
    309                                    forward_iterator<const int*>(ib)) == false);
    310 #ifdef HAS_FOUR_ITERATOR_VERSION
    311         assert(std::is_permutation(forward_iterator<const int*>(ia),
    312                                    forward_iterator<const int*>(ia + sa),
    313                                    forward_iterator<const int*>(ib),
    314                                    forward_iterator<const int*>(ib + sa)) == false);
    315 #endif
    316     }
    317     {
    318         const int ia[] = {0, 0, 0};
    319         const int ib[] = {1, 0, 1};
    320         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    321         assert(std::is_permutation(forward_iterator<const int*>(ia),
    322                                    forward_iterator<const int*>(ia + sa),
    323                                    forward_iterator<const int*>(ib)) == false);
    324 #ifdef HAS_FOUR_ITERATOR_VERSION
    325         assert(std::is_permutation(forward_iterator<const int*>(ia),
    326                                    forward_iterator<const int*>(ia + sa),
    327                                    forward_iterator<const int*>(ib),
    328                                    forward_iterator<const int*>(ib + sa)) == false);
    329 #endif
    330     }
    331     {
    332         const int ia[] = {0, 0, 0};
    333         const int ib[] = {1, 0, 2};
    334         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    335         assert(std::is_permutation(forward_iterator<const int*>(ia),
    336                                    forward_iterator<const int*>(ia + sa),
    337                                    forward_iterator<const int*>(ib)) == false);
    338 #ifdef HAS_FOUR_ITERATOR_VERSION
    339         assert(std::is_permutation(forward_iterator<const int*>(ia),
    340                                    forward_iterator<const int*>(ia + sa),
    341                                    forward_iterator<const int*>(ib),
    342                                    forward_iterator<const int*>(ib + sa)) == false);
    343 #endif
    344     }
    345     {
    346         const int ia[] = {0, 0, 0};
    347         const int ib[] = {1, 1, 0};
    348         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    349         assert(std::is_permutation(forward_iterator<const int*>(ia),
    350                                    forward_iterator<const int*>(ia + sa),
    351                                    forward_iterator<const int*>(ib)) == false);
    352 #ifdef HAS_FOUR_ITERATOR_VERSION
    353         assert(std::is_permutation(forward_iterator<const int*>(ia),
    354                                    forward_iterator<const int*>(ia + sa),
    355                                    forward_iterator<const int*>(ib),
    356                                    forward_iterator<const int*>(ib + sa)) == false);
    357 #endif
    358     }
    359     {
    360         const int ia[] = {0, 0, 0};
    361         const int ib[] = {1, 1, 1};
    362         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    363         assert(std::is_permutation(forward_iterator<const int*>(ia),
    364                                    forward_iterator<const int*>(ia + sa),
    365                                    forward_iterator<const int*>(ib)) == false);
    366 #ifdef HAS_FOUR_ITERATOR_VERSION
    367         assert(std::is_permutation(forward_iterator<const int*>(ia),
    368                                    forward_iterator<const int*>(ia + sa),
    369                                    forward_iterator<const int*>(ib),
    370                                    forward_iterator<const int*>(ib + sa)) == false);
    371 #endif
    372     }
    373     {
    374         const int ia[] = {0, 0, 0};
    375         const int ib[] = {1, 1, 2};
    376         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    377         assert(std::is_permutation(forward_iterator<const int*>(ia),
    378                                    forward_iterator<const int*>(ia + sa),
    379                                    forward_iterator<const int*>(ib)) == false);
    380 #ifdef HAS_FOUR_ITERATOR_VERSION
    381         assert(std::is_permutation(forward_iterator<const int*>(ia),
    382                                    forward_iterator<const int*>(ia + sa),
    383                                    forward_iterator<const int*>(ib),
    384                                    forward_iterator<const int*>(ib + sa)) == false);
    385 #endif
    386     }
    387     {
    388         const int ia[] = {0, 0, 0};
    389         const int ib[] = {1, 2, 0};
    390         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    391         assert(std::is_permutation(forward_iterator<const int*>(ia),
    392                                    forward_iterator<const int*>(ia + sa),
    393                                    forward_iterator<const int*>(ib)) == false);
    394 #ifdef HAS_FOUR_ITERATOR_VERSION
    395         assert(std::is_permutation(forward_iterator<const int*>(ia),
    396                                    forward_iterator<const int*>(ia + sa),
    397                                    forward_iterator<const int*>(ib),
    398                                    forward_iterator<const int*>(ib + sa)) == false);
    399 #endif
    400     }
    401     {
    402         const int ia[] = {0, 0, 0};
    403         const int ib[] = {1, 2, 1};
    404         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    405         assert(std::is_permutation(forward_iterator<const int*>(ia),
    406                                    forward_iterator<const int*>(ia + sa),
    407                                    forward_iterator<const int*>(ib)) == false);
    408 #ifdef HAS_FOUR_ITERATOR_VERSION
    409         assert(std::is_permutation(forward_iterator<const int*>(ia),
    410                                    forward_iterator<const int*>(ia + sa),
    411                                    forward_iterator<const int*>(ib),
    412                                    forward_iterator<const int*>(ib + sa)) == false);
    413 #endif
    414     }
    415     {
    416         const int ia[] = {0, 0, 0};
    417         const int ib[] = {1, 2, 2};
    418         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    419         assert(std::is_permutation(forward_iterator<const int*>(ia),
    420                                    forward_iterator<const int*>(ia + sa),
    421                                    forward_iterator<const int*>(ib)) == false);
    422 #ifdef HAS_FOUR_ITERATOR_VERSION
    423         assert(std::is_permutation(forward_iterator<const int*>(ia),
    424                                    forward_iterator<const int*>(ia + sa),
    425                                    forward_iterator<const int*>(ib),
    426                                    forward_iterator<const int*>(ib + sa)) == false);
    427 #endif
    428     }
    429     {
    430         const int ia[] = {0, 0, 1};
    431         const int ib[] = {1, 0, 0};
    432         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    433         assert(std::is_permutation(forward_iterator<const int*>(ia),
    434                                    forward_iterator<const int*>(ia + sa),
    435                                    forward_iterator<const int*>(ib)) == true);
    436 #ifdef HAS_FOUR_ITERATOR_VERSION
    437         assert(std::is_permutation(forward_iterator<const int*>(ia),
    438                                    forward_iterator<const int*>(ia + sa),
    439                                    forward_iterator<const int*>(ib),
    440                                    forward_iterator<const int*>(ib + sa)) == true);
    441         assert(std::is_permutation(forward_iterator<const int*>(ia),
    442                                    forward_iterator<const int*>(ia + sa),
    443                                    forward_iterator<const int*>(ib),
    444                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    445 #endif
    446     }
    447     {
    448         const int ia[] = {0, 0, 1};
    449         const int ib[] = {1, 0, 1};
    450         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    451         assert(std::is_permutation(forward_iterator<const int*>(ia),
    452                                    forward_iterator<const int*>(ia + sa),
    453                                    forward_iterator<const int*>(ib)) == false);
    454 #ifdef HAS_FOUR_ITERATOR_VERSION
    455         assert(std::is_permutation(forward_iterator<const int*>(ia),
    456                                    forward_iterator<const int*>(ia + sa),
    457                                    forward_iterator<const int*>(ib),
    458                                    forward_iterator<const int*>(ib + sa)) == false);
    459 #endif
    460     }
    461     {
    462         const int ia[] = {0, 1, 2};
    463         const int ib[] = {1, 0, 2};
    464         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    465         assert(std::is_permutation(forward_iterator<const int*>(ia),
    466                                    forward_iterator<const int*>(ia + sa),
    467                                    forward_iterator<const int*>(ib)) == true);
    468 #ifdef HAS_FOUR_ITERATOR_VERSION
    469         assert(std::is_permutation(forward_iterator<const int*>(ia),
    470                                    forward_iterator<const int*>(ia + sa),
    471                                    forward_iterator<const int*>(ib),
    472                                    forward_iterator<const int*>(ib + sa)) == true);
    473         assert(std::is_permutation(forward_iterator<const int*>(ia),
    474                                    forward_iterator<const int*>(ia + sa),
    475                                    forward_iterator<const int*>(ib),
    476                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    477 #endif
    478     }
    479     {
    480         const int ia[] = {0, 1, 2};
    481         const int ib[] = {1, 2, 0};
    482         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    483         assert(std::is_permutation(forward_iterator<const int*>(ia),
    484                                    forward_iterator<const int*>(ia + sa),
    485                                    forward_iterator<const int*>(ib)) == true);
    486 #ifdef HAS_FOUR_ITERATOR_VERSION
    487         assert(std::is_permutation(forward_iterator<const int*>(ia),
    488                                    forward_iterator<const int*>(ia + sa),
    489                                    forward_iterator<const int*>(ib),
    490                                    forward_iterator<const int*>(ib + sa)) == true);
    491         assert(std::is_permutation(forward_iterator<const int*>(ia),
    492                                    forward_iterator<const int*>(ia + sa),
    493                                    forward_iterator<const int*>(ib),
    494                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    495 #endif
    496     }
    497     {
    498         const int ia[] = {0, 1, 2};
    499         const int ib[] = {2, 1, 0};
    500         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    501         assert(std::is_permutation(forward_iterator<const int*>(ia),
    502                                    forward_iterator<const int*>(ia + sa),
    503                                    forward_iterator<const int*>(ib)) == true);
    504 #ifdef HAS_FOUR_ITERATOR_VERSION
    505         assert(std::is_permutation(forward_iterator<const int*>(ia),
    506                                    forward_iterator<const int*>(ia + sa),
    507                                    forward_iterator<const int*>(ib),
    508                                    forward_iterator<const int*>(ib + sa)) == true);
    509         assert(std::is_permutation(forward_iterator<const int*>(ia),
    510                                    forward_iterator<const int*>(ia + sa),
    511                                    forward_iterator<const int*>(ib),
    512                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    513 #endif
    514     }
    515     {
    516         const int ia[] = {0, 1, 2};
    517         const int ib[] = {2, 0, 1};
    518         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    519         assert(std::is_permutation(forward_iterator<const int*>(ia),
    520                                    forward_iterator<const int*>(ia + sa),
    521                                    forward_iterator<const int*>(ib)) == true);
    522 #ifdef HAS_FOUR_ITERATOR_VERSION
    523         assert(std::is_permutation(forward_iterator<const int*>(ia),
    524                                    forward_iterator<const int*>(ia + sa),
    525                                    forward_iterator<const int*>(ib),
    526                                    forward_iterator<const int*>(ib + sa)) == true);
    527         assert(std::is_permutation(forward_iterator<const int*>(ia),
    528                                    forward_iterator<const int*>(ia + sa),
    529                                    forward_iterator<const int*>(ib),
    530                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    531 #endif
    532     }
    533     {
    534         const int ia[] = {0, 0, 1};
    535         const int ib[] = {1, 0, 1};
    536         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    537         assert(std::is_permutation(forward_iterator<const int*>(ia),
    538                                    forward_iterator<const int*>(ia + sa),
    539                                    forward_iterator<const int*>(ib)) == false);
    540 #ifdef HAS_FOUR_ITERATOR_VERSION
    541         assert(std::is_permutation(forward_iterator<const int*>(ia),
    542                                    forward_iterator<const int*>(ia + sa),
    543                                    forward_iterator<const int*>(ib),
    544                                    forward_iterator<const int*>(ib + sa)) == false);
    545 #endif
    546     }
    547     {
    548         const int ia[] = {0, 0, 1};
    549         const int ib[] = {1, 0, 0};
    550         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    551         assert(std::is_permutation(forward_iterator<const int*>(ia),
    552                                    forward_iterator<const int*>(ia + sa),
    553                                    forward_iterator<const int*>(ib)) == true);
    554 #ifdef HAS_FOUR_ITERATOR_VERSION
    555         assert(std::is_permutation(forward_iterator<const int*>(ia),
    556                                    forward_iterator<const int*>(ia + sa),
    557                                    forward_iterator<const int*>(ib),
    558                                    forward_iterator<const int*>(ib + sa)) == true);
    559         assert(std::is_permutation(forward_iterator<const int*>(ia),
    560                                    forward_iterator<const int*>(ia + sa),
    561                                    forward_iterator<const int*>(ib + 1),
    562                                    forward_iterator<const int*>(ib + sa)) == false);
    563         assert(std::is_permutation(forward_iterator<const int*>(ia),
    564                                    forward_iterator<const int*>(ia + sa),
    565                                    forward_iterator<const int*>(ib),
    566                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    567 #endif
    568     }
    569     {
    570         const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
    571         const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2};
    572         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    573         assert(std::is_permutation(forward_iterator<const int*>(ia),
    574                                    forward_iterator<const int*>(ia + sa),
    575                                    forward_iterator<const int*>(ib)) == true);
    576 #ifdef HAS_FOUR_ITERATOR_VERSION
    577         assert(std::is_permutation(forward_iterator<const int*>(ia),
    578                                    forward_iterator<const int*>(ia + sa),
    579                                    forward_iterator<const int*>(ib),
    580                                    forward_iterator<const int*>(ib + sa)) == true);
    581         assert(std::is_permutation(forward_iterator<const int*>(ia),
    582                                    forward_iterator<const int*>(ia + sa),
    583                                    forward_iterator<const int*>(ib + 1 ),
    584                                    forward_iterator<const int*>(ib + sa)) == false);
    585         assert(std::is_permutation(forward_iterator<const int*>(ia),
    586                                    forward_iterator<const int*>(ia + sa),
    587                                    forward_iterator<const int*>(ib),
    588                                    forward_iterator<const int*>(ib + sa - 1)) == false);
    589 #endif
    590     }
    591     {
    592         const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
    593         const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0};
    594         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    595         assert(std::is_permutation(forward_iterator<const int*>(ia),
    596                                    forward_iterator<const int*>(ia + sa),
    597                                    forward_iterator<const int*>(ib)) == false);
    598 #ifdef HAS_FOUR_ITERATOR_VERSION
    599         assert(std::is_permutation(forward_iterator<const int*>(ia),
    600                                    forward_iterator<const int*>(ia + sa),
    601                                    forward_iterator<const int*>(ib),
    602                                    forward_iterator<const int*>(ib + sa)) == false);
    603 #endif
    604     }
    605 }
    606