struct __add_ref<_Tp&>
{ typedef _Tp& type; };
+ // Adds an rvalue reference to a non-reference type.
+ template<typename _Tp>
+ struct __add_r_ref
+ { typedef _Tp&& type; };
+
+ template<typename _Tp>
+ struct __add_r_ref<_Tp&>
+ { typedef _Tp& type; };
+
template<std::size_t _Idx, typename _Head, bool _IsEmpty>
struct _Head_base;
_Head& _M_head() { return *this; }
const _Head& _M_head() const { return *this; }
-
- void
- _M_swap_impl(_Head& __h)
- {
- using std::swap;
- swap(__h, _M_head());
- }
};
template<std::size_t _Idx, typename _Head>
_Head& _M_head() { return _M_head_impl; }
const _Head& _M_head() const { return _M_head_impl; }
- void
- _M_swap_impl(_Head& __h)
- {
- using std::swap;
- swap(__h, _M_head());
- }
-
_Head _M_head_impl;
};
*/
template<std::size_t _Idx>
struct _Tuple_impl<_Idx>
- {
+ {
+ template<std::size_t, typename...> friend class _Tuple_impl;
+
protected:
- void _M_swap_impl(_Tuple_impl&) { /* no-op */ }
+ void _M_swap(_Tuple_impl&) noexcept { /* no-op */ }
};
/**
: public _Tuple_impl<_Idx + 1, _Tail...>,
private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
{
+ template<std::size_t, typename...> friend class _Tuple_impl;
+
typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base;
protected:
void
- _M_swap_impl(_Tuple_impl& __in)
+ _M_swap(_Tuple_impl& __in)
+ noexcept(noexcept(swap(std::declval<_Head&>(),
+ std::declval<_Head&>()))
+ && noexcept(__in._M_tail()._M_swap(__in._M_tail())))
{
- _Base::_M_swap_impl(__in._M_head());
- _Inherited::_M_swap_impl(__in._M_tail());
+ using std::swap;
+ swap(this->_M_head(), __in._M_head());
+ _Inherited::_M_swap(__in._M_tail());
}
};
void
swap(tuple& __in)
- { _Inherited::_M_swap_impl(__in); }
+ noexcept(noexcept(__in._M_swap(__in)))
+ { _Inherited::_M_swap(__in); }
};
template<>
class tuple<>
{
public:
- void swap(tuple&) { /* no-op */ }
+ void swap(tuple&) noexcept { /* no-op */ }
};
/// tuple (2-element), with construction and assignment from a pair.
tuple&
operator=(tuple&& __in)
+ // noexcept has to wait is_nothrow_move_assignable
{
static_cast<_Inherited&>(*this) = std::move(__in);
return *this;
template<typename _U1, typename _U2>
tuple&
- operator=(pair<_U1, _U2>&& __in)
+ operator=(pair<_U1, _U2>&& __in) noexcept
{
this->_M_head() = std::forward<_U1>(__in.first);
this->_M_tail()._M_head() = std::forward<_U2>(__in.second);
void
swap(tuple& __in)
- {
- using std::swap;
- swap(this->_M_head(), __in._M_head());
- swap(this->_M_tail()._M_head(), __in._M_tail()._M_head());
- }
+ noexcept(noexcept(__in._M_swap(__in)))
+ { _Inherited::_M_swap(__in); }
};
/// tuple (1-element).
void
swap(tuple& __in)
- { _Inherited::_M_swap_impl(__in); }
+ noexcept(noexcept(__in._M_swap(__in)))
+ { _Inherited::_M_swap(__in); }
};
__get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t)
{ return __t._M_head(); }
- // Return a reference (const reference) to the ith element of a tuple.
- // Any const or non-const ref elements are returned with their original type.
+ // Return a reference (const reference, rvalue reference) to the ith element
+ // of a tuple. Any const or non-const ref elements are returned with their
+ // original type.
template<std::size_t __i, typename... _Elements>
inline typename __add_ref<
- typename tuple_element<__i, tuple<_Elements...> >::type
+ typename tuple_element<__i, tuple<_Elements...>>::type
>::type
- get(tuple<_Elements...>& __t)
+ get(tuple<_Elements...>& __t) noexcept
{ return __get_helper<__i>(__t); }
template<std::size_t __i, typename... _Elements>
inline typename __add_c_ref<
- typename tuple_element<__i, tuple<_Elements...> >::type
+ typename tuple_element<__i, tuple<_Elements...>>::type
>::type
- get(const tuple<_Elements...>& __t)
+ get(const tuple<_Elements...>& __t) noexcept
{ return __get_helper<__i>(__t); }
+ template<std::size_t __i, typename... _Elements>
+ inline typename __add_r_ref<
+ typename tuple_element<__i, tuple<_Elements...>>::type
+ >::type
+ get(tuple<_Elements...>&& __t) noexcept
+ { return std::forward<typename tuple_element<__i,
+ tuple<_Elements...>>::type&&>(get<__i>(__t)); }
+
// This class helps construct the various comparison operations on tuples
template<std::size_t __check_equal_size, std::size_t __i, std::size_t __j,
typename _Tp, typename _Up>
template<typename... _Elements>
inline tuple<_Elements&&...>
- forward_as_tuple(_Elements&&... __args)
+ forward_as_tuple(_Elements&&... __args) noexcept
{ return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
template<std::size_t...> struct __index_holder { };
template<typename... _Elements>
inline tuple<_Elements&...>
- tie(_Elements&... __args)
+ tie(_Elements&... __args) noexcept
{ return tuple<_Elements&...>(__args...); }
template<typename... _Elements>
inline void
swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
+ noexcept(noexcept(__x.swap(__y)))
{ __x.swap(__y); }
// A class (and instance) which can be used in 'tie' when an element
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2011-05-17 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 <tuple>
+
+void test01()
+{
+ std::tuple<int> t1;
+
+ int&& t1one __attribute__((unused)) = std::get<0>(std::move(t1));
+
+ std::tuple<float, int> t2;
+
+ float&& t2one __attribute__((unused)) = std::get<0>(std::move(t2));
+ int&& t2two __attribute__((unused)) = std::get<1>(std::move(t2));
+
+ std::tuple<short, int, double> t3;
+
+ short&& t3one __attribute__((unused)) = std::get<0>(std::move(t3));
+ int&& t3two __attribute__((unused)) = std::get<1>(std::move(t3));
+ double&& t3thr __attribute__((unused)) = std::get<2>(std::move(t3));
+}