This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Simplify tr1::array::at


Hi,

tested x86-linux, committed mainline and 4_2-branch.

Paolo.

///////////////
2006-12-28  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/array (array<>::_M_at): Remove.
	(array<>::_M_check): Add.
	(array<>::at): Use the latter.
Index: include/tr1/array
===================================================================
--- include/tr1/array	(revision 120219)
+++ include/tr1/array	(working copy)
@@ -128,11 +128,17 @@
 
       reference
       at(size_type __n)
-      { return _M_at<_Nm>(__n); }
+      { 
+	_M_check<_Nm>(__n);
+	return _M_instance[__n];
+      }
 
       const_reference
       at(size_type __n) const
-      { return _M_at<_Nm>(__n); }
+      {
+	_M_check<_Nm>(__n);
+	return _M_instance[__n];
+      }
 
       reference 
       front()
@@ -160,39 +166,18 @@
 
     private:
       template<std::size_t _Mm>
-        typename __gnu_cxx::__enable_if<_Mm, reference>::__type
-        _M_at(size_type __n)
+        typename __gnu_cxx::__enable_if<_Mm, void>::__type
+        _M_check(size_type __n) const
         {
 	  if (__builtin_expect(__n >= _Mm, false))
-	    std::__throw_out_of_range(__N("array::_M_at"));
-	  return _M_instance[__n];
+	    std::__throw_out_of_range(__N("array::_M_check"));
 	}
 
       // Avoid "unsigned comparison with zero" warnings.
       template<std::size_t _Mm>
-        typename __gnu_cxx::__enable_if<!_Mm, reference>::__type
-        _M_at(size_type)
-        {
-	  std::__throw_out_of_range(__N("array::_M_at"));
-	  return _M_instance[0];
-	}
-
-      template<std::size_t _Mm>
-        typename __gnu_cxx::__enable_if<_Mm, const_reference>::__type
-        _M_at(size_type __n) const
-        {
-	  if (__builtin_expect(__n >= _Mm, false))
-	    std::__throw_out_of_range(__N("array::_M_at"));
-	  return _M_instance[__n];
-	}
-
-      template<std::size_t _Mm>
-        typename __gnu_cxx::__enable_if<!_Mm, const_reference>::__type
-        _M_at(size_type) const
-        {
-	  std::__throw_out_of_range(__N("array::_M_at"));
-	  return _M_instance[0];
-	}     
+        typename __gnu_cxx::__enable_if<!_Mm, void>::__type
+        _M_check(size_type) const
+        { std::__throw_out_of_range(__N("array::_M_check")); }
     };
 
   // Array comparisons.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]