Home | History | Annotate | Download | only in forwardlist.ops
      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 // <forward_list>
     11 
     12 // template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
     13 
     14 #include <forward_list>
     15 #include <iterator>
     16 #include <cassert>
     17 
     18 #include "min_allocator.h"
     19 
     20 bool g(int x, int y)
     21 {
     22     return x == y;
     23 }
     24 
     25 int main()
     26 {
     27     {
     28         typedef int T;
     29         typedef std::forward_list<T> C;
     30         const T t1[] = {0, 5, 5, 0, 0, 0, 5};
     31         const T t2[] = {0, 5, 0, 5};
     32         C c1(std::begin(t1), std::end(t1));
     33         C c2(std::begin(t2), std::end(t2));
     34         c1.unique(g);
     35         assert(c1 == c2);
     36     }
     37     {
     38         typedef int T;
     39         typedef std::forward_list<T> C;
     40         const T t1[] = {0, 0, 0, 0};
     41         const T t2[] = {0};
     42         C c1(std::begin(t1), std::end(t1));
     43         C c2(std::begin(t2), std::end(t2));
     44         c1.unique(g);
     45         assert(c1 == c2);
     46     }
     47     {
     48         typedef int T;
     49         typedef std::forward_list<T> C;
     50         const T t1[] = {5, 5, 5};
     51         const T t2[] = {5};
     52         C c1(std::begin(t1), std::end(t1));
     53         C c2(std::begin(t2), std::end(t2));
     54         c1.unique(g);
     55         assert(c1 == c2);
     56     }
     57     {
     58         typedef int T;
     59         typedef std::forward_list<T> C;
     60         C c1;
     61         C c2;
     62         c1.unique(g);
     63         assert(c1 == c2);
     64     }
     65     {
     66         typedef int T;
     67         typedef std::forward_list<T> C;
     68         const T t1[] = {5, 5, 5, 0};
     69         const T t2[] = {5, 0};
     70         C c1(std::begin(t1), std::end(t1));
     71         C c2(std::begin(t2), std::end(t2));
     72         c1.unique(g);
     73         assert(c1 == c2);
     74     }
     75 #if __cplusplus >= 201103L
     76     {
     77         typedef int T;
     78         typedef std::forward_list<T, min_allocator<T>> C;
     79         const T t1[] = {0, 5, 5, 0, 0, 0, 5};
     80         const T t2[] = {0, 5, 0, 5};
     81         C c1(std::begin(t1), std::end(t1));
     82         C c2(std::begin(t2), std::end(t2));
     83         c1.unique(g);
     84         assert(c1 == c2);
     85     }
     86     {
     87         typedef int T;
     88         typedef std::forward_list<T, min_allocator<T>> C;
     89         const T t1[] = {0, 0, 0, 0};
     90         const T t2[] = {0};
     91         C c1(std::begin(t1), std::end(t1));
     92         C c2(std::begin(t2), std::end(t2));
     93         c1.unique(g);
     94         assert(c1 == c2);
     95     }
     96     {
     97         typedef int T;
     98         typedef std::forward_list<T, min_allocator<T>> C;
     99         const T t1[] = {5, 5, 5};
    100         const T t2[] = {5};
    101         C c1(std::begin(t1), std::end(t1));
    102         C c2(std::begin(t2), std::end(t2));
    103         c1.unique(g);
    104         assert(c1 == c2);
    105     }
    106     {
    107         typedef int T;
    108         typedef std::forward_list<T, min_allocator<T>> C;
    109         C c1;
    110         C c2;
    111         c1.unique(g);
    112         assert(c1 == c2);
    113     }
    114     {
    115         typedef int T;
    116         typedef std::forward_list<T, min_allocator<T>> C;
    117         const T t1[] = {5, 5, 5, 0};
    118         const T t2[] = {5, 0};
    119         C c1(std::begin(t1), std::end(t1));
    120         C c2(std::begin(t2), std::end(t2));
    121         c1.unique(g);
    122         assert(c1 == c2);
    123     }
    124 #endif
    125 }
    126