Commit 18eeaec4 by Paolo Carlini Committed by Paolo Carlini

utility (get(std::pair<>&&)): Add.

2011-05-16  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/utility (get(std::pair<>&&)): Add.
	* include/bits/stl_pair.h (pair::swap(pair&),
	swap(pair<>&, pair<>&)): Use noexcept.
	* include/bits/random.h (discard_block_engine<>::base,
	independent_bits_engine<>::base, shuffle_order_engine<>::base,
	random_device::entropy): Use noexcept.
	* include/std/array: Use noexcept where appropriate.
	(get(array<>&&)): Add.
	* testsuite/23_containers/array/requirements/get.cc: New.
	* testsuite/20_util/pair/get.cc: Likewise.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-error
	line number.

From-SVN: r173798
parent f6449011
2011-05-16 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/utility (get(std::pair<>&&)): Add.
* include/bits/stl_pair.h (pair::swap(pair&),
swap(pair<>&, pair<>&)): Use noexcept.
* include/bits/random.h (discard_block_engine<>::base,
independent_bits_engine<>::base, shuffle_order_engine<>::base,
random_device::entropy): Use noexcept.
* include/std/array: Use noexcept where appropriate.
(get(array<>&&)): Add.
* testsuite/23_containers/array/requirements/get.cc: New.
* testsuite/20_util/pair/get.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-error
line number.
2011-05-15 Paolo Carlini <paolo.carlini@oracle.com> 2011-05-15 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/c++config (_GLIBCXX_NOEXCEPT, _GLIBCXX_USE_NOEXCEPT): * include/bits/c++config (_GLIBCXX_NOEXCEPT, _GLIBCXX_USE_NOEXCEPT):
......
...@@ -881,7 +881,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -881,7 +881,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* object. * object.
*/ */
const _RandomNumberEngine& const _RandomNumberEngine&
base() const base() const noexcept
{ return _M_b; } { return _M_b; }
/** /**
...@@ -1090,7 +1090,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1090,7 +1090,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* object. * object.
*/ */
const _RandomNumberEngine& const _RandomNumberEngine&
base() const base() const noexcept
{ return _M_b; } { return _M_b; }
/** /**
...@@ -1320,7 +1320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1320,7 +1320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* Gets a const reference to the underlying generator engine object. * Gets a const reference to the underlying generator engine object.
*/ */
const _RandomNumberEngine& const _RandomNumberEngine&
base() const base() const noexcept
{ return _M_b; } { return _M_b; }
/** /**
...@@ -1553,7 +1553,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1553,7 +1553,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return std::numeric_limits<result_type>::max(); } { return std::numeric_limits<result_type>::max(); }
double double
entropy() const entropy() const noexcept
{ return 0.0; } { return 0.0; }
result_type result_type
......
// Pair implementation -*- C++ -*- // Pair implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
// 2010, 2011
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -152,6 +153,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -152,6 +153,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
pair& pair&
operator=(pair&& __p) operator=(pair&& __p)
// noexcept has to wait is_nothrow_move_assignable
{ {
first = std::move(__p.first); first = std::move(__p.first);
second = std::move(__p.second); second = std::move(__p.second);
...@@ -178,6 +180,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -178,6 +180,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
swap(pair& __p) swap(pair& __p)
noexcept(noexcept(swap(first, __p.first))
&& noexcept(swap(second, __p.second)))
{ {
using std::swap; using std::swap;
swap(first, __p.first); swap(first, __p.first);
...@@ -239,6 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -239,6 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<class _T1, class _T2> template<class _T1, class _T2>
inline void inline void
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
noexcept(noexcept(__x.swap(__y)))
{ __x.swap(__y); } { __x.swap(__y); }
#endif #endif
......
// <array> -*- C++ -*- // <array> -*- C++ -*-
// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -83,66 +83,67 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -83,66 +83,67 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
swap(array& __other) swap(array& __other)
noexcept(noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())))
{ std::swap_ranges(begin(), end(), __other.begin()); } { std::swap_ranges(begin(), end(), __other.begin()); }
// Iterators. // Iterators.
iterator iterator
begin() begin() noexcept
{ return iterator(std::__addressof(_M_instance[0])); } { return iterator(std::__addressof(_M_instance[0])); }
const_iterator const_iterator
begin() const begin() const noexcept
{ return const_iterator(std::__addressof(_M_instance[0])); } { return const_iterator(std::__addressof(_M_instance[0])); }
iterator iterator
end() end() noexcept
{ return iterator(std::__addressof(_M_instance[_Nm])); } { return iterator(std::__addressof(_M_instance[_Nm])); }
const_iterator const_iterator
end() const end() const noexcept
{ return const_iterator(std::__addressof(_M_instance[_Nm])); } { return const_iterator(std::__addressof(_M_instance[_Nm])); }
reverse_iterator reverse_iterator
rbegin() rbegin() noexcept
{ return reverse_iterator(end()); } { return reverse_iterator(end()); }
const_reverse_iterator const_reverse_iterator
rbegin() const rbegin() const noexcept
{ return const_reverse_iterator(end()); } { return const_reverse_iterator(end()); }
reverse_iterator reverse_iterator
rend() rend() noexcept
{ return reverse_iterator(begin()); } { return reverse_iterator(begin()); }
const_reverse_iterator const_reverse_iterator
rend() const rend() const noexcept
{ return const_reverse_iterator(begin()); } { return const_reverse_iterator(begin()); }
const_iterator const_iterator
cbegin() const cbegin() const noexcept
{ return const_iterator(std::__addressof(_M_instance[0])); } { return const_iterator(std::__addressof(_M_instance[0])); }
const_iterator const_iterator
cend() const cend() const noexcept
{ return const_iterator(std::__addressof(_M_instance[_Nm])); } { return const_iterator(std::__addressof(_M_instance[_Nm])); }
const_reverse_iterator const_reverse_iterator
crbegin() const crbegin() const noexcept
{ return const_reverse_iterator(end()); } { return const_reverse_iterator(end()); }
const_reverse_iterator const_reverse_iterator
crend() const crend() const noexcept
{ return const_reverse_iterator(begin()); } { return const_reverse_iterator(begin()); }
// Capacity. // Capacity.
constexpr size_type constexpr size_type
size() const { return _Nm; } size() const noexcept { return _Nm; }
constexpr size_type constexpr size_type
max_size() const { return _Nm; } max_size() const noexcept { return _Nm; }
constexpr bool constexpr bool
empty() const { return size() == 0; } empty() const noexcept { return size() == 0; }
// Element access. // Element access.
reference reference
...@@ -186,11 +187,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -186,11 +187,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return _Nm ? *(end() - 1) : *end(); } { return _Nm ? *(end() - 1) : *end(); }
_Tp* _Tp*
data() data() noexcept
{ return std::__addressof(_M_instance[0]); } { return std::__addressof(_M_instance[0]); }
const _Tp* const _Tp*
data() const data() const noexcept
{ return std::__addressof(_M_instance[0]); } { return std::__addressof(_M_instance[0]); }
}; };
...@@ -228,13 +229,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -228,13 +229,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return !(__one < __two); } { return !(__one < __two); }
// Specialized algorithms [6.2.2.2]. // Specialized algorithms.
template<typename _Tp, std::size_t _Nm> template<typename _Tp, std::size_t _Nm>
inline void inline void
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
noexcept(noexcept(__one.swap(__two)))
{ __one.swap(__two); } { __one.swap(__two); }
// Tuple interface to class template array [6.2.2.5]. // Tuple interface to class template array.
/// tuple_size /// tuple_size
template<typename _Tp> template<typename _Tp>
...@@ -258,12 +260,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -258,12 +260,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<std::size_t _Int, typename _Tp, std::size_t _Nm> template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline _Tp& inline _Tp&
get(array<_Tp, _Nm>& __arr) get(array<_Tp, _Nm>& __arr) noexcept
{ return __arr[_Int]; } { return __arr[_Int]; }
template<std::size_t _Int, typename _Tp, std::size_t _Nm> template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline _Tp&&
get(array<_Tp, _Nm>&& __arr) noexcept
{ return std::move(get<_Int>(__arr)); }
template<std::size_t _Int, typename _Tp, std::size_t _Nm>
inline const _Tp& inline const _Tp&
get(const array<_Tp, _Nm>& __arr) get(const array<_Tp, _Nm>& __arr) noexcept
{ return __arr[_Int]; } { return __arr[_Int]; }
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
// <utility> -*- C++ -*- // <utility> -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
// 2010, 2011
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -108,34 +109,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -108,34 +109,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct __pair_get<0> struct __pair_get<0>
{ {
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) static _Tp1&
{ return __pair.first; } __get(std::pair<_Tp1, _Tp2>& __pair) _GLIBCXX_NOEXCEPT
{ return __pair.first; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Tp1, typename _Tp2>
static _Tp1&&
__move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
{ return std::forward<_Tp1>(__pair.first); }
#endif
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) static const _Tp1&
{ return __pair.first; } __const_get(const std::pair<_Tp1, _Tp2>& __pair) _GLIBCXX_NOEXCEPT
{ return __pair.first; }
}; };
template<> template<>
struct __pair_get<1> struct __pair_get<1>
{ {
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) static _Tp2&
{ return __pair.second; } __get(std::pair<_Tp1, _Tp2>& __pair) _GLIBCXX_NOEXCEPT
{ return __pair.second; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Tp1, typename _Tp2>
static _Tp2&&
__move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
{ return std::forward<_Tp2>(__pair.second); }
#endif
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) static const _Tp2&
{ return __pair.second; } __const_get(const std::pair<_Tp1, _Tp2>& __pair) _GLIBCXX_NOEXCEPT
{ return __pair.second; }
}; };
template<std::size_t _Int, class _Tp1, class _Tp2> template<std::size_t _Int, class _Tp1, class _Tp2>
inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
get(std::pair<_Tp1, _Tp2>& __in) get(std::pair<_Tp1, _Tp2>& __in) _GLIBCXX_NOEXCEPT
{ return __pair_get<_Int>::__get(__in); } { return __pair_get<_Int>::__get(__in); }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<std::size_t _Int, class _Tp1, class _Tp2>
inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&&
get(std::pair<_Tp1, _Tp2>&& __in) noexcept
{ return __pair_get<_Int>::__move_get(std::move(__in)); }
#endif
template<std::size_t _Int, class _Tp1, class _Tp2> template<std::size_t _Int, class _Tp1, class _Tp2>
inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
get(const std::pair<_Tp1, _Tp2>& __in) get(const std::pair<_Tp1, _Tp2>& __in) _GLIBCXX_NOEXCEPT
{ return __pair_get<_Int>::__const_get(__in); } { return __pair_get<_Int>::__const_get(__in); }
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// 2011-05-16 Paolo Carlini <paolo.carlini@oracle.com>
//
// 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
// <http://www.gnu.org/licenses/>.
#include <utility>
void test01()
{
std::pair<float, int> p;
float&& pfirst __attribute__((unused)) = std::get<0>(std::move(p));
int&& psecond __attribute__((unused)) = std::get<1>(std::move(p));
}
...@@ -56,4 +56,4 @@ main() ...@@ -56,4 +56,4 @@ main()
// { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 1050 }
// { dg-warning "note" "" { target *-*-* } 342 } // { dg-warning "note" "" { target *-*-* } 342 }
// { dg-warning "note" "" { target *-*-* } 292 } // { dg-warning "note" "" { target *-*-* } 292 }
// { dg-warning "note" "" { target *-*-* } 207 } // { dg-warning "note" "" { target *-*-* } 211 }
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// 2011-05-16 Paolo Carlini <paolo.carlini@oracle.com>
//
// 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
// <http://www.gnu.org/licenses/>.
#include <array>
void test01()
{
std::array<int, 2> a;
int&& aone __attribute__((unused)) = std::get<0>(std::move(a));
int&& atwo __attribute__((unused)) = std::get<1>(std::move(a));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment