Home | History | Annotate | Download | only in set.cons
      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 // <set>
     11 
     12 // class set
     13 
     14 // set& operator=(set&& s);
     15 
     16 #include <set>
     17 #include <cassert>
     18 
     19 #include "MoveOnly.h"
     20 #include "../../../test_compare.h"
     21 #include "test_allocator.h"
     22 #include "min_allocator.h"
     23 
     24 int main()
     25 {
     26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     27     {
     28         typedef MoveOnly V;
     29         typedef test_compare<std::less<MoveOnly> > C;
     30         typedef test_allocator<V> A;
     31         typedef std::set<MoveOnly, C, A> M;
     32         typedef std::move_iterator<V*> I;
     33         V a1[] =
     34         {
     35             V(1),
     36             V(1),
     37             V(1),
     38             V(2),
     39             V(2),
     40             V(2),
     41             V(3),
     42             V(3),
     43             V(3)
     44         };
     45         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     46         V a2[] =
     47         {
     48             V(1),
     49             V(1),
     50             V(1),
     51             V(2),
     52             V(2),
     53             V(2),
     54             V(3),
     55             V(3),
     56             V(3)
     57         };
     58         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
     59         M m3(C(3), A(7));
     60         m3 = std::move(m1);
     61         assert(m3 == m2);
     62         assert(m3.get_allocator() == A(7));
     63         assert(m3.key_comp() == C(5));
     64         assert(m1.empty());
     65     }
     66     {
     67         typedef MoveOnly V;
     68         typedef test_compare<std::less<MoveOnly> > C;
     69         typedef test_allocator<V> A;
     70         typedef std::set<MoveOnly, C, A> M;
     71         typedef std::move_iterator<V*> I;
     72         V a1[] =
     73         {
     74             V(1),
     75             V(1),
     76             V(1),
     77             V(2),
     78             V(2),
     79             V(2),
     80             V(3),
     81             V(3),
     82             V(3)
     83         };
     84         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     85         V a2[] =
     86         {
     87             V(1),
     88             V(1),
     89             V(1),
     90             V(2),
     91             V(2),
     92             V(2),
     93             V(3),
     94             V(3),
     95             V(3)
     96         };
     97         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
     98         M m3(C(3), A(5));
     99         m3 = std::move(m1);
    100         assert(m3 == m2);
    101         assert(m3.get_allocator() == A(5));
    102         assert(m3.key_comp() == C(5));
    103         assert(m1.empty());
    104     }
    105     {
    106         typedef MoveOnly V;
    107         typedef test_compare<std::less<MoveOnly> > C;
    108         typedef other_allocator<V> A;
    109         typedef std::set<MoveOnly, C, A> M;
    110         typedef std::move_iterator<V*> I;
    111         V a1[] =
    112         {
    113             V(1),
    114             V(1),
    115             V(1),
    116             V(2),
    117             V(2),
    118             V(2),
    119             V(3),
    120             V(3),
    121             V(3)
    122         };
    123         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
    124         V a2[] =
    125         {
    126             V(1),
    127             V(1),
    128             V(1),
    129             V(2),
    130             V(2),
    131             V(2),
    132             V(3),
    133             V(3),
    134             V(3)
    135         };
    136         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
    137         M m3(C(3), A(5));
    138         m3 = std::move(m1);
    139         assert(m3 == m2);
    140         assert(m3.get_allocator() == A(7));
    141         assert(m3.key_comp() == C(5));
    142         assert(m1.empty());
    143     }
    144 #if TEST_STD_VER >= 11
    145     {
    146         typedef MoveOnly V;
    147         typedef test_compare<std::less<MoveOnly> > C;
    148         typedef min_allocator<V> A;
    149         typedef std::set<MoveOnly, C, A> M;
    150         typedef std::move_iterator<V*> I;
    151         V a1[] =
    152         {
    153             V(1),
    154             V(1),
    155             V(1),
    156             V(2),
    157             V(2),
    158             V(2),
    159             V(3),
    160             V(3),
    161             V(3)
    162         };
    163         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
    164         V a2[] =
    165         {
    166             V(1),
    167             V(1),
    168             V(1),
    169             V(2),
    170             V(2),
    171             V(2),
    172             V(3),
    173             V(3),
    174             V(3)
    175         };
    176         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
    177         M m3(C(3), A());
    178         m3 = std::move(m1);
    179         assert(m3 == m2);
    180         assert(m3.get_allocator() == A());
    181         assert(m3.key_comp() == C(5));
    182         assert(m1.empty());
    183     }
    184 #endif
    185 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    186 }
    187