From patchwork Sun Jul 12 18:45:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 494165 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EAEE11402D6 for ; Mon, 13 Jul 2015 04:45:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vjyY+z1I; dkim-atps=neutral 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=M+1HZqj/zcWiMHygNiK9YfWXHyrfChyFhiEhDRIXq2u6cK nepbyL5+P2DDKBVOaM1sMkCtzuMASkL5EYHMMtNxxmYQo6pBXqr3QxkPGPtDQh+e AqQyxw5G+G2+1LauNY4voGzOuYSEdc+JekR6U9NrFt8VevY3RepLu4cCRSZKU= 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=7ea32SK6ognFqK1tZX7xl/ZFHcc=; b=vjyY+z1IVoQTQsK4c3Kl Cr+Ws9t7zJfBbLQh+uaypweqV5zn7DS3PnkXy5JPfoTfyjpdtHLotqVa1lrxYlVC Fxgl3ryXkrciOUI+sUGKN3PuZZsnh/xQEvM7jDnHP7nlpDGmXr/4jjpS8bUWVZJ1 LejcQJ417I4mhSwk0bdfqNE= Received: (qmail 122459 invoked by alias); 12 Jul 2015 18:45:32 -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 122440 invoked by uid 89); 12 Jul 2015 18:45:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-ie0-f174.google.com Received: from mail-ie0-f174.google.com (HELO mail-ie0-f174.google.com) (209.85.223.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 12 Jul 2015 18:45:28 +0000 Received: by iecuq6 with SMTP id uq6so222934668iec.2; Sun, 12 Jul 2015 11:45:26 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.107.46.159 with SMTP id u31mr41525794iou.69.1436726726297; Sun, 12 Jul 2015 11:45:26 -0700 (PDT) Received: by 10.36.152.137 with HTTP; Sun, 12 Jul 2015 11:45:26 -0700 (PDT) Date: Sun, 12 Jul 2015 21:45:26 +0300 Message-ID: Subject: [v3 PATCH] Implement make_array and to_array from the Fundamentals v2 TS draft From: Ville Voutilainen To: libstdc++@gcc.gnu.org, "gcc-patches@gcc.gnu.org" Tested on Linux-PPC64. 2015-07-12 Ville Voutilainen Implement std::experimental::fundamentals_v2::make_array and std::experimental::fundamentals_v2::to_array. * include/Makefile.am: Add array. * include/Makefile.in: Add array. * include/experimental/array: New. * testsuite/experimental/array/make_array.cc: Likewise. * testsuite/experimental/array/neg.cc: Likewise. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 05be8ad..41fc4af 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -646,6 +646,7 @@ experimental_builddir = ./experimental experimental_headers = \ ${experimental_srcdir}/algorithm \ ${experimental_srcdir}/any \ + ${experimental_srcdir}/array \ ${experimental_srcdir}/chrono \ ${experimental_srcdir}/deque \ ${experimental_srcdir}/erase_if.h \ @@ -657,6 +658,7 @@ experimental_headers = \ ${experimental_srcdir}/memory \ ${experimental_srcdir}/numeric \ ${experimental_srcdir}/optional \ + ${experimental_srcdir}/propagate_const \ ${experimental_srcdir}/ratio \ ${experimental_srcdir}/set \ ${experimental_srcdir}/string \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index bab83b4..b2a140c 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -935,6 +935,7 @@ experimental_builddir = ./experimental experimental_headers = \ ${experimental_srcdir}/algorithm \ ${experimental_srcdir}/any \ + ${experimental_srcdir}/array \ ${experimental_srcdir}/chrono \ ${experimental_srcdir}/deque \ ${experimental_srcdir}/erase_if.h \ @@ -946,6 +947,7 @@ experimental_headers = \ ${experimental_srcdir}/memory \ ${experimental_srcdir}/numeric \ ${experimental_srcdir}/optional \ + ${experimental_srcdir}/propagate_const \ ${experimental_srcdir}/ratio \ ${experimental_srcdir}/set \ ${experimental_srcdir}/string \ diff --git a/libstdc++-v3/include/experimental/array b/libstdc++-v3/include/experimental/array new file mode 100644 index 0000000..1e1b60e --- /dev/null +++ b/libstdc++-v3/include/experimental/array @@ -0,0 +1,106 @@ +// -*- C++ -*- + +// Copyright (C) 2015 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file experimental/array + * This is a TS C++ Library header. + */ + +#ifndef _GLIBCXX_EXPERIMENTAL_ARRAY +#define _GLIBCXX_EXPERIMENTAL_ARRAY 1 + +#pragma GCC system_header + +#if __cplusplus <= 201103L +# include +#else + +#include +#include +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace experimental +{ +inline namespace fundamentals_v2 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @defgroup make_array Array creation functions + * @ingroup experimental + * + * Array creation functions as described in N4529, + * Working Draft, C++ Extensions for Library Fundamentals, Version 2 + * + * @{ + */ + +template +struct __is_reference_wrapper : false_type +{ }; + +template +struct __is_reference_wrapper> : true_type +{ }; + +template +constexpr auto make_array(_Types&&... __t) + -> array, + common_type_t<_Types...>, + _D>, + sizeof...(_Types)> +{ + static_assert(__or_<__not_>, + __and_<__not_<__is_reference_wrapper>>...>> + ::value, + "make_array cannot be used without an explicit target type " + "if any of the types given is a reference_wrapper"); + return {{__t...}}; +} + +template +constexpr array, _N> +__to_array(_Tp (&__a)[_N], + index_sequence<_Idx...>) +{ + return {{__a[_Idx]...}}; +} + +template +constexpr array, _N> to_array(_Tp (&__a)[_N]) +{ + return __to_array(__a, make_index_sequence<_N>{}); +} + + // @} group make_array + _GLIBCXX_END_NAMESPACE_VERSION +} // namespace fundamentals_v2 +} // namespace experimental + +} // namespace std + +#endif // C++14 + +#endif // _GLIBCXX_EXPERIMENTAL_ARRAY diff --git a/libstdc++-v3/testsuite/experimental/array/make_array.cc b/libstdc++-v3/testsuite/experimental/array/make_array.cc new file mode 100644 index 0000000..5a01146 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/make_array.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++14" } +// { dg-do run } + +// Copyright (C) 2015 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +int main() +{ + char x[42]; + std::array y = std::experimental::to_array(x); + std::array z = std::experimental::make_array(1,2,3,4,5); + std::array zz = std::experimental::make_array(1,2L, 3); + int dummy; + auto good = std::experimental::make_array< + std::reference_wrapper>(std::ref(dummy)); + constexpr char x2[42]{}; + constexpr std::array y2 = std::experimental::to_array(x2); + constexpr std::array z2 = + std::experimental::make_array(1,2,3,4,5); + constexpr std::array zz2 + = std::experimental::make_array(1,2L, 3); +} diff --git a/libstdc++-v3/testsuite/experimental/array/neg.cc b/libstdc++-v3/testsuite/experimental/array/neg.cc new file mode 100644 index 0000000..643466b --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/neg.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2015 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +int main() +{ + int dummy; + auto bad = std::experimental::make_array(std::ref(dummy)); + // { dg-error "make_array cannot be used without an explicit target type if any of the types given is a reference_wrapper" "" { target *-*-* } 75 } +}