[Patch] Clean up tr1/tuple

Doug Gregor doug.gregor@gmail.com
Tue Mar 13 18:49:00 GMT 2007


On 3/12/07, Paolo Carlini <pcarlini@suse.de> wrote:
> Tested x86_64-linux. Doug, can you double check?

Looks good. A few minor questions...

> - // Returns a const reference to the ith element of a tuple.
> - // Any const or non-const ref elements are returned with their original type.
> - template<int __i, typename _Head, typename... _Tail>
> -   inline typename __add_ref<_Head>::type
> -     get(_Tuple_impl<__i, _Head, _Tail...>& __t)
> -     {
> -       return __t._M_head;
> -     }
> +  // Returns a const reference to the ith element of a tuple.
> +  // Any const or non-const ref elements are returned with their original type.
> +  template<int __i, typename _Head, typename... _Tail>
> +    inline typename __add_ref<_Head>::type
> +    get(_Tuple_impl<__i, _Head, _Tail...>& __t)
> +    {
> +      return __t._M_head;
> +    }
>
> - template<int __i, typename _Head, typename... _Tail>
> -   inline typename __add_c_ref<_Head>::type
> -     get(const _Tuple_impl<__i, _Head, _Tail...>& __t)
> -     {
> -       return __t._M_head;
> -     }
> +  template<int __i, typename _Head, typename... _Tail>
> +    inline typename __add_c_ref<_Head>::type
> +    get(const _Tuple_impl<__i, _Head, _Tail...>& __t)
> +    {
> +      return __t._M_head;
> +    }

Chris mention this when I originally submitted the patch for variadic
templates, but I want to mention it again: we're relying on a
base-class conversion for calls to get(), because we don't provide the
exact signature described in TR1, e.g.,

  template<int __i, typename... _Elements>
  inline typename __add_c_ref<typename tuple_element<__i,
tuple<_Elements...> >::type>::type
  get(const tuple<_Elements...>& t);

Should we rename the get()'s above to __get_helper, and put in
forwarding get()'s with exact signatures?

The down side is that the get()'s using the _Tuple_impl base
conversion require O(1) instantiations, while the forwarding get()
relies on tuple_element... which needs O(I) instantiations. On the up
side, if/when we get decltype, tuple_element becomes O(1)
instantiations.

> - // A class (and instance) which can be used in 'tie' when an element
> - // of a tuple is not required
> - struct swallow_assign
> - {
> -   template<class T>
> -   swallow_assign&
> -     operator=(const T&)
> -     { return *this; }
> - };
> +  // A class (and instance) which can be used in 'tie' when an element
> +  // of a tuple is not required
> +  struct swallow_assign
> +  {
> +    template<class T>
> +      swallow_assign&
> +      operator=(const T&)
> +      { return *this; }
> +  };

I think swallow_assign needs to be uglified.

  Cheers,
  Doug



More information about the Libstdc++ mailing list