From 76aa78e9eb7ade737abc19cbea1bcd690170b039 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 8 Jun 2011 11:07:24 +0000 Subject: [PATCH] allocator.h (__shrink_to_fit): Simplify. 2011-06-08 Paolo Carlini * include/bits/allocator.h (__shrink_to_fit): Simplify. * include/bits/stl_vector.h (vector<>::shrink_to_fit): Adjust. * include/bits/stl_deque.h: Likewise. * include/bits/stl_bvector.h: Likewise. From-SVN: r174802 --- libstdc++-v3/ChangeLog | 13 +++++++++-- libstdc++-v3/include/bits/allocator.h | 30 +++++++++---------------- libstdc++-v3/include/bits/stl_bvector.h | 2 +- libstdc++-v3/include/bits/stl_deque.h | 2 +- libstdc++-v3/include/bits/stl_vector.h | 2 +- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b259e9a9782..e456f596469 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2011-06-08 Paolo Carlini + + * include/bits/allocator.h (__shrink_to_fit): Simplify. + * include/bits/stl_vector.h (vector<>::shrink_to_fit): Adjust. + * include/bits/stl_deque.h: Likewise. + * include/bits/stl_bvector.h: Likewise. + 2011-06-07 Jason Merrill * testsuite/lib/prune.exp: s/required/instantiated/. @@ -7,7 +14,8 @@ * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise. * testsuite/20_util/forward/1_neg.cc: Likewise. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise. - * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. + * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: + Likewise. * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Likewise. * testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise. * testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc: Likewise. @@ -17,7 +25,8 @@ * testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Likewise. * testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Likewise. * testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Likewise. - * testsuite/tr1/2_general_utilities/shared_ptr/assign/shared_ptr_neg.cc: Likewise. + * testsuite/tr1/2_general_utilities/shared_ptr/assign/ + shared_ptr_neg.cc: Likewise. 2011-06-07 Paolo Carlini diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 6fccba51bb1..4fc14105cd3 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -184,28 +184,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; #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 - // CopyConstructible. - // 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> + bool + __shrink_to_fit(_Tp& __v) { - static void - _S_do_it(_Tp& __v) - { - __try - { _Tp(__v).swap(__v); } - __catch(...) { } - } - }; + __try + { + _Tp(__v).swap(__v); + return true; + } + __catch(...) + { return false; } + } template class __alloctr_rebind_helper diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index edf662987cb..30e7b2d9675 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -844,7 +844,7 @@ template #ifdef __GXX_EXPERIMENTAL_CXX0X__ void shrink_to_fit() - { std::__shrink_to_fit::_S_do_it(*this); } + { std::__shrink_to_fit(*this); } #endif void diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 7ddfbc5ac16..fab63f130c8 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -1196,7 +1196,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** A non-binding request to reduce memory use. */ void shrink_to_fit() - { std::__shrink_to_fit::_S_do_it(*this); } + { std::__shrink_to_fit(*this); } #endif /** diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 5fa5f522e0c..4f617861e8f 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -646,7 +646,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** A non-binding request to reduce capacity() to size(). */ void shrink_to_fit() - { std::__shrink_to_fit::_S_do_it(*this); } + { std::__shrink_to_fit(*this); } #endif /** -- 2.30.2