From patchwork Mon Sep 27 17:29:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 65887 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]) by ozlabs.org (Postfix) with SMTP id 0126EB70DD for ; Tue, 28 Sep 2010 03:30:14 +1000 (EST) Received: (qmail 8080 invoked by alias); 27 Sep 2010 17:30:05 -0000 Received: (qmail 7864 invoked by uid 22791); 27 Sep 2010 17:30:00 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp14.tin.it (HELO vsmtp14.tin.it) (212.216.176.118) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Sep 2010 17:29:54 +0000 Received: from [192.168.0.4] (79.47.193.60) by vsmtp14.tin.it (8.5.113) id 4BCE30370CDCC022; Mon, 27 Sep 2010 19:29:50 +0200 Message-ID: <4CA0D48E.7060401@oracle.com> Date: Mon, 27 Sep 2010 19:29:50 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Thunderbird/3.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ , Jonathan Wakely Subject: [v3] Add allocator_arg_t, uses_allocator... X-IsSubscribed: yes 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 Hi, tested x86_64-linux, committed to mainline. Thanks, Paolo. PS: Jon, is there code in and elsewhere which we could enable rather easily?!? 2010-09-27 Paolo Carlini * include/bits/allocator.h (allocator_arg_t, allocator_arg, uses_allocator): Add. * testsuite/20_util/uses_allocator/value.cc: New. * testsuite/20_util/uses_allocator/requirements/typedefs.cc: Likewise. * testsuite/20_util/uses_allocator/requirements/ explicit_instantiation.cc: Likewise. * include/bits/stl_queue.h (uses_allocator, uses_allocator): Add. * include/bits/stl_stack.h (uses_allocator): Likewise. * include/bits/stl_pair.h (piecewise_construct): Add. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error line number. Index: include/bits/stl_queue.h =================================================================== --- include/bits/stl_queue.h (revision 164646) +++ include/bits/stl_queue.h (working copy) @@ -307,6 +307,10 @@ inline void swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y) { __x.swap(__y); } + + template + struct uses_allocator, _Alloc> + : public uses_allocator<_Seq, _Alloc>::type { }; #endif /** @@ -536,6 +540,11 @@ swap(priority_queue<_Tp, _Sequence, _Compare>& __x, priority_queue<_Tp, _Sequence, _Compare>& __y) { __x.swap(__y); } + + template + struct uses_allocator, _Alloc> + : public uses_allocator<_Sequence, _Alloc>::type { }; #endif _GLIBCXX_END_NAMESPACE Index: include/bits/stl_stack.h =================================================================== --- include/bits/stl_stack.h (revision 164646) +++ include/bits/stl_stack.h (working copy) @@ -282,6 +282,10 @@ inline void swap(stack<_Tp, _Seq>& __x, stack<_Tp, _Seq>& __y) { __x.swap(__y); } + + template + struct uses_allocator, _Alloc> + : public uses_allocator<_Seq, _Alloc>::type { }; #endif _GLIBCXX_END_NAMESPACE Index: include/bits/stl_pair.h =================================================================== --- include/bits/stl_pair.h (revision 164646) +++ include/bits/stl_pair.h (working copy) @@ -68,6 +68,9 @@ #ifdef __GXX_EXPERIMENTAL_CXX0X__ struct piecewise_construct_t { }; + static const piecewise_construct_t piecewise_construct + = piecewise_construct_t(); + // forward declarations template class tuple; Index: include/bits/allocator.h =================================================================== --- include/bits/allocator.h (revision 164646) +++ include/bits/allocator.h (working copy) @@ -47,6 +47,10 @@ // Define the base class to std::allocator. #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#include +#endif + _GLIBCXX_BEGIN_NAMESPACE(std) /** @@ -177,28 +181,71 @@ }; #ifdef __GXX_EXPERIMENTAL_CXX0X__ - // A very basic implementation for now. In general we have to wait for - // the availability of the infrastructure described in N2983: we should - // try when either T has a move constructor which cannot throw or T is - // CopyContructible. - // NB: This code doesn't properly belong here, we should find a more - // suited place common to std::vector and std::deque. - template - struct __shrink_to_fit - { static void _S_do_it(_Tp&) { } }; + // A very basic implementation for now. In general we have to wait for + // the availability of the infrastructure described in N2983: we should + // try when either T has a move constructor which cannot throw or T is + // CopyContructible. + // NB: This code doesn't properly belong here, we should find a more + // suited place common to std::vector and std::deque. + template + struct __shrink_to_fit + { static void _S_do_it(_Tp&) { } }; - template - struct __shrink_to_fit<_Tp, true> - { - static void - _S_do_it(_Tp& __v) - { - __try - { _Tp(__v).swap(__v); } - __catch(...) { } - } - }; + template + struct __shrink_to_fit<_Tp, true> + { + static void + _S_do_it(_Tp& __v) + { + __try + { _Tp(__v).swap(__v); } + __catch(...) { } + } + }; + + + /// [allocator.tag] + struct allocator_arg_t { }; + + static const allocator_arg_t allocator_arg = allocator_arg_t(); + + template + class __has_allocator_type + : public __sfinae_types + { + template + struct _Wrap_type + { }; + + template + static __one __test(_Wrap_type*); + + template + static __two __test(...); + + public: + static const bool __value = sizeof(__test<_Tp>(0)) == 1; + }; + + template::__value> + struct __uses_allocator_helper + : public false_type { }; + + template + struct __uses_allocator_helper<_Tp, _Alloc, true> + : public integral_constant::value> + { }; + + /// [allocator.uses.trait] + template + struct uses_allocator + : public integral_constant::value> + { }; + #endif _GLIBCXX_END_NAMESPACE Index: testsuite/20_util/uses_allocator/value.cc =================================================================== --- testsuite/20_util/uses_allocator/value.cc (revision 0) +++ testsuite/20_util/uses_allocator/value.cc (revision 0) @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-09-27 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include +#include +#include + +struct MyAlloc { }; + +struct MyDerivedAlloc +: public MyAlloc { }; + +struct UA { }; + +struct UB { typedef int allocator_type; }; + +struct UC { typedef MyAlloc allocator_type; }; + +struct UD { typedef MyDerivedAlloc allocator_type; }; + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::uses_allocator; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true))); + + // Negative tests. + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/20_util/uses_allocator/requirements/typedefs.cc =================================================================== --- testsuite/20_util/uses_allocator/requirements/typedefs.cc (revision 0) +++ testsuite/20_util/uses_allocator/requirements/typedefs.cc (revision 0) @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-09-27 Paolo Carlini +// +// Copyright (C) 2010 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 +// . + +#include + +void test01() +{ + // Check for required typedefs + typedef std::uses_allocator test_type; + typedef test_type::value_type value_type; + typedef test_type::type type; + typedef test_type::type::value_type type_value_type; + typedef test_type::type::type type_type; +} Index: testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc =================================================================== --- testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc (revision 0) +++ testsuite/20_util/uses_allocator/requirements/explicit_instantiation.cc (revision 0) @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-09-27 Paolo Carlini + +// Copyright (C) 2010 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 +// . + +#include + +namespace std +{ + typedef short test_type; + template struct uses_allocator; +} Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc =================================================================== --- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (revision 164646) +++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc (working copy) @@ -48,4 +48,4 @@ // { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 340 } // { dg-warning "note" "" { target *-*-* } 290 } -// { dg-warning "note" "" { target *-*-* } 197 } +// { dg-warning "note" "" { target *-*-* } 200 }