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
10843d9101SEric Fiselier 
115a83710eSEric Fiselier // <vector>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // vector(vector&& c);
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <vector>
165a83710eSEric Fiselier #include <cassert>
178cef7fd7SEric Fiselier #include "test_macros.h"
185a83710eSEric Fiselier #include "test_allocator.h"
195a83710eSEric Fiselier #include "min_allocator.h"
205a83710eSEric Fiselier 
tests()21*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
225a83710eSEric Fiselier {
239a140a15SNikolas Klauser     test_allocator_statistics alloc_stats;
245a83710eSEric Fiselier     {
259a140a15SNikolas Klauser         std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5, &alloc_stats));
269a140a15SNikolas Klauser         std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5, &alloc_stats));
275a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
285a83710eSEric Fiselier         {
2921981194SStephan T. Lavavej             l.push_back(true);
3021981194SStephan T. Lavavej             lo.push_back(true);
315a83710eSEric Fiselier         }
325a83710eSEric Fiselier         std::vector<bool, test_allocator<bool> > l2 = std::move(l);
335a83710eSEric Fiselier         assert(l2 == lo);
345a83710eSEric Fiselier         assert(l.empty());
355a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
365a83710eSEric Fiselier     }
375a83710eSEric Fiselier     {
385a83710eSEric Fiselier         std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5));
395a83710eSEric Fiselier         std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5));
405a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
415a83710eSEric Fiselier         {
4221981194SStephan T. Lavavej             l.push_back(true);
4321981194SStephan T. Lavavej             lo.push_back(true);
445a83710eSEric Fiselier         }
455a83710eSEric Fiselier         std::vector<bool, other_allocator<bool> > l2 = std::move(l);
465a83710eSEric Fiselier         assert(l2 == lo);
475a83710eSEric Fiselier         assert(l.empty());
485a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
495a83710eSEric Fiselier     }
505a83710eSEric Fiselier     {
515a83710eSEric Fiselier         std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{});
525a83710eSEric Fiselier         std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{});
535a83710eSEric Fiselier         for (int i = 1; i <= 3; ++i)
545a83710eSEric Fiselier         {
5521981194SStephan T. Lavavej             l.push_back(true);
5621981194SStephan T. Lavavej             lo.push_back(true);
575a83710eSEric Fiselier         }
585a83710eSEric Fiselier         std::vector<bool, min_allocator<bool> > l2 = std::move(l);
595a83710eSEric Fiselier         assert(l2 == lo);
605a83710eSEric Fiselier         assert(l.empty());
615a83710eSEric Fiselier         assert(l2.get_allocator() == lo.get_allocator());
625a83710eSEric Fiselier     }
638cef7fd7SEric Fiselier     {
649a140a15SNikolas Klauser       alloc_stats.clear();
658cef7fd7SEric Fiselier       using Vect = std::vector<bool, test_allocator<bool> >;
668cef7fd7SEric Fiselier       using AllocT = Vect::allocator_type;
679a140a15SNikolas Klauser       Vect v(test_allocator<bool>(42, 101, &alloc_stats));
689a140a15SNikolas Klauser       assert(alloc_stats.count == 1);
698cef7fd7SEric Fiselier       {
708cef7fd7SEric Fiselier         const AllocT& a = v.get_allocator();
719a140a15SNikolas Klauser         assert(alloc_stats.count == 2);
728cef7fd7SEric Fiselier         assert(a.get_data() == 42);
738cef7fd7SEric Fiselier         assert(a.get_id() == 101);
748cef7fd7SEric Fiselier       }
759a140a15SNikolas Klauser       assert(alloc_stats.count == 1);
769a140a15SNikolas Klauser       alloc_stats.clear_ctor_counters();
778cef7fd7SEric Fiselier 
788cef7fd7SEric Fiselier       Vect v2 = std::move(v);
799a140a15SNikolas Klauser       assert(alloc_stats.count == 2);
809a140a15SNikolas Klauser       assert(alloc_stats.copied == 0);
819a140a15SNikolas Klauser       assert(alloc_stats.moved == 1);
828cef7fd7SEric Fiselier       {
838cef7fd7SEric Fiselier         const AllocT& a = v.get_allocator();
848cef7fd7SEric Fiselier         assert(a.get_id() == test_alloc_base::moved_value);
858cef7fd7SEric Fiselier         assert(a.get_data() == test_alloc_base::moved_value);
868cef7fd7SEric Fiselier       }
878cef7fd7SEric Fiselier       {
888cef7fd7SEric Fiselier         const AllocT& a = v2.get_allocator();
898cef7fd7SEric Fiselier         assert(a.get_id() == 101);
908cef7fd7SEric Fiselier         assert(a.get_data() == 42);
918cef7fd7SEric Fiselier       }
928cef7fd7SEric Fiselier     }
932df59c50SJF Bastien 
94*c74059c5SNikolas Klauser     return true;
95*c74059c5SNikolas Klauser }
96*c74059c5SNikolas Klauser 
main(int,char **)97*c74059c5SNikolas Klauser int main(int, char**)
98*c74059c5SNikolas Klauser {
99*c74059c5SNikolas Klauser     tests();
100*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
101*c74059c5SNikolas Klauser     static_assert(tests());
102*c74059c5SNikolas Klauser #endif
1032df59c50SJF Bastien     return 0;
1045a83710eSEric Fiselier }
105