From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7887 invoked by alias); 19 May 2011 20:50:14 -0000 Received: (qmail 7870 invoked by uid 22791); 19 May 2011 20:50:12 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp204.alice.it (HELO smtp204.alice.it) (82.57.200.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 May 2011 20:49:55 +0000 Received: from [192.168.1.4] (79.52.192.9) by smtp204.alice.it (8.5.124.08) id 4D7E0F6405D967AB; Thu, 19 May 2011 22:49:52 +0200 Message-ID: <4DD58236.8080508@oracle.com> Date: Fri, 20 May 2011 07:36:00 -0000 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Add cv tuple_size and tuple_element Content-Type: multipart/mixed; boundary="------------030307000100060101090406" X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01422.txt.bz2 This is a multi-part message in MIME format. --------------030307000100060101090406 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 66 Hi, tested x86_64-linux, committed. Paolo. /////////////////// --------------030307000100060101090406 Content-Type: text/plain; name="CL_cv_tuple_size_element" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="CL_cv_tuple_size_element" Content-length: 593 2011-05-19 Paolo Carlini * include/std/tuple (tuple_element<__i, const _Tp>, tuple_element<__i, volatile _Tp>, tuple_element<__i, const volatile _Tp>, tuple_size, tuple_size, tuple_size): Add. * include/std/utility (tuple_size>): Tweak. * include/std/array (tuple_size>): Likewise. * testsuite/20_util/tuple/cv_tuple_size.cc: New. * testsuite/20_util/tuple/cv_tuple_element.cc: Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-warning line number. --------------030307000100060101090406 Content-Type: text/plain; name="patch_cv_tuple_size_element" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch_cv_tuple_size_element" Content-length: 7631 Index: include/std/tuple =================================================================== --- include/std/tuple (revision 173917) +++ include/std/tuple (working copy) @@ -505,20 +505,54 @@ typedef _Head type; }; + template + struct tuple_element<__i, const _Tp> + { + typedef typename + add_const::type>::type type; + }; + + template + struct tuple_element<__i, volatile _Tp> + { + typedef typename + add_volatile::type>::type type; + }; + + template + struct tuple_element<__i, const volatile _Tp> + { + typedef typename + add_cv::type>::type type; + }; + /// Finds the size of a given tuple type. template struct tuple_size; + template + struct tuple_size + : public integral_constant< + typename remove_cv::value)>::type, + tuple_size<_Tp>::value> { }; + + template + struct tuple_size + : public integral_constant< + typename remove_cv::value)>::type, + tuple_size<_Tp>::value> { }; + + template + struct tuple_size + : public integral_constant< + typename remove_cv::value)>::type, + tuple_size<_Tp>::value> { }; + /// class tuple_size template - struct tuple_size > - { - static const std::size_t value = sizeof...(_Elements); - }; + struct tuple_size> + : public integral_constant { }; - template - const std::size_t tuple_size >::value; - template inline typename __add_ref<_Head>::type __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept Index: include/std/utility =================================================================== --- include/std/utility (revision 173917) +++ include/std/utility (working copy) @@ -88,13 +88,9 @@ // Various functions which give std::pair a tuple-like interface. template struct tuple_size> - { static const std::size_t value = 2; }; + : public integral_constant { }; template - const std::size_t - tuple_size >::value; - - template struct tuple_element<0, std::pair<_Tp1, _Tp2>> { typedef _Tp1 type; }; Index: include/std/array =================================================================== --- include/std/array (revision 173917) +++ include/std/array (working copy) @@ -242,18 +242,14 @@ template class tuple_size; + template + struct tuple_size> + : public integral_constant { }; + /// tuple_element template class tuple_element; - template - struct tuple_size > - { static const std::size_t value = _Nm; }; - - template - const std::size_t - tuple_size >::value; - template struct tuple_element<_Int, array<_Tp, _Nm> > { typedef _Tp type; }; Index: testsuite/20_util/tuple/cv_tuple_size.cc =================================================================== --- testsuite/20_util/tuple/cv_tuple_size.cc (revision 0) +++ testsuite/20_util/tuple/cv_tuple_size.cc (revision 0) @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 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 +// . + +// Tuple + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + VERIFY( tuple_size >::value == 0 ); + VERIFY( tuple_size >::value == 1 ); + VERIFY( tuple_size >::value == 1 ); + + typedef tuple test_tuple1; + VERIFY( tuple_size::value == 3 ); + VERIFY( tuple_size::value == 3 ); + VERIFY( tuple_size > >::value == 1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/20_util/tuple/cv_tuple_element.cc =================================================================== --- testsuite/20_util/tuple/cv_tuple_element.cc (revision 0) +++ testsuite/20_util/tuple/cv_tuple_element.cc (revision 0) @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2011-05-19 Paolo Carlini +// +// Copyright (C) 2011 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 +// . + +// Tuple + +#include + +using namespace std; + +static_assert(is_same>::type, + const double>::value, "Error"); +static_assert(is_same>::type, + volatile void>::value, "Error"); +static_assert(is_same>::type, const volatile int>::value, "Error"); Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 173917) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -51,7 +51,7 @@ // { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 469 } -// { dg-warning "note" "" { target *-*-* } 603 } +// { dg-warning "note" "" { target *-*-* } 637 } // { dg-warning "note" "" { target *-*-* } 1056 } // { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 342 } --------------030307000100060101090406--