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, class BinaryPredicate>
     13 //   bool
     14 //   is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
     15 //                  ForwardIterator2 first2, BinaryPredicate pred);
     16 
     17 #include <algorithm>
     18 #include <functional>
     19 #include <cassert>
     20 
     21 #include "test_iterators.h"
     22 
     23 #if _LIBCPP_STD_VER > 11
     24 #define HAS_FOUR_ITERATOR_VERSION
     25 #endif
     26 
     27 int comparison_count = 0;
     28 template <typename T>
     29 bool counting_equals ( const T &a, const T &b ) {
     30     ++comparison_count;
     31     return a == b;
     32     }
     33 
     34 
     35 int main()
     36 {
     37     {
     38         const int ia[] = {0};
     39         const int ib[] = {0};
     40         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     41         assert(std::is_permutation(forward_iterator<const int*>(ia),
     42                                    forward_iterator<const int*>(ia + 0),
     43                                    forward_iterator<const int*>(ib),
     44                                    std::equal_to<const int>()) == true);
     45         assert(std::is_permutation(forward_iterator<const int*>(ia),
     46                                    forward_iterator<const int*>(ia + sa),
     47                                    forward_iterator<const int*>(ib),
     48                                    std::equal_to<const int>()) == true);
     49 #ifdef HAS_FOUR_ITERATOR_VERSION
     50         assert(std::is_permutation(forward_iterator<const int*>(ia),
     51                                    forward_iterator<const int*>(ia + sa),
     52                                    forward_iterator<const int*>(ib),
     53                                    forward_iterator<const int*>(ib + sa),
     54                                    std::equal_to<const int>()) == true);
     55         assert(std::is_permutation(forward_iterator<const int*>(ia),
     56                                    forward_iterator<const int*>(ia + sa),
     57                                    forward_iterator<const int*>(ib),
     58                                    forward_iterator<const int*>(ib + sa - 1),
     59                                    std::equal_to<const int>()) == false);
     60 #endif
     61     }
     62     {
     63         const int ia[] = {0};
     64         const int ib[] = {1};
     65         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     66         assert(std::is_permutation(forward_iterator<const int*>(ia),
     67                                    forward_iterator<const int*>(ia + sa),
     68                                    forward_iterator<const int*>(ib),
     69                                    std::equal_to<const int>()) == false);
     70 #ifdef HAS_FOUR_ITERATOR_VERSION
     71         assert(std::is_permutation(forward_iterator<const int*>(ia),
     72                                    forward_iterator<const int*>(ia + sa),
     73                                    forward_iterator<const int*>(ib),
     74                                    forward_iterator<const int*>(ib + sa),
     75                                    std::equal_to<const int>()) == false);
     76 #endif
     77     }
     78 
     79     {
     80         const int ia[] = {0, 0};
     81         const int ib[] = {0, 0};
     82         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     83         assert(std::is_permutation(forward_iterator<const int*>(ia),
     84                                    forward_iterator<const int*>(ia + sa),
     85                                    forward_iterator<const int*>(ib),
     86                                    std::equal_to<const int>()) == true);
     87 #ifdef HAS_FOUR_ITERATOR_VERSION
     88         assert(std::is_permutation(forward_iterator<const int*>(ia),
     89                                    forward_iterator<const int*>(ia + sa),
     90                                    forward_iterator<const int*>(ib),
     91                                    forward_iterator<const int*>(ib + sa),
     92                                    std::equal_to<const int>()) == true);
     93         assert(std::is_permutation(forward_iterator<const int*>(ia),
     94                                    forward_iterator<const int*>(ia + sa),
     95                                    forward_iterator<const int*>(ib),
     96                                    forward_iterator<const int*>(ib + sa - 1),
     97                                    std::equal_to<const int>()) == false);
     98 #endif
     99     }
    100     {
    101         const int ia[] = {0, 0};
    102         const int ib[] = {0, 1};
    103         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    104         assert(std::is_permutation(forward_iterator<const int*>(ia),
    105                                    forward_iterator<const int*>(ia + sa),
    106                                    forward_iterator<const int*>(ib),
    107                                    std::equal_to<const int>()) == false);
    108 #ifdef HAS_FOUR_ITERATOR_VERSION
    109         assert(std::is_permutation(forward_iterator<const int*>(ia),
    110                                    forward_iterator<const int*>(ia + sa),
    111                                    forward_iterator<const int*>(ib),
    112                                    forward_iterator<const int*>(ib + sa),
    113                                    std::equal_to<const int>()) == false);
    114 #endif
    115     }
    116     {
    117         const int ia[] = {0, 0};
    118         const int ib[] = {1, 0};
    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),
    123                                    std::equal_to<const int>()) == false);
    124 #ifdef HAS_FOUR_ITERATOR_VERSION
    125         assert(std::is_permutation(forward_iterator<const int*>(ia),
    126                                    forward_iterator<const int*>(ia + sa),
    127                                    forward_iterator<const int*>(ib),
    128                                    forward_iterator<const int*>(ib + sa),
    129                                    std::equal_to<const int>()) == false);
    130 #endif
    131     }
    132     {
    133         const int ia[] = {0, 0};
    134         const int ib[] = {1, 1};
    135         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    136         assert(std::is_permutation(forward_iterator<const int*>(ia),
    137                                    forward_iterator<const int*>(ia + sa),
    138                                    forward_iterator<const int*>(ib),
    139                                    std::equal_to<const int>()) == false);
    140 #ifdef HAS_FOUR_ITERATOR_VERSION
    141         assert(std::is_permutation(forward_iterator<const int*>(ia),
    142                                    forward_iterator<const int*>(ia + sa),
    143                                    forward_iterator<const int*>(ib),
    144                                    forward_iterator<const int*>(ib + sa),
    145                                    std::equal_to<const int>()) == false);
    146 #endif
    147     }
    148     {
    149         const int ia[] = {0, 1};
    150         const int ib[] = {0, 0};
    151         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    152         assert(std::is_permutation(forward_iterator<const int*>(ia),
    153                                    forward_iterator<const int*>(ia + sa),
    154                                    forward_iterator<const int*>(ib),
    155                                    std::equal_to<const int>()) == false);
    156 #ifdef HAS_FOUR_ITERATOR_VERSION
    157         assert(std::is_permutation(forward_iterator<const int*>(ia),
    158                                    forward_iterator<const int*>(ia + sa),
    159                                    forward_iterator<const int*>(ib),
    160                                    forward_iterator<const int*>(ib + sa),
    161                                    std::equal_to<const int>()) == false);
    162 #endif
    163     }
    164     {
    165         const int ia[] = {0, 1};
    166         const int ib[] = {0, 1};
    167         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    168         assert(std::is_permutation(forward_iterator<const int*>(ia),
    169                                    forward_iterator<const int*>(ia + sa),
    170                                    forward_iterator<const int*>(ib),
    171                                    std::equal_to<const int>()) == true);
    172 #ifdef HAS_FOUR_ITERATOR_VERSION
    173         assert(std::is_permutation(forward_iterator<const int*>(ia),
    174                                    forward_iterator<const int*>(ia + sa),
    175                                    forward_iterator<const int*>(ib),
    176                                    forward_iterator<const int*>(ib + sa),
    177                                    std::equal_to<const int>()) == true);
    178         assert(std::is_permutation(forward_iterator<const int*>(ia),
    179                                    forward_iterator<const int*>(ia + sa),
    180                                    forward_iterator<const int*>(ib),
    181                                    forward_iterator<const int*>(ib + sa - 1),
    182                                    std::equal_to<const int>()) == false);
    183 #endif
    184     }
    185     {
    186         const int ia[] = {0, 1};
    187         const int ib[] = {1, 0};
    188         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    189         assert(std::is_permutation(forward_iterator<const int*>(ia),
    190                                    forward_iterator<const int*>(ia + sa),
    191                                    forward_iterator<const int*>(ib),
    192                                    std::equal_to<const int>()) == true);
    193 #ifdef HAS_FOUR_ITERATOR_VERSION
    194         assert(std::is_permutation(forward_iterator<const int*>(ia),
    195                                    forward_iterator<const int*>(ia + sa),
    196                                    forward_iterator<const int*>(ib),
    197                                    forward_iterator<const int*>(ib + sa),
    198                                    std::equal_to<const int>()) == true);
    199         assert(std::is_permutation(forward_iterator<const int*>(ia),
    200                                    forward_iterator<const int*>(ia + sa),
    201                                    forward_iterator<const int*>(ib),
    202                                    forward_iterator<const int*>(ib + sa - 1),
    203                                    std::equal_to<const int>()) == false);
    204 #endif
    205     }
    206     {
    207         const int ia[] = {0, 1};
    208         const int ib[] = {1, 1};
    209         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    210         assert(std::is_permutation(forward_iterator<const int*>(ia),
    211                                    forward_iterator<const int*>(ia + sa),
    212                                    forward_iterator<const int*>(ib),
    213                                    std::equal_to<const int>()) == false);
    214 #ifdef HAS_FOUR_ITERATOR_VERSION
    215         assert(std::is_permutation(forward_iterator<const int*>(ia),
    216                                    forward_iterator<const int*>(ia + sa),
    217                                    forward_iterator<const int*>(ib),
    218                                    forward_iterator<const int*>(ib + sa),
    219                                    std::equal_to<const int>()) == false);
    220 #endif
    221     }
    222     {
    223         const int ia[] = {1, 0};
    224         const int ib[] = {0, 0};
    225         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    226         assert(std::is_permutation(forward_iterator<const int*>(ia),
    227                                    forward_iterator<const int*>(ia + sa),
    228                                    forward_iterator<const int*>(ib),
    229                                    std::equal_to<const int>()) == false);
    230 #ifdef HAS_FOUR_ITERATOR_VERSION
    231         assert(std::is_permutation(forward_iterator<const int*>(ia),
    232                                    forward_iterator<const int*>(ia + sa),
    233                                    forward_iterator<const int*>(ib),
    234                                    forward_iterator<const int*>(ib + sa),
    235                                    std::equal_to<const int>()) == false);
    236 #endif
    237     }
    238     {
    239         const int ia[] = {1, 0};
    240         const int ib[] = {0, 1};
    241         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    242         assert(std::is_permutation(forward_iterator<const int*>(ia),
    243                                    forward_iterator<const int*>(ia + sa),
    244                                    forward_iterator<const int*>(ib),
    245                                    std::equal_to<const int>()) == true);
    246 #ifdef HAS_FOUR_ITERATOR_VERSION
    247         assert(std::is_permutation(forward_iterator<const int*>(ia),
    248                                    forward_iterator<const int*>(ia + sa),
    249                                    forward_iterator<const int*>(ib),
    250                                    forward_iterator<const int*>(ib + sa),
    251                                    std::equal_to<const int>()) == true);
    252         assert(std::is_permutation(forward_iterator<const int*>(ia),
    253                                    forward_iterator<const int*>(ia + sa),
    254                                    forward_iterator<const int*>(ib),
    255                                    forward_iterator<const int*>(ib + sa - 1),
    256                                    std::equal_to<const int>()) == false);
    257 #endif
    258     }
    259     {
    260         const int ia[] = {1, 0};
    261         const int ib[] = {1, 0};
    262         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    263         assert(std::is_permutation(forward_iterator<const int*>(ia),
    264                                    forward_iterator<const int*>(ia + sa),
    265                                    forward_iterator<const int*>(ib),
    266                                    std::equal_to<const int>()) == true);
    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),
    272                                    std::equal_to<const int>()) == true);
    273         assert(std::is_permutation(forward_iterator<const int*>(ia),
    274                                    forward_iterator<const int*>(ia + sa),
    275                                    forward_iterator<const int*>(ib),
    276                                    forward_iterator<const int*>(ib + sa - 1),
    277                                    std::equal_to<const int>()) == false);
    278 #endif
    279     }
    280     {
    281         const int ia[] = {1, 0};
    282         const int ib[] = {1, 1};
    283         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    284         assert(std::is_permutation(forward_iterator<const int*>(ia),
    285                                    forward_iterator<const int*>(ia + sa),
    286                                    forward_iterator<const int*>(ib),
    287                                    std::equal_to<const int>()) == false);
    288 #ifdef HAS_FOUR_ITERATOR_VERSION
    289         assert(std::is_permutation(forward_iterator<const int*>(ia),
    290                                    forward_iterator<const int*>(ia + sa),
    291                                    forward_iterator<const int*>(ib),
    292                                    forward_iterator<const int*>(ib + sa),
    293                                    std::equal_to<const int>()) == false);
    294 #endif
    295     }
    296     {
    297         const int ia[] = {1, 1};
    298         const int ib[] = {0, 0};
    299         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    300         assert(std::is_permutation(forward_iterator<const int*>(ia),
    301                                    forward_iterator<const int*>(ia + sa),
    302                                    forward_iterator<const int*>(ib),
    303                                    std::equal_to<const int>()) == false);
    304 #ifdef HAS_FOUR_ITERATOR_VERSION
    305         assert(std::is_permutation(forward_iterator<const int*>(ia),
    306                                    forward_iterator<const int*>(ia + sa),
    307                                    forward_iterator<const int*>(ib),
    308                                    forward_iterator<const int*>(ib + sa),
    309                                    std::equal_to<const int>()) == false);
    310 #endif
    311     }
    312     {
    313         const int ia[] = {1, 1};
    314         const int ib[] = {0, 1};
    315         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    316         assert(std::is_permutation(forward_iterator<const int*>(ia),
    317                                    forward_iterator<const int*>(ia + sa),
    318                                    forward_iterator<const int*>(ib),
    319                                    std::equal_to<const int>()) == false);
    320 #ifdef HAS_FOUR_ITERATOR_VERSION
    321         assert(std::is_permutation(forward_iterator<const int*>(ia),
    322                                    forward_iterator<const int*>(ia + sa),
    323                                    forward_iterator<const int*>(ib),
    324                                    forward_iterator<const int*>(ib + sa),
    325                                    std::equal_to<const int>()) == false);
    326 #endif
    327     }
    328     {
    329         const int ia[] = {1, 1};
    330         const int ib[] = {1, 0};
    331         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    332         assert(std::is_permutation(forward_iterator<const int*>(ia),
    333                                    forward_iterator<const int*>(ia + sa),
    334                                    forward_iterator<const int*>(ib),
    335                                    std::equal_to<const int>()) == false);
    336 #ifdef HAS_FOUR_ITERATOR_VERSION
    337         assert(std::is_permutation(forward_iterator<const int*>(ia),
    338                                    forward_iterator<const int*>(ia + sa),
    339                                    forward_iterator<const int*>(ib),
    340                                    forward_iterator<const int*>(ib + sa),
    341                                    std::equal_to<const int>()) == false);
    342 #endif
    343     }
    344     {
    345         const int ia[] = {1, 1};
    346         const int ib[] = {1, 1};
    347         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    348         assert(std::is_permutation(forward_iterator<const int*>(ia),
    349                                    forward_iterator<const int*>(ia + sa),
    350                                    forward_iterator<const int*>(ib),
    351                                    std::equal_to<const int>()) == true);
    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),
    357                                    std::equal_to<const int>()) == true);
    358         assert(std::is_permutation(forward_iterator<const int*>(ia),
    359                                    forward_iterator<const int*>(ia + sa),
    360                                    forward_iterator<const int*>(ib),
    361                                    forward_iterator<const int*>(ib + sa - 1),
    362                                    std::equal_to<const int>()) == false);
    363 #endif
    364     }
    365 
    366     {
    367         const int ia[] = {0, 0, 0};
    368         const int ib[] = {1, 0, 0};
    369         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    370         assert(std::is_permutation(forward_iterator<const int*>(ia),
    371                                    forward_iterator<const int*>(ia + sa),
    372                                    forward_iterator<const int*>(ib),
    373                                    std::equal_to<const int>()) == false);
    374 #ifdef HAS_FOUR_ITERATOR_VERSION
    375         assert(std::is_permutation(forward_iterator<const int*>(ia),
    376                                    forward_iterator<const int*>(ia + sa),
    377                                    forward_iterator<const int*>(ib),
    378                                    forward_iterator<const int*>(ib + sa),
    379                                    std::equal_to<const int>()) == false);
    380 #endif
    381     }
    382     {
    383         const int ia[] = {0, 0, 0};
    384         const int ib[] = {1, 0, 1};
    385         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    386         assert(std::is_permutation(forward_iterator<const int*>(ia),
    387                                    forward_iterator<const int*>(ia + sa),
    388                                    forward_iterator<const int*>(ib),
    389                                    std::equal_to<const int>()) == false);
    390 #ifdef HAS_FOUR_ITERATOR_VERSION
    391         assert(std::is_permutation(forward_iterator<const int*>(ia),
    392                                    forward_iterator<const int*>(ia + sa),
    393                                    forward_iterator<const int*>(ib),
    394                                    forward_iterator<const int*>(ib + sa),
    395                                    std::equal_to<const int>()) == false);
    396 #endif
    397     }
    398     {
    399         const int ia[] = {0, 0, 0};
    400         const int ib[] = {1, 0, 2};
    401         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    402         assert(std::is_permutation(forward_iterator<const int*>(ia),
    403                                    forward_iterator<const int*>(ia + sa),
    404                                    forward_iterator<const int*>(ib),
    405                                    std::equal_to<const int>()) == false);
    406 #ifdef HAS_FOUR_ITERATOR_VERSION
    407         assert(std::is_permutation(forward_iterator<const int*>(ia),
    408                                    forward_iterator<const int*>(ia + sa),
    409                                    forward_iterator<const int*>(ib),
    410                                    forward_iterator<const int*>(ib + sa),
    411                                    std::equal_to<const int>()) == false);
    412 #endif
    413     }
    414     {
    415         const int ia[] = {0, 0, 0};
    416         const int ib[] = {1, 1, 0};
    417         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    418         assert(std::is_permutation(forward_iterator<const int*>(ia),
    419                                    forward_iterator<const int*>(ia + sa),
    420                                    forward_iterator<const int*>(ib),
    421                                    std::equal_to<const int>()) == 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),
    427                                    std::equal_to<const int>()) == false);
    428 #endif
    429     }
    430     {
    431         const int ia[] = {0, 0, 0};
    432         const int ib[] = {1, 1, 1};
    433         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    434         assert(std::is_permutation(forward_iterator<const int*>(ia),
    435                                    forward_iterator<const int*>(ia + sa),
    436                                    forward_iterator<const int*>(ib),
    437                                    std::equal_to<const int>()) == false);
    438 #ifdef HAS_FOUR_ITERATOR_VERSION
    439         assert(std::is_permutation(forward_iterator<const int*>(ia),
    440                                    forward_iterator<const int*>(ia + sa),
    441                                    forward_iterator<const int*>(ib),
    442                                    forward_iterator<const int*>(ib + sa),
    443                                    std::equal_to<const int>()) == false);
    444 #endif
    445     }
    446     {
    447         const int ia[] = {0, 0, 0};
    448         const int ib[] = {1, 1, 2};
    449         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    450         assert(std::is_permutation(forward_iterator<const int*>(ia),
    451                                    forward_iterator<const int*>(ia + sa),
    452                                    forward_iterator<const int*>(ib),
    453                                    std::equal_to<const int>()) == 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),
    459                                    std::equal_to<const int>()) == false);
    460 #endif
    461     }
    462     {
    463         const int ia[] = {0, 0, 0};
    464         const int ib[] = {1, 2, 0};
    465         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    466         assert(std::is_permutation(forward_iterator<const int*>(ia),
    467                                    forward_iterator<const int*>(ia + sa),
    468                                    forward_iterator<const int*>(ib),
    469                                    std::equal_to<const int>()) == false);
    470 #ifdef HAS_FOUR_ITERATOR_VERSION
    471         assert(std::is_permutation(forward_iterator<const int*>(ia),
    472                                    forward_iterator<const int*>(ia + sa),
    473                                    forward_iterator<const int*>(ib),
    474                                    forward_iterator<const int*>(ib + sa),
    475                                    std::equal_to<const int>()) == false);
    476 #endif
    477     }
    478     {
    479         const int ia[] = {0, 0, 0};
    480         const int ib[] = {1, 2, 1};
    481         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    482         assert(std::is_permutation(forward_iterator<const int*>(ia),
    483                                    forward_iterator<const int*>(ia + sa),
    484                                    forward_iterator<const int*>(ib),
    485                                    std::equal_to<const int>()) == false);
    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),
    491                                    std::equal_to<const int>()) == false);
    492 #endif
    493     }
    494     {
    495         const int ia[] = {0, 0, 0};
    496         const int ib[] = {1, 2, 2};
    497         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    498         assert(std::is_permutation(forward_iterator<const int*>(ia),
    499                                    forward_iterator<const int*>(ia + sa),
    500                                    forward_iterator<const int*>(ib),
    501                                    std::equal_to<const int>()) == false);
    502 #ifdef HAS_FOUR_ITERATOR_VERSION
    503         assert(std::is_permutation(forward_iterator<const int*>(ia),
    504                                    forward_iterator<const int*>(ia + sa),
    505                                    forward_iterator<const int*>(ib),
    506                                    forward_iterator<const int*>(ib + sa),
    507                                    std::equal_to<const int>()) == false);
    508 #endif
    509     }
    510     {
    511         const int ia[] = {0, 0, 1};
    512         const int ib[] = {1, 0, 0};
    513         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    514         assert(std::is_permutation(forward_iterator<const int*>(ia),
    515                                    forward_iterator<const int*>(ia + sa),
    516                                    forward_iterator<const int*>(ib),
    517                                    std::equal_to<const int>()) == true);
    518 #ifdef HAS_FOUR_ITERATOR_VERSION
    519         assert(std::is_permutation(forward_iterator<const int*>(ia),
    520                                    forward_iterator<const int*>(ia + sa),
    521                                    forward_iterator<const int*>(ib),
    522                                    forward_iterator<const int*>(ib + sa),
    523                                    std::equal_to<const int>()) == true);
    524         assert(std::is_permutation(forward_iterator<const int*>(ia),
    525                                    forward_iterator<const int*>(ia + sa),
    526                                    forward_iterator<const int*>(ib),
    527                                    forward_iterator<const int*>(ib + sa - 1),
    528                                    std::equal_to<const int>()) == false);
    529 #endif
    530     }
    531     {
    532         const int ia[] = {0, 0, 1};
    533         const int ib[] = {1, 0, 1};
    534         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    535         assert(std::is_permutation(forward_iterator<const int*>(ia),
    536                                    forward_iterator<const int*>(ia + sa),
    537                                    forward_iterator<const int*>(ib),
    538                                    std::equal_to<const int>()) == false);
    539 #ifdef HAS_FOUR_ITERATOR_VERSION
    540         assert(std::is_permutation(forward_iterator<const int*>(ia),
    541                                    forward_iterator<const int*>(ia + sa),
    542                                    forward_iterator<const int*>(ib),
    543                                    forward_iterator<const int*>(ib + sa),
    544                                    std::equal_to<const int>()) == false);
    545 #endif
    546     }
    547     {
    548         const int ia[] = {0, 1, 2};
    549         const int ib[] = {1, 0, 2};
    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),
    554                                    std::equal_to<const int>()) == true);
    555 #ifdef HAS_FOUR_ITERATOR_VERSION
    556         assert(std::is_permutation(forward_iterator<const int*>(ia),
    557                                    forward_iterator<const int*>(ia + sa),
    558                                    forward_iterator<const int*>(ib),
    559                                    forward_iterator<const int*>(ib + sa),
    560                                    std::equal_to<const int>()) == true);
    561         assert(std::is_permutation(forward_iterator<const int*>(ia),
    562                                    forward_iterator<const int*>(ia + sa),
    563                                    forward_iterator<const int*>(ib),
    564                                    forward_iterator<const int*>(ib + sa - 1),
    565                                    std::equal_to<const int>()) == false);
    566 #endif
    567     }
    568     {
    569         const int ia[] = {0, 1, 2};
    570         const int ib[] = {1, 2, 0};
    571         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    572         assert(std::is_permutation(forward_iterator<const int*>(ia),
    573                                    forward_iterator<const int*>(ia + sa),
    574                                    forward_iterator<const int*>(ib),
    575                                    std::equal_to<const int>()) == 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),
    581                                    std::equal_to<const int>()) == true);
    582         assert(std::is_permutation(forward_iterator<const int*>(ia),
    583                                    forward_iterator<const int*>(ia + sa),
    584                                    forward_iterator<const int*>(ib),
    585                                    forward_iterator<const int*>(ib + sa - 1),
    586                                    std::equal_to<const int>()) == false);
    587 #endif
    588     }
    589     {
    590         const int ia[] = {0, 1, 2};
    591         const int ib[] = {2, 1, 0};
    592         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    593         assert(std::is_permutation(forward_iterator<const int*>(ia),
    594                                    forward_iterator<const int*>(ia + sa),
    595                                    forward_iterator<const int*>(ib),
    596                                    std::equal_to<const int>()) == true);
    597 #ifdef HAS_FOUR_ITERATOR_VERSION
    598         assert(std::is_permutation(forward_iterator<const int*>(ia),
    599                                    forward_iterator<const int*>(ia + sa),
    600                                    forward_iterator<const int*>(ib),
    601                                    forward_iterator<const int*>(ib + sa),
    602                                    std::equal_to<const int>()) == true);
    603         assert(std::is_permutation(forward_iterator<const int*>(ia),
    604                                    forward_iterator<const int*>(ia + sa),
    605                                    forward_iterator<const int*>(ib),
    606                                    forward_iterator<const int*>(ib + sa - 1),
    607                                    std::equal_to<const int>()) == false);
    608 #endif
    609     }
    610     {
    611         const int ia[] = {0, 1, 2};
    612         const int ib[] = {2, 0, 1};
    613         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    614         assert(std::is_permutation(forward_iterator<const int*>(ia),
    615                                    forward_iterator<const int*>(ia + sa),
    616                                    forward_iterator<const int*>(ib),
    617                                    std::equal_to<const int>()) == true);
    618 #ifdef HAS_FOUR_ITERATOR_VERSION
    619         assert(std::is_permutation(forward_iterator<const int*>(ia),
    620                                    forward_iterator<const int*>(ia + sa),
    621                                    forward_iterator<const int*>(ib),
    622                                    forward_iterator<const int*>(ib + sa),
    623                                    std::equal_to<const int>()) == true);
    624         assert(std::is_permutation(forward_iterator<const int*>(ia),
    625                                    forward_iterator<const int*>(ia + sa),
    626                                    forward_iterator<const int*>(ib),
    627                                    forward_iterator<const int*>(ib + sa - 1),
    628                                    std::equal_to<const int>()) == false);
    629 #endif
    630     }
    631     {
    632         const int ia[] = {0, 0, 1};
    633         const int ib[] = {1, 0, 1};
    634         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    635         assert(std::is_permutation(forward_iterator<const int*>(ia),
    636                                    forward_iterator<const int*>(ia + sa),
    637                                    forward_iterator<const int*>(ib),
    638                                    std::equal_to<const int>()) == false);
    639 #ifdef HAS_FOUR_ITERATOR_VERSION
    640         assert(std::is_permutation(forward_iterator<const int*>(ia),
    641                                    forward_iterator<const int*>(ia + sa),
    642                                    forward_iterator<const int*>(ib),
    643                                    forward_iterator<const int*>(ib + sa),
    644                                    std::equal_to<const int>()) == false);
    645 #endif
    646     }
    647     {
    648         const int ia[] = {0, 0, 1};
    649         const int ib[] = {1, 0, 0};
    650         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    651         assert(std::is_permutation(forward_iterator<const int*>(ia),
    652                                    forward_iterator<const int*>(ia + sa),
    653                                    forward_iterator<const int*>(ib),
    654                                    std::equal_to<const int>()) == true);
    655 #ifdef HAS_FOUR_ITERATOR_VERSION
    656         assert(std::is_permutation(forward_iterator<const int*>(ia),
    657                                    forward_iterator<const int*>(ia + sa),
    658                                    forward_iterator<const int*>(ib),
    659                                    forward_iterator<const int*>(ib + sa),
    660                                    std::equal_to<const int>()) == true);
    661         assert(std::is_permutation(forward_iterator<const int*>(ia),
    662                                    forward_iterator<const int*>(ia + sa),
    663                                    forward_iterator<const int*>(ib + 1),
    664                                    forward_iterator<const int*>(ib + sa),
    665                                    std::equal_to<const int>()) == false);
    666         assert(std::is_permutation(forward_iterator<const int*>(ia),
    667                                    forward_iterator<const int*>(ia + sa),
    668                                    forward_iterator<const int*>(ib),
    669                                    forward_iterator<const int*>(ib + sa - 1),
    670                                    std::equal_to<const int>()) == false);
    671 #endif
    672     }
    673     {
    674         const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
    675         const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2};
    676         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    677         assert(std::is_permutation(forward_iterator<const int*>(ia),
    678                                    forward_iterator<const int*>(ia + sa),
    679                                    forward_iterator<const int*>(ib),
    680                                    std::equal_to<const int>()) == true);
    681 #ifdef HAS_FOUR_ITERATOR_VERSION
    682         assert(std::is_permutation(forward_iterator<const int*>(ia),
    683                                    forward_iterator<const int*>(ia + sa),
    684                                    forward_iterator<const int*>(ib),
    685                                    forward_iterator<const int*>(ib + sa),
    686                                    std::equal_to<const int>()) == true);
    687         assert(std::is_permutation(forward_iterator<const int*>(ia),
    688                                    forward_iterator<const int*>(ia + sa),
    689                                    forward_iterator<const int*>(ib + 1),
    690                                    forward_iterator<const int*>(ib + sa),
    691                                    std::equal_to<const int>()) == false);
    692         assert(std::is_permutation(forward_iterator<const int*>(ia),
    693                                    forward_iterator<const int*>(ia + sa),
    694                                    forward_iterator<const int*>(ib),
    695                                    forward_iterator<const int*>(ib + sa - 1),
    696                                    std::equal_to<const int>()) == false);
    697         comparison_count = 0;
    698         assert(std::is_permutation(forward_iterator<const int*>(ia),
    699                                    forward_iterator<const int*>(ia + sa),
    700                                    forward_iterator<const int*>(ib),
    701                                    forward_iterator<const int*>(ib + sa - 1),
    702                                    counting_equals<const int>) == false);
    703         assert ( comparison_count > 0 );
    704         comparison_count = 0;
    705         assert(std::is_permutation(random_access_iterator<const int*>(ia),
    706                                    random_access_iterator<const int*>(ia + sa),
    707                                    random_access_iterator<const int*>(ib),
    708                                    random_access_iterator<const int*>(ib + sa - 1),
    709                                    counting_equals<const int>) == false);
    710         assert ( comparison_count == 0 );
    711 #endif
    712     }
    713     {
    714         const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
    715         const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0};
    716         const unsigned sa = sizeof(ia)/sizeof(ia[0]);
    717         assert(std::is_permutation(forward_iterator<const int*>(ia),
    718                                    forward_iterator<const int*>(ia + sa),
    719                                    forward_iterator<const int*>(ib),
    720                                    std::equal_to<const int>()) == false);
    721 #ifdef HAS_FOUR_ITERATOR_VERSION
    722         assert(std::is_permutation(forward_iterator<const int*>(ia),
    723                                    forward_iterator<const int*>(ia + sa),
    724                                    forward_iterator<const int*>(ib),
    725                                    forward_iterator<const int*>(ib + sa),
    726                                    std::equal_to<const int>()) == false);
    727 #endif
    728     }
    729 }
    730