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