This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Prefer plain operator== to traits::eq in num_get


Hi,

Nathan suggested this work during the recent exchange with Martin.
Indeed, I'm convinced that this is the way to go.

Besides, as a matter of fact:
1- We are already (inconsistently) using operator== in money_get.
2- In the standard, 22.2.2.1.2, p8, the comparisons are explicitly
  carried out via operator==, *not* traits::eq.

Thus, the below. The only, very minor IMO, catch, is that operator== has
to be added to 'pod_char' and 'character' in the testsuite, otherwise,
some instantiations fail: the equalitycomparable requirement seems natural
and a third (*) char-like class dseigned by Gaby already has operator==.

Tested x86-linux, please speak soon, in case! ;)

Paolo.

///////////////

(*) Yes, ASAP, I'd like to clean up a bit the tangle of char-like
classes we have in the testsuite ;)
2004-03-05  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get<>::_M_extract_float,
	num_get<>::_M_extract_int, num_get<>::do_get(bool&),
	__pad<>::_S_pad): Prefer plain operator== to traits::eq().
	* testsuite/testsuite_character.h (struct __gnu_test::character):
	Provide operator==.
	* testsuite/testsuite_hooks.h (struct __gnu_test::pod_char):
	Likewise.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2004-03-03 21:38:21.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2004-03-05 19:52:27.000000000 +0100
@@ -182,11 +182,10 @@
       if (__beg != __end)
 	{
 	  const char_type __c = *__beg;
-	  const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
-	  if ((__plus || __traits_type::eq(__c, __lit[_S_iminus]))
-	      && (!__lc->_M_use_grouping
-		  || !__traits_type::eq(__c, __lc->_M_thousands_sep))
-	      && !__traits_type::eq(__c, __lc->_M_decimal_point))
+	  const bool __plus = __c == __lit[_S_iplus];
+	  if ((__plus || __c == __lit[_S_iminus])
+	      && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
+	      && !(__c == __lc->_M_decimal_point))
 	    {
 	      __xtrc += __plus ? '+' : '-';
 	      ++__beg;
@@ -197,11 +196,10 @@
       while (__beg != __end)
 	{
 	  const char_type __c = *__beg;
-	  if (__lc->_M_use_grouping
-	      && __traits_type::eq(__c, __lc->_M_thousands_sep)
-	      || __traits_type::eq(__c, __lc->_M_decimal_point))
+	  if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
+	      || __c == __lc->_M_decimal_point)
 	    break;
-	  else if (__traits_type::eq(__c, __lit[_S_izero]))
+	  else if (__c == __lit[_S_izero])
 	    {
 	      if (!__found_mantissa)
 		{
@@ -228,8 +226,7 @@
 	  // According to 22.2.2.1.2, p8-9, first look for thousands_sep
 	  // and decimal_point.
 	  const char_type __c = *__beg;
-          if (__lc->_M_use_grouping
-	      && __traits_type::eq(__c, __lc->_M_thousands_sep))
+          if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 	    {
 	      if (!__found_dec && !__found_sci)
 		{
@@ -250,7 +247,7 @@
 	      else
 		break;
             }
-	  else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+	  else if (__c == __lc->_M_decimal_point)
 	    {
 	      if (!__found_dec && !__found_sci)
 		{
@@ -273,8 +270,7 @@
 	      ++__sep_pos;
 	      ++__beg;
 	    }
-	  else if ((__traits_type::eq(__c, __lit[_S_ie])
-		    || __traits_type::eq(__c, __lit[_S_iE]))
+	  else if ((__c == __lit[_S_ie] || __c == __lit[_S_iE])
 		   && __found_mantissa && !__found_sci)
 	    {
 	      // Scientific notation.
@@ -286,12 +282,11 @@
 	      // Remove optional plus or minus sign, if they exist.
 	      if (++__beg != __end)
 		{
-		  const bool __plus = __traits_type::eq(*__beg,
-							__lit[_S_iplus]);
-		  if ((__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
-		      && (!__lc->_M_use_grouping
-			  || !__traits_type::eq(*__beg, __lc->_M_thousands_sep))
-		      && !__traits_type::eq(*__beg, __lc->_M_decimal_point))
+		  const bool __plus = *__beg == __lit[_S_iplus];
+		  if ((__plus || *__beg == __lit[_S_iminus])
+		      && !(__lc->_M_use_grouping
+			   && *__beg == __lc->_M_thousands_sep)
+		      && !(*__beg == __lc->_M_decimal_point))
 		    {
 		      __xtrc += __plus ? '+' : '-';
 		      ++__beg;
@@ -351,11 +346,10 @@
 	  {
 	    const char_type __c = *__beg;
 	    if (numeric_limits<_ValueT>::is_signed)
-	      __negative = __traits_type::eq(__c, __lit[_S_iminus]);
-	    if ((__negative || __traits_type::eq(__c, __lit[_S_iplus]))
-		&& (!__lc->_M_use_grouping
-		    || !__traits_type::eq(__c, __lc->_M_thousands_sep))
-		&& !__traits_type::eq(__c, __lc->_M_decimal_point))
+	      __negative = __c == __lit[_S_iminus];
+	    if ((__negative || __c == __lit[_S_iplus])
+		&& !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
+		&& !(__c == __lc->_M_decimal_point))
 	      ++__beg;
 	  }
 
@@ -364,20 +358,17 @@
 	while (__beg != __end)
 	  {
 	    const char_type __c = *__beg;
-	    if (__lc->_M_use_grouping
-		&& __traits_type::eq(__c, __lc->_M_thousands_sep)
-		|| __traits_type::eq(__c, __lc->_M_decimal_point))
+	    if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep
+		|| __c == __lc->_M_decimal_point)
 	      break;
-	    else if (__traits_type::eq(__c, __lit[_S_izero])
-		     && (!__found_num || __base == 10))
+	    else if (__c == __lit[_S_izero] && (!__found_num || __base == 10))
 	      {
 		__found_num = true;
 		++__beg;
 	      }
 	    else if (__found_num)
 	      {
-		if (__traits_type::eq(__c, __lit[_S_ix])
-		    || __traits_type::eq(__c, __lit[_S_iX]))
+		if (__c == __lit[_S_ix] || __c == __lit[_S_iX])
 		  {
 		    if (__basefield == 0)
 		      __base = 16;
@@ -416,8 +407,7 @@
 		// According to 22.2.2.1.2, p8-9, first look for thousands_sep
 		// and decimal_point.
 		const char_type __c = *__beg;
-		if (__lc->_M_use_grouping
-		    && __traits_type::eq(__c, __lc->_M_thousands_sep))
+		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 		  {
 		    // NB: Thousands separator at the beginning of a string
 		    // is a no-no, as is two consecutive thousands separators.
@@ -432,7 +422,7 @@
 			break;
 		      }
 		  }
-		else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+		else if (__c == __lc->_M_decimal_point)
 		  break;
 		else if (__q = __traits_type::find(__lit_zero, __len, __c))
 		  {
@@ -462,8 +452,7 @@
 	    for (; __beg != __end; ++__beg)
 	      {
 		const char_type __c = *__beg;
-		if (__lc->_M_use_grouping
-		    && __traits_type::eq(__c, __lc->_M_thousands_sep))
+		if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep)
 		  {
 		    if (__sep_pos)
 		      {
@@ -476,7 +465,7 @@
 			break;
 		      }
 		  }
-		else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+		else if (__c == __lc->_M_decimal_point)
 		  break;
 		else if (__q = __traits_type::find(__lit_zero, __len, __c))
 		  {
@@ -560,13 +549,13 @@
             {
 	      if (__testf)
 		if (__n < __lc->_M_falsename_size)
-		  __testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
+		  __testf = *__beg == __lc->_M_falsename[__n];
 		else
 		  break;
 
 	      if (__testt)
 		if (__n < __lc->_M_truename_size)
-		  __testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
+		  __testt = *__beg == __lc->_M_truename[__n];
 		else
 		  break;
 
@@ -2330,13 +2319,12 @@
           const locale& __loc = __io._M_getloc();
 	  const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
 
-	  const bool __testsign = _Traits::eq(__ctype.widen('-'), __olds[0])
-	                          || _Traits::eq(__ctype.widen('+'), __olds[0]);
-	  const bool __testhex = (_Traits::eq(__ctype.widen('0'), __olds[0])
+	  const bool __testsign = (__ctype.widen('-') == __olds[0]
+				   || __ctype.widen('+') == __olds[0]);
+	  const bool __testhex = (__ctype.widen('0') == __olds[0]
 				  && __oldlen > 1
-				  && (_Traits::eq(__ctype.widen('x'), __olds[1])
-				      || _Traits::eq(__ctype.widen('X'),
-						     __olds[1])));
+				  && (__ctype.widen('x') == __olds[1]
+				      || __ctype.widen('X') == __olds[1]));
 	  if (__testhex)
 	    {
 	      __news[0] = __olds[0];
diff -urN libstdc++-v3-orig/testsuite/testsuite_character.h libstdc++-v3/testsuite/testsuite_character.h
--- libstdc++-v3-orig/testsuite/testsuite_character.h	2003-11-04 06:27:37.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_character.h	2004-03-05 19:42:42.000000000 +0100
@@ -51,6 +51,10 @@
     }
   };
 
+  inline bool
+  operator==(const character& lhs, const character& rhs)
+  { return lhs.val == rhs.val; }
+
   // State type.
   struct conversion_state
   {
diff -urN libstdc++-v3-orig/testsuite/testsuite_hooks.h libstdc++-v3/testsuite/testsuite_hooks.h
--- libstdc++-v3-orig/testsuite/testsuite_hooks.h	2004-01-12 09:11:03.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_hooks.h	2004-03-05 19:44:47.000000000 +0100
@@ -152,6 +152,10 @@
   {
     unsigned char c;
   };
+
+  inline bool
+  operator==(const pod_char& lhs, const pod_char& rhs)
+  { return lhs.c == rhs.c; }
   
   struct pod_int
   {

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