From patchwork Fri Nov 15 16:34:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 291617 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A48C52C009E for ; Sat, 16 Nov 2013 03:36:02 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=gneYgrsSZtjkBnptpPyKB3ZMpDDvVLbM/zR6+/np5Bw5Qu 6FUeyv3dWZE15hgD6kZhke5uHOZukd71sYvi1ZW1/ieUFE7O+K++gPEB5i574Iv0 GXem5cpuIdxmXRav6b2japcWKWfd0eGnscyuQ/ARTlvze2Uf8Wm0Vjaa7hGgA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=FpEKC3kFNW6rbmEPaT95zz9r1dk=; b=aIBKfMkn2vaxDgkUUl9w hJtQ7trndq/e9/sRTBQK+eNAcf5j28a8hDVFNpQlV6gziTlhg+I/hNWkYRqxeBLf aPgHIJ2lydh35UTkj2c0XGzUsx1IQs13I5R1VAjZHV4+Yww5m+DjoJFCC6Kx+0y8 emep384FqloH47qv7LqJRR8= Received: (qmail 2508 invoked by alias); 15 Nov 2013 16:35:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2484 invoked by uid 89); 15 Nov 2013 16:35:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lb0-f169.google.com Received: from Unknown (HELO mail-lb0-f169.google.com) (209.85.217.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 15 Nov 2013 16:34:41 +0000 Received: by mail-lb0-f169.google.com with SMTP id x18so1735130lbi.14 for ; Fri, 15 Nov 2013 08:34:31 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.152.245.1 with SMTP id xk1mr323477lac.49.1384533271535; Fri, 15 Nov 2013 08:34:31 -0800 (PST) Received: by 10.112.173.195 with HTTP; Fri, 15 Nov 2013 08:34:31 -0800 (PST) Date: Fri, 15 Nov 2013 16:34:31 +0000 Message-ID: Subject: [v3 patch] add emplace members to vector From: Jonathan Wakely To: "libstdc++" , gcc-patches Implement LWG 2187. * include/bits/stl_bvector.h (vector::emplace_back()): LWG 2187: Define. (vector::emplace()): Likewise. * testsuite/23_containers/vector/bool/emplace.cc: New. Teted x86_64-linux, committed to trunk. diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 8e4b023..3b5a0c2 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -971,7 +971,18 @@ template clear() _GLIBCXX_NOEXCEPT { _M_erase_at_end(begin()); } - +#if __cplusplus >= 201103L + template + void + emplace_back(_Args&&... __args) + { push_back(bool(__args...)); } + + template + iterator + emplace(const_iterator __pos, _Args&&... __args) + { return insert(__pos, bool(__args...)); } +#endif + protected: // Precondition: __first._M_offset == 0 && __result._M_offset == 0. iterator diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/emplace.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace.cc new file mode 100644 index 0000000..f44ea1f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/emplace.cc @@ -0,0 +1,51 @@ +// { dg-options " -std=gnu++11 " } + +// Copyright (C) 2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.3.8 class vector + +#include +#include + +void test01() +{ + std::vector v; + v.emplace_back(); + VERIFY( v[0] == false ); + v.emplace_back(1); + VERIFY( v[1] == true ); + VERIFY( v.size() == 2 ); +} + +void test02() +{ + std::vector v; + auto it = v.emplace(v.cbegin()); + VERIFY( it == v.begin() ); + VERIFY( *it == false ); + it = v.emplace(it, 1); + VERIFY( it == v.begin() ); + VERIFY( *it == true ); + VERIFY( v.size() == 2 ); +} + +int main() +{ + test01(); + test02(); +}