From: Paolo Carlini Date: Fri, 23 May 2008 23:08:41 +0000 (+0000) Subject: tuple: Replace int -> size_t throughout per DR 775. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=740508bee20b9ca226fddfa76007623e2d11403e;p=gcc.git tuple: Replace int -> size_t throughout per DR 775. 2008-05-23 Paolo Carlini * include/std/tuple: Replace int -> size_t throughout per DR 775. * include/tr1_impl/array: Likewise. * include/tr1_impl/utility: Likewise. * doc/xml/manual/intro.xml: Add an entry for DR 775. From-SVN: r135834 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8d83a2483d3..ca2eb74234a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2008-05-23 Paolo Carlini + + * include/std/tuple: Replace int -> size_t throughout per DR 775. + * include/tr1_impl/array: Likewise. + * include/tr1_impl/utility: Likewise. + * doc/xml/manual/intro.xml: Add an entry for DR 775. + 2008-05-23 Paolo Carlini * doc/xml/manual/intro.xml: Adjust links to ISO documents. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 1596c3b3feb..0287c9e5562 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -635,6 +635,12 @@ In C++0x mode, add at() and at() const. + 775: + Tuple indexing should be unsigned? + + Implement the int -> size_t replacements. + + 778: std::bitset does not have any constructor taking a string literal diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 38a6bbb47f2..83a81ee497a 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -62,10 +62,10 @@ namespace std struct __add_ref<_Tp&> { typedef _Tp& type; }; - template + template struct _Head_base; - template + template struct _Head_base<_Idx, _Head, true> : public _Head { @@ -83,7 +83,7 @@ namespace std const _Head& _M_head() const { return *this; } }; - template + template struct _Head_base<_Idx, _Head, false> { _Head_base() @@ -110,14 +110,14 @@ namespace std * point in the hierarchy; we use it to implement a constant-time * get() operation. */ - template + template struct _Tuple_impl; /** * Zero-element tuple implementation. This is the basis case for the * inheritance recursion. */ - template + template struct _Tuple_impl<_Idx> { }; /** @@ -125,7 +125,7 @@ namespace std * and derive from a @c Tuple_impl containing the remaining elements * (which contains the @c Tail). */ - template + template struct _Tuple_impl<_Idx, _Head, _Tail...> : public _Tuple_impl<_Idx + 1, _Tail...>, private _Head_base<_Idx, _Head, std::is_empty<_Head>::value> @@ -372,14 +372,14 @@ namespace std /// Gives the type of the ith element of a given tuple type. - template + template struct tuple_element; /** * Recursive case for tuple_element: strip off the first element in * the tuple and retrieve the (i-1)th element of the remaining tuple. */ - template + template struct tuple_element<__i, tuple<_Head, _Tail...> > : tuple_element<__i - 1, tuple<_Tail...> > { }; @@ -400,32 +400,32 @@ namespace std template struct tuple_size > { - static const int value = sizeof...(_Elements); + static const std::size_t value = sizeof...(_Elements); }; template - const int tuple_size >::value; + const std::size_t tuple_size >::value; - template + template inline typename __add_ref<_Head>::type __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) { return __t._M_head(); } - template + template inline typename __add_c_ref<_Head>::type __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. - template + template inline typename __add_ref< typename tuple_element<__i, tuple<_Elements...> >::type >::type get(tuple<_Elements...>& __t) { return __get_helper<__i>(__t); } - template + template inline typename __add_c_ref< typename tuple_element<__i, tuple<_Elements...> >::type >::type @@ -433,28 +433,28 @@ namespace std { return __get_helper<__i>(__t); } // This class helps construct the various comparison operations on tuples - template struct __tuple_compare; - template + template struct __tuple_compare<0, __i, __j, _Tp, _Up> { static 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)); + __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u)); } static bool __less(const _Tp& __t, const _Up& __u) { return ((get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) && - __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u)); + __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u)); } }; - template + template struct __tuple_compare<0, __i, __i, _Tp, _Up> { static bool __eq(const _Tp&, const _Up&) @@ -520,12 +520,13 @@ namespace std return __result_type(std::forward<_Elements>(__args)...); } - template struct __index_holder { }; + template struct __index_holder { }; - template + template struct __index_holder_impl; - template + template struct __index_holder_impl<__i, __index_holder<_Indexes...>, _IdxHolder, _Elements...> { @@ -534,7 +535,7 @@ namespace std _Elements...>::type type; }; - template + template struct __index_holder_impl<__i, __index_holder<_Indexes...> > { typedef __index_holder<_Indexes...> type; }; @@ -542,8 +543,8 @@ namespace std struct __make_index_holder : __index_holder_impl<0, __index_holder<>, _Elements...> { }; - template + template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(const tuple<_TElements...>& __t, const __index_holder<_TIdx...>&, @@ -552,8 +553,8 @@ namespace std { return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)..., get<_UIdx>(__u)...); } - template + template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(tuple<_TElements...>&& __t, const __index_holder<_TIdx...>&, @@ -562,8 +563,8 @@ namespace std { return tuple<_TElements..., _UElements...> (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); } - template + template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(const tuple<_TElements...>& __t, const __index_holder<_TIdx...>&, @@ -572,8 +573,8 @@ namespace std { return tuple<_TElements..., _UElements...> (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); } - template + template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(tuple<_TElements...>&& __t, const __index_holder<_TIdx...>&, @@ -585,7 +586,7 @@ namespace std template inline tuple<_TElements..., _UElements...> tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) - { + { return __tuple_cat_helper(__t, typename __make_index_holder<_TElements...>::type(), __u, typename diff --git a/libstdc++-v3/include/tr1_impl/array b/libstdc++-v3/include/tr1_impl/array index 437670f3dfc..a9047438843 100644 --- a/libstdc++-v3/include/tr1_impl/array +++ b/libstdc++-v3/include/tr1_impl/array @@ -1,6 +1,6 @@ // class template array -*- C++ -*- -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -222,26 +222,51 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 class tuple_size; /// tuple_element - template +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else + template +#endif class tuple_element; template struct tuple_size > +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + { static const std::size_t value = _Nm; }; +#else { static const int value = _Nm; }; +#endif template - const int tuple_size >::value; +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + const std::size_t +#else + const int +#endif + tuple_size >::value; +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else template +#endif struct tuple_element<_Int, array<_Tp, _Nm> > { typedef _Tp type; }; +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else template +#endif inline _Tp& get(array<_Tp, _Nm>& __arr) { return __arr[_Int]; } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else template +#endif inline const _Tp& get(const array<_Tp, _Nm>& __arr) { return __arr[_Int]; } diff --git a/libstdc++-v3/include/tr1_impl/utility b/libstdc++-v3/include/tr1_impl/utility index 42040c9103c..c70ed9b63cf 100644 --- a/libstdc++-v3/include/tr1_impl/utility +++ b/libstdc++-v3/include/tr1_impl/utility @@ -1,7 +1,6 @@ - // TR1 utility -*- C++ -*- -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 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 @@ -37,16 +36,32 @@ namespace std { _GLIBCXX_BEGIN_NAMESPACE_TR1 - template class tuple_size; - template class tuple_element; + template + class tuple_size; + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else + template +#endif + class tuple_element; // Various functions which give std::pair a tuple-like interface. template struct tuple_size > +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + { static const std::size_t value = 2; }; +#else { static const int value = 2; }; +#endif template - const int tuple_size >::value; +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + const std::size_t +#else + const int +#endif + tuple_size >::value; template struct tuple_element<0, std::pair<_Tp1, _Tp2> > @@ -55,9 +70,13 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 template struct tuple_element<1, std::pair<_Tp1, _Tp2> > { typedef _Tp2 type; }; - - template struct __pair_get; +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else + template +#endif + struct __pair_get; template<> struct __pair_get<0> @@ -83,15 +102,23 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 { return __pair.second; } }; - template - inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& - get(std::pair<_Tp1, _Tp2>& __in) - { return __pair_get<_Int>::__get(__in); } - - template - inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& - get(const std::pair<_Tp1, _Tp2>& __in) - { return __pair_get<_Int>::__const_get(__in); } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else + template +#endif + inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& + get(std::pair<_Tp1, _Tp2>& __in) + { return __pair_get<_Int>::__get(__in); } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template +#else + template +#endif + inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& + get(const std::pair<_Tp1, _Tp2>& __in) + { return __pair_get<_Int>::__const_get(__in); } _GLIBCXX_END_NAMESPACE_TR1 }