// <tuple> -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007-2014 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__
+#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <utility>
+#include <array>
#include <bits/uses_allocator.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+ /**
+ * @addtogroup utilities
+ * @{
+ */
+
// Adds a const reference to a non-reference type.
template<typename _Tp>
struct __add_c_ref
struct __add_r_ref<_Tp&>
{ typedef _Tp& type; };
- // To work around c++/49225 aka c++/48322.
- template<typename...>
- struct __conv_types { };
-
- template<typename _Tuple1, typename _Tuple2>
- struct __one_by_one_convertible
- : public false_type { };
-
- template<typename _Tp, typename _Up>
- struct __one_by_one_convertible<__conv_types<_Tp>, __conv_types<_Up>>
- : public is_convertible<_Tp, _Up>::type { };
-
- template<typename _T1, typename... _TR, typename _U1, typename... _UR>
- struct __one_by_one_convertible<__conv_types<_T1, _TR...>,
- __conv_types<_U1, _UR...>>
- : public __and_<is_convertible<_T1, _U1>,
- __one_by_one_convertible<__conv_types<_TR...>,
- __conv_types<_UR...>>>::type
- { };
-
- template<typename _Tuple1, typename _Tuple2>
- struct __all_convertible;
-
- template<typename... _TTypes, typename... _UTypes>
- struct __all_convertible<__conv_types<_TTypes...>,
- __conv_types<_UTypes...>>
- : public __one_by_one_convertible<__conv_types<_TTypes...>,
- __conv_types<_UTypes...>>::type { };
-
- template<std::size_t _Idx, typename _Head, bool _IsEmpty>
+ template<std::size_t _Idx, typename _Head, bool _IsEmptyNotFinal>
struct _Head_base;
template<std::size_t _Idx, typename _Head>
void _M_swap(_Tuple_impl&) noexcept { /* no-op */ }
};
+ template<typename _Tp>
+ struct __is_empty_non_tuple : is_empty<_Tp> { };
+
+ // Using EBO for elements that are tuples causes ambiguous base errors.
+ template<typename _El0, typename... _El>
+ struct __is_empty_non_tuple<tuple<_El0, _El...>> : false_type { };
+
+ // Use the Empty Base-class Optimization for empty, non-final types.
+ template<typename _Tp>
+ using __empty_not_final
+ = typename conditional<__is_final(_Tp), false_type,
+ __is_empty_non_tuple<_Tp>>::type;
+
/**
* Recursive tuple implementation. Here we store the @c Head element
* and derive from a @c Tuple_impl containing the remaining elements
template<std::size_t _Idx, typename _Head, typename... _Tail>
struct _Tuple_impl<_Idx, _Head, _Tail...>
: public _Tuple_impl<_Idx + 1, _Tail...>,
- private _Head_base<_Idx, _Head, std::is_empty<_Head>::value>
+ private _Head_base<_Idx, _Head, __empty_not_final<_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;
+ typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
static constexpr _Head&
_M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
constexpr _Tuple_impl(const _Tuple_impl&) = default;
+ constexpr
_Tuple_impl(_Tuple_impl&& __in)
noexcept(__and_<is_nothrow_move_constructible<_Head>,
is_nothrow_move_constructible<_Inherited>>::value)
_Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
template<typename _UHead, typename... _UTails>
- _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
- : _Inherited(std::move
- (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
+ constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
+ : _Inherited(std::move
+ (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
_Base(std::forward<_UHead>
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
: _Inherited(__elements...) { }
template<typename... _UElements, typename = typename
- enable_if<__and_<integral_constant<bool, sizeof...(_UElements)
- == sizeof...(_Elements)>,
- __all_convertible<__conv_types<_UElements...>,
- __conv_types<_Elements...>>
- >::value>::type>
+ enable_if<__and_<is_convertible<_UElements,
+ _Elements>...>::value>::type>
explicit
constexpr tuple(_UElements&&... __elements)
: _Inherited(std::forward<_UElements>(__elements)...) { }
constexpr tuple(tuple&&) = default;
template<typename... _UElements, typename = typename
- enable_if<__and_<integral_constant<bool, sizeof...(_UElements)
- == sizeof...(_Elements)>,
- __all_convertible<__conv_types<const _UElements&...>,
- __conv_types<_Elements...>>
- >::value>::type>
+ enable_if<__and_<is_convertible<const _UElements&,
+ _Elements>...>::value>::type>
constexpr tuple(const tuple<_UElements...>& __in)
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements, typename = typename
- enable_if<__and_<integral_constant<bool, sizeof...(_UElements)
- == sizeof...(_Elements)>,
- __all_convertible<__conv_types<_UElements...>,
- __conv_types<_Elements...>>
- >::value>::type>
+ enable_if<__and_<is_convertible<_UElements,
+ _Elements>...>::value>::type>
constexpr tuple(tuple<_UElements...>&& __in)
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
template<typename _U1, typename _U2, typename = typename
enable_if<__and_<is_convertible<_U1, _T1>,
is_convertible<_U2, _T2>>::value>::type>
- constexpr tuple(pair<_U1, _U2>&& __in)
+ constexpr tuple(pair<_U1, _U2>&& __in)
: _Inherited(std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { }
{ return std::forward<typename tuple_element<__i,
tuple<_Elements...>>::type&&>(get<__i>(__t)); }
+#if __cplusplus > 201103L
+ template<typename _Head, size_t __i, typename... _Tail>
+ constexpr typename __add_ref<_Head>::type
+ __get_helper2(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
+ { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
+
+ template<typename _Head, size_t __i, typename... _Tail>
+ constexpr typename __add_c_ref<_Head>::type
+ __get_helper2(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
+ { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
+
+ template <typename _Tp, typename... _Types>
+ constexpr _Tp&
+ get(tuple<_Types...>& __t) noexcept
+ { return __get_helper2<_Tp>(__t); }
+
+ template <typename _Tp, typename... _Types>
+ constexpr _Tp&&
+ get(tuple<_Types...>&& __t) noexcept
+ { return std::move(__get_helper2<_Tp>(__t)); }
+
+ template <typename _Tp, typename... _Types>
+ constexpr const _Tp&
+ get(const tuple<_Types...>& __t) noexcept
+ { return __get_helper2<_Tp>(__t); }
+#endif
+
// 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<std::size_t __i, std::size_t __j, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __j, _Tp, _Up>
{
- static bool
+ static constexpr bool
__eq(const _Tp& __t, const _Up& __u)
{
return (get<__i>(__t) == get<__i>(__u) &&
__tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
}
- static bool
+ static constexpr bool
__less(const _Tp& __t, const _Up& __u)
{
return ((get<__i>(__t) < get<__i>(__u))
template<std::size_t __i, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __i, _Tp, _Up>
{
- static bool
+ static constexpr bool
__eq(const _Tp&, const _Up&) { return true; }
- static bool
+ static constexpr bool
__less(const _Tp&, const _Up&) { return false; }
};
template<typename... _TElements, typename... _UElements>
- bool
+ constexpr bool
operator==(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{
typedef tuple<_TElements...> _Tp;
typedef tuple<_UElements...> _Up;
- return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
+ return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
}
template<typename... _TElements, typename... _UElements>
- bool
+ constexpr bool
operator<(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{
typedef tuple<_TElements...> _Tp;
typedef tuple<_UElements...> _Up;
- return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
+ return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value,
0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
}
template<typename... _TElements, typename... _UElements>
- inline bool
+ constexpr bool
operator!=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__t == __u); }
template<typename... _TElements, typename... _UElements>
- inline bool
+ constexpr bool
operator>(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return __u < __t; }
template<typename... _TElements, typename... _UElements>
- inline bool
+ constexpr bool
operator<=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__u < __t); }
template<typename... _TElements, typename... _UElements>
- inline bool
+ constexpr bool
operator>=(const tuple<_TElements...>& __t,
const tuple<_UElements...>& __u)
{ return !(__t < __u); }
// NB: DR 705.
template<typename... _Elements>
- inline tuple<typename __decay_and_strip<_Elements>::__type...>
+ constexpr tuple<typename __decay_and_strip<_Elements>::__type...>
make_tuple(_Elements&&... __args)
{
typedef tuple<typename __decay_and_strip<_Elements>::__type...>
}
template<typename... _Elements>
- inline tuple<_Elements&&...>
+ tuple<_Elements&&...>
forward_as_tuple(_Elements&&... __args) noexcept
{ return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
-
- template<typename, std::size_t> struct array;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp& get(array<_Tp, _Nm>&) noexcept;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr _Tp&& get(array<_Tp, _Nm>&&) noexcept;
-
- template<std::size_t _Int, typename _Tp, std::size_t _Nm>
- constexpr const _Tp& get(const array<_Tp, _Nm>&) noexcept;
-
template<typename>
struct __is_tuple_like_impl : false_type
{ };
<typename std::remove_reference<_Tp>::type>::type>::type
{ };
- // Stores a tuple of indices. Also used by bind() to extract the elements
- // in a tuple.
- template<std::size_t... _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;
- };
-
template<std::size_t, typename, typename, std::size_t>
struct __make_tuple_impl;
}
};
+ /// tuple_cat
template<typename... _Tpls, typename = typename
enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
constexpr auto
return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
}
+ /// tie
template<typename... _Elements>
inline tuple<_Elements&...>
tie(_Elements&... __args) noexcept
{ return tuple<_Elements&...>(__args...); }
+ /// swap
template<typename... _Elements>
inline void
swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
// 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<typename... _Args1, typename... _Args2>
+ inline
+ pair<_T1, _T2>::
+ pair(piecewise_construct_t,
+ tuple<_Args1...> __first, tuple<_Args2...> __second)
+ : pair(__first, __second,
+ typename _Build_index_tuple<sizeof...(_Args1)>::__type(),
+ typename _Build_index_tuple<sizeof...(_Args2)>::__type())
+ { }
template<class _T1, class _T2>
- template<typename _Tp, typename... _Args, std::size_t... _Indexes>
- inline _Tp
- pair<_T1, _T2>::__do_cons(tuple<_Args...>&& __tuple,
- const _Index_tuple<_Indexes...>&)
- { return _Tp(std::forward<_Args>(get<_Indexes>(__tuple))...); }
+ template<typename... _Args1, std::size_t... _Indexes1,
+ typename... _Args2, std::size_t... _Indexes2>
+ inline
+ pair<_T1, _T2>::
+ pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
+ _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
+ : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
+ second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
+ { }
+
+ /// @}
_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace
+} // namespace std
-#endif // __GXX_EXPERIMENTAL_CXX0X__
+#endif // C++11
#endif // _GLIBCXX_TUPLE