~ubuntu-branches/ubuntu/trusty/libc++/trusty

« back to all changes in this revision

Viewing changes to libcxx/test/containers/sequences/list/list.cons/assign_move.pass.cpp

  • Committer: Package Import Robot
  • Author(s): Andrej Belym
  • Date: 2012-06-02 19:25:47 UTC
  • Revision ID: package-import@ubuntu.com-20120602192547-b6ta950a8ckc9um2
Tags: upstream-1.0~svn160132
ImportĀ upstreamĀ versionĀ 1.0~svn160132

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// <list>
 
11
 
 
12
// list& operator=(list&& c);
 
13
 
 
14
#include <list>
 
15
#include <cassert>
 
16
#include "../../../MoveOnly.h"
 
17
#include "../../../test_allocator.h"
 
18
 
 
19
int main()
 
20
{
 
21
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
22
    {
 
23
        std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
 
24
        std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
 
25
        for (int i = 1; i <= 3; ++i)
 
26
        {
 
27
            l.push_back(i);
 
28
            lo.push_back(i);
 
29
        }
 
30
        std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
 
31
        l2 = std::move(l);
 
32
        assert(l2 == lo);
 
33
        assert(l.empty());
 
34
        assert(l2.get_allocator() == lo.get_allocator());
 
35
    }
 
36
    {
 
37
        std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
 
38
        std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
 
39
        for (int i = 1; i <= 3; ++i)
 
40
        {
 
41
            l.push_back(i);
 
42
            lo.push_back(i);
 
43
        }
 
44
        std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
 
45
        l2 = std::move(l);
 
46
        assert(l2 == lo);
 
47
        assert(!l.empty());
 
48
        assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
 
49
    }
 
50
    {
 
51
        std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
 
52
        std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
 
53
        for (int i = 1; i <= 3; ++i)
 
54
        {
 
55
            l.push_back(i);
 
56
            lo.push_back(i);
 
57
        }
 
58
        std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
 
59
        l2 = std::move(l);
 
60
        assert(l2 == lo);
 
61
        assert(l.empty());
 
62
        assert(l2.get_allocator() == lo.get_allocator());
 
63
    }
 
64
#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
65
}