lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master fc4057e 3/9: Genericize


From: Greg Chicares
Subject: [lmi-commits] [lmi] master fc4057e 3/9: Genericize
Date: Wed, 15 Feb 2017 20:26:59 -0500 (EST)

branch: master
commit fc4057e9c0db586ed1fbfc79f1eb832d30bdaf06
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Genericize
---
 facets.cpp | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/facets.cpp b/facets.cpp
index 51abb63..a72bb47 100644
--- a/facets.cpp
+++ b/facets.cpp
@@ -25,8 +25,8 @@
 
 #include <algorithm>                    // std::copy()
 
-// Class blank_is_not_whitespace_ctype is intended for extracting
-// std::strings from a stream without stopping at blanks. It is a
+// Class C_is_not_whitespace_ctype is intended for extracting
+// std::strings from a stream without stopping at char <C>. It is a
 // derived work based on Dietmar Kuehl's article
 //   http://groups.google.com/groups?selm=7vpld2%24jj%241%40nnrp1.deja.com
 // which bears no copyright notice, as is usual in usenet.
@@ -35,8 +35,8 @@
 //   http://groups.google.com/groups?selm=3820A76F.3952E808%40ihug.co.nz
 // that ' ' can be used as an array index even if type 'char' is
 // signed, because 2.2/3 requires it to have a positive value.
-// However, gcc has a warning for 'char' array indexes that doesn't
-// recognize this exception, so a workaround for "[' ']" is used here.
+// The template parameter is specifically unsigned to avoid compiler
+// warnings about [] with a negative index.
 //
 // GWC modified this class
 //   in 2004 (see Motivation below)
@@ -66,10 +66,11 @@
 
 namespace
 {
-    class blank_is_not_whitespace_ctype: public std::ctype<char>
+    template<unsigned char C>
+    class C_is_not_whitespace_ctype: public std::ctype<char>
     {
       public:
-        blank_is_not_whitespace_ctype()
+        C_is_not_whitespace_ctype()
             :std::ctype<char>(get_table(), false, 1)
             {}
 
@@ -78,7 +79,7 @@ namespace
             {
             static std::ctype_base::mask rc[table_size];
             std::copy(classic_table(), classic_table() + table_size, rc);
-            rc[' '] &= ~std::ctype_base::space;
+            rc[C] &= ~std::ctype_base::space;
             return rc;
             }
     };
@@ -96,6 +97,6 @@ namespace
 
 std::locale const& blank_is_not_whitespace_locale()
 {
-    return locale_with_facet<blank_is_not_whitespace_ctype>();
+    return locale_with_facet<C_is_not_whitespace_ctype<' '>>();
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]