15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03
1075fd25e4SEric Fiselier 
115a83710eSEric Fiselier // <list>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // list(list&& c);
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <list>
165a83710eSEric Fiselier #include <cassert>
177fc6a556SMarshall Clow #include "test_macros.h"
18949389c3SMarshall Clow #include "MoveOnly.h"
195a83710eSEric Fiselier #include "test_allocator.h"
205a83710eSEric Fiselier #include "min_allocator.h"
215a83710eSEric Fiselier 
main(int,char **)222df59c50SJF Bastien int main(int, char**)
235a83710eSEric Fiselier {
245a83710eSEric Fiselier     {
255a83710eSEric Fiselier         std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
265a83710eSEric Fiselier         std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
275a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
285a83710eSEric Fiselier         {
295a83710eSEric Fiselier             l.push_back(i);
305a83710eSEric Fiselier             lo.push_back(i);
315a83710eSEric Fiselier         }
32*8935c844SArthur O'Dwyer         std::list<MoveOnly, test_allocator<MoveOnly> >::iterator it = l.begin();
335a83710eSEric Fiselier         std::list<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l);
345a83710eSEric Fiselier         assert(l2 == lo);
355a83710eSEric Fiselier         assert(l.empty());
365a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
37*8935c844SArthur O'Dwyer         assert(it == l2.begin());  // Iterators remain valid
385a83710eSEric Fiselier     }
395a83710eSEric Fiselier     {
405a83710eSEric Fiselier         std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
415a83710eSEric Fiselier         std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
425a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
435a83710eSEric Fiselier         {
445a83710eSEric Fiselier             l.push_back(i);
455a83710eSEric Fiselier             lo.push_back(i);
465a83710eSEric Fiselier         }
47*8935c844SArthur O'Dwyer         std::list<MoveOnly, other_allocator<MoveOnly> >::iterator it = l.begin();
485a83710eSEric Fiselier         std::list<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l);
495a83710eSEric Fiselier         assert(l2 == lo);
505a83710eSEric Fiselier         assert(l.empty());
515a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
52*8935c844SArthur O'Dwyer         assert(it == l2.begin());  // Iterators remain valid
535a83710eSEric Fiselier     }
545a83710eSEric Fiselier     {
555a83710eSEric Fiselier         std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
565a83710eSEric Fiselier         std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
575a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
585a83710eSEric Fiselier         {
595a83710eSEric Fiselier             l.push_back(i);
605a83710eSEric Fiselier             lo.push_back(i);
615a83710eSEric Fiselier         }
62*8935c844SArthur O'Dwyer         std::list<MoveOnly, min_allocator<MoveOnly> >::iterator it = l.begin();
635a83710eSEric Fiselier         std::list<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
645a83710eSEric Fiselier         assert(l2 == lo);
655a83710eSEric Fiselier         assert(l.empty());
665a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
67*8935c844SArthur O'Dwyer         assert(it == l2.begin());  // Iterators remain valid
685a83710eSEric Fiselier     }
692df59c50SJF Bastien 
702df59c50SJF Bastien   return 0;
715a83710eSEric Fiselier }
72