1// Copyright (C) 2008-2015 Free Software Foundation, Inc. 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 3, or (at your option) 7// any later version. 8// 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING3. If not see 16// <http://www.gnu.org/licenses/>. 17// 18 19// { dg-options "-std=gnu++11" } 20 21#include <vector> 22#include <testsuite_allocator.h> 23 24using namespace __gnu_test; 25 26int main() 27{ 28 typedef std::vector<int, tracker_allocator<int> > Container; 29 const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; 30 bool ok = true; 31 32 tracker_allocator_counter::reset(); 33 { 34 Container c({ 2, 4, 1 }); 35 ok = check_construct_destroy("Construct from init-list", 3, 0) && ok; 36 ok &= (c[0] == 2); 37 ok &= (c[1] == 4); 38 } 39 ok = check_construct_destroy("Construct from init-list", 3, 3) && ok; 40 41 { 42 Container c(arr10, arr10 + 10); 43 tracker_allocator_counter::reset(); 44 c.insert(c.begin() + 7, { 234, 42, 1 }); 45 ok = check_construct_destroy("Insert init-list", 13, 10) && ok; 46 ok &= (c[7] == 234); 47 } 48 ok = check_construct_destroy("Insert init-list", 13, 23) && ok; 49 50 { 51 Container c; 52 tracker_allocator_counter::reset(); 53 c = { 13, 0, 42 }; 54 ok = check_construct_destroy("Assign init-list", 3, 0) && ok; 55 ok &= (c[0] == 13); 56 } 57 ok = check_construct_destroy("Assign init-list", 3, 3) && ok; 58 59 return ok ? 0 : 1;; 60} 61