Re: [Boost-bugs] [Boost C++ Libraries] #4649: token_functions.hpp (220) : fix for warning C4127 conditional expression is constant

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4649: token_functions.hpp (220) : fix for warning C4127 conditional expression is constant
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-09-15 10:40:57


#4649: token_functions.hpp (220) : fix for warning C4127 conditional expression
is constant
------------------------------------------------------------+---------------
  Reporter: Andrew Macgregor <aamacgregor@…> | Owner: jsiek
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: tokenizer
   Version: Boost 1.44.0 | Severity: Problem
Resolution: | Keywords: isspace
------------------------------------------------------------+---------------

Comment (by Andrew Macgrego <aamacgregor@…>):

 I just realised that the problem also affects ispunct too.

 Perhaps the following solution?

 Add:
 {{{
 #if !defined(BOOST_NO_CWCTYPE)

   struct is_space
   {
     template <typename char_type>
     static bool wchar_func(char_type c) { return std::iswspace(c) != 0; }

     template <typename char_type>
     static bool char_func(char_type c) { return std::isspace(c) != 0; }
   };

   struct is_punct
   {
     template <typename char_type>
     static bool wchar_func(char_type c) { return std::iswpunct(c) != 0; }

     template <typename char_type>
     static bool char_func(char_type c) { return std::ispunct(c) != 0; }
   };

   template <typename function_pair, typename traits, size_t
 char_type_size>
   struct check
   {
     typedef typename traits::char_type char_type;
     static bool value_for(char_type c) { return
 function_pair::wchar_func(c); }
   };

   template <typename function_pair, typename traits>
   struct check<function_pair, traits, 1>
   {
     typedef typename traits::char_type char_type;
     static bool value_for(char_type c) { return
 function_pair::char_func(c); }
   };
 #endif
 }}}

 And replace:

 {{{
   if (sizeof(char_type) == 1)
     return std::isspace(c) != 0;
   else
     return std::iswspace(c) != 0;
 }}}

 with

 {{{
   return check<is_space, traits, sizeof(char_type)>::value_for(c);
 }}}

 and replace

 {{{
   if (sizeof(char_type) == 1)
     return std::ispunct(c) != 0;
   else
     return std::iswpunct(c) != 0;
 }}}

 with

 {{{
   return check<is_punct, traits, sizeof(char_type)>::value_for(c);
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4649#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC