1169689Skan// { dg-options "-std=gnu++11" } 2169689Skan 3169689Skan// Copyright (C) 2010-2015 Free Software Foundation, Inc. 4169689Skan// 5169689Skan// This file is part of the GNU ISO C++ Library. This library is free 6169689Skan// software; you can redistribute it and/or modify it under the 7169689Skan// terms of the GNU General Public License as published by the 8169689Skan// Free Software Foundation; either version 3, or (at your option) 9169689Skan// any later version. 10169689Skan// 11169689Skan// This library is distributed in the hope that it will be useful, 12169689Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13169689Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169689Skan// GNU General Public License for more details. 15169689Skan// 16169689Skan// You should have received a copy of the GNU General Public License along 17169689Skan// with this library; see the file COPYING3. If not see 18169689Skan// <http://www.gnu.org/licenses/>. 19169689Skan 20169689Skan// range insert 21169689Skan 22169689Skan#include <string> 23169689Skan#include <iterator> 24169689Skan#include <algorithm> 25169689Skan#include <unordered_set> 26169689Skan#include <testsuite_hooks.h> 27169689Skan 28169689Skanbool test __attribute__((unused)) = true; 29169689Skan 30169689Skanvoid test01() 31169689Skan{ 32169689Skan typedef std::unordered_set<std::string> Set; 33169689Skan Set s; 34169689Skan VERIFY(s.empty()); 35169689Skan 36169689Skan const int N = 10; 37169689Skan const std::string A[N] = { "red", "green", "blue", "violet", "cyan", 38169689Skan "magenta", "yellow", "orange", "pink", "gray" }; 39169689Skan 40169689Skan s.insert(A+0, A+N); 41169689Skan VERIFY(s.size() == static_cast<unsigned int>(N)); 42169689Skan VERIFY(std::distance(s.begin(), s.end()) == N); 43169689Skan 44169689Skan for (int i = 0; i < N; ++i) { 45169689Skan std::string str = A[i]; 46169689Skan Set::iterator it = std::find(s.begin(), s.end(), str); 47169689Skan VERIFY(it != s.end()); 48169689Skan } 49169689Skan} 50169689Skan 51169689Skanvoid test02() 52169689Skan{ 53169689Skan typedef std::unordered_set<int> Set; 54169689Skan Set s; 55169689Skan VERIFY(s.empty()); 56169689Skan 57169689Skan const int N = 8; 58169689Skan const int A[N] = { 3, 7, 4, 8, 2, 4, 6, 7 }; 59169689Skan 60169689Skan s.insert(A+0, A+N); 61169689Skan VERIFY(s.size() == 6); 62169689Skan VERIFY(std::distance(s.begin(), s.end()) == 6); 63169689Skan 64169689Skan VERIFY(std::count(s.begin(), s.end(), 2) == 1); 65169689Skan VERIFY(std::count(s.begin(), s.end(), 3) == 1); 66169689Skan VERIFY(std::count(s.begin(), s.end(), 4) == 1); 67169689Skan VERIFY(std::count(s.begin(), s.end(), 6) == 1); 68169689Skan VERIFY(std::count(s.begin(), s.end(), 7) == 1); 69169689Skan VERIFY(std::count(s.begin(), s.end(), 8) == 1); 70169689Skan} 71169689Skan 72169689Skanint main() 73169689Skan{ 74169689Skan test01(); 75169689Skan test02(); 76169689Skan return 0; 77169689Skan} 78169689Skan