// <tuple> -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 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
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
-# include <c++0x_warning.h>
+# include <bits/c++0x_warning.h>
#else
#include <utility>
tuple(_UElements&&... __elements)
: _Inherited(std::forward<_UElements>(__elements)...) { }
- tuple(const tuple& __in)
- : _Inherited(static_cast<const _Inherited&>(__in)) { }
+ tuple(const tuple&) = default;
tuple(tuple&& __in)
: _Inherited(static_cast<_Inherited&&>(__in)) { }
tuple(_U1&& __a1, _U2&& __a2)
: _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
- tuple(const tuple& __in)
- : _Inherited(static_cast<const _Inherited&>(__in)) { }
+ tuple(const tuple&) = default;
tuple(tuple&& __in)
: _Inherited(static_cast<_Inherited&&>(__in)) { }
template<typename _U1, typename _U2>
tuple(pair<_U1, _U2>&& __in)
- : _Inherited(std::move(__in.first), std::move(__in.second)) { }
+ : _Inherited(std::forward<_U1>(__in.first),
+ std::forward<_U2>(__in.second)) { }
tuple&
operator=(const tuple& __in)
return __result_type(std::forward<_Elements>(__args)...);
}
+ template<typename _Tp, bool = is_array<_Tp>::value>
+ struct __pa_add_rvalue_reference_helper
+ { typedef typename std::add_rvalue_reference<_Tp>::type __type; };
+
+ template<typename _Tp>
+ struct __pa_add_rvalue_reference_helper<_Tp, true>
+ { typedef _Tp& __type; };
+
+ template<typename _Tp>
+ struct __pa_add_rvalue_reference
+ : public __pa_add_rvalue_reference_helper<_Tp>
+ { };
+
+ template<typename... _Elements>
+ inline tuple<typename __pa_add_rvalue_reference<_Elements>::__type...>
+ pack_arguments(_Elements&&... __args)
+ {
+ typedef tuple<typename __pa_add_rvalue_reference<_Elements>::__type...>
+ __result_type;
+ return __result_type(std::forward<_Elements>(__args)...);
+ }
+
template<std::size_t...> struct __index_holder { };
template<std::size_t __i, typename _IdxHolder, typename... _Elements>
struct _Swallow_assign
{
template<class _Tp>
- _Swallow_assign&
- operator=(const _Tp&)
+ const _Swallow_assign&
+ operator=(const _Tp&) const
{ return *this; }
};
- // TODO: Put this in some kind of shared file.
- namespace
- {
- _Swallow_assign ignore;
- }; // anonymous namespace
+ const _Swallow_assign ignore{};
+
+ /**
+ * Stores a tuple of indices. Used by bind() to extract the elements
+ * in a tuple.
+ */
+ template<int... _Indexes>
+ struct _Index_tuple
+ {
+ typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
+ };
+
+ /// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
+ template<std::size_t _Num>
+ struct _Build_index_tuple
+ {
+ typedef typename _Build_index_tuple<_Num-1>::__type::__next __type;
+ };
+
+ template<>
+ struct _Build_index_tuple<0>
+ {
+ typedef _Index_tuple<> __type;
+ };
+
+ // See stl_pair.h...
+ template<class _T1, class _T2>
+ template<typename _Tp, typename... _Args>
+ inline _Tp
+ pair<_T1, _T2>::
+ __cons(tuple<_Args...>&& __tuple)
+ {
+ typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
+ _Indexes;
+ return __do_cons<_Tp>(std::move(__tuple), _Indexes());
+ }
+
+ template<class _T1, class _T2>
+ template<typename _Tp, typename... _Args, int... _Indexes>
+ inline _Tp
+ pair<_T1, _T2>::
+ __do_cons(tuple<_Args...>&& __tuple,
+ const _Index_tuple<_Indexes...>&)
+ { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
}
#endif // __GXX_EXPERIMENTAL_CXX0X__