Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55206 - in branches/release: . boost/mpl libs/mpl/test
From: eric_at_[hidden]
Date: 2009-07-30 14:43:18


Author: eric_niebler
Date: 2009-07-27 14:39:32 EDT (Mon, 27 Jul 2009)
New Revision: 55206
URL: http://svn.boost.org/trac/boost/changeset/55206

Log:
Merged revisions 55146 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r55146 | eric_niebler | 2009-07-24 10:22:50 -0700 (Fri, 24 Jul 2009) | 1 line
  
  fix bug with signed char
........

Properties modified:
   branches/release/ (props changed)
Text files modified:
   branches/release/boost/mpl/string.hpp | 58 +++++++++++++++++++++------------------
   branches/release/libs/mpl/test/string.cpp | 41 ++++++++++++++++++++++++++++
   2 files changed, 72 insertions(+), 27 deletions(-)

Modified: branches/release/boost/mpl/string.hpp
==============================================================================
--- branches/release/boost/mpl/string.hpp (original)
+++ branches/release/boost/mpl/string.hpp 2009-07-27 14:39:32 EDT (Mon, 27 Jul 2009)
@@ -44,6 +44,10 @@
 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+#include <iterator>
+
+#include <iterator> // for bidirectional_iterator_tag
+#include <climits>
 
 namespace boost { namespace mpl
 {
@@ -54,51 +58,51 @@
     // multi-character literals should be localized to these macros.
 
     #define BOOST_MPL_MULTICHAR_LENGTH(c) \
- (std::size_t)((c>0xffffff)+(c>0xffff)+(c>0xff)+1)
+ (std::size_t)((c<CHAR_MIN) ? 4 : ((c>0xffffff)+(c>0xffff)+(c>0xff)+1))
 
     #if defined(BOOST_LITTLE_ENDIAN) && defined(__SUNPRO_CC)
 
         #define BOOST_MPL_MULTICHAR_AT(c,i) \
- (char)(0xff&(c>>(8*(std::size_t)(i))))
+ (char)(0xff&((unsigned)(c)>>(8*(std::size_t)(i))))
 
         #define BOOST_MPL_MULTICHAR_PUSH_BACK(c,i) \
- ((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(c))
+ ((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(unsigned)(c))
 
         #define BOOST_MPL_MULTICHAR_PUSH_FRONT(c,i) \
- (((c)<<8)|(unsigned char)(i))
+ (((unsigned)(c)<<8)|(unsigned char)(i))
 
         #define BOOST_MPL_MULTICHAR_POP_BACK(c) \
- (((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(c))
+ (((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(unsigned)(c))
 
         #define BOOST_MPL_MULTICHAR_POP_FRONT(c) \
- ((c)>>8)
+ ((unsigned)(c)>>8)
 
     #else
 
         #define BOOST_MPL_MULTICHAR_AT(c,i) \
- (char)(0xff&(c>>(8*(BOOST_MPL_MULTICHAR_LENGTH(c)-(std::size_t)(i)-1))))
+ (char)(0xff&((unsigned)(c)>>(8*(BOOST_MPL_MULTICHAR_LENGTH(c)-(std::size_t)(i)-1))))
 
         #define BOOST_MPL_MULTICHAR_PUSH_BACK(c,i) \
- (((c)<<8)|(unsigned char)(i))
+ (((unsigned)(c)<<8)|(unsigned char)(i))
 
         #define BOOST_MPL_MULTICHAR_PUSH_FRONT(c,i) \
- ((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(c))
+ ((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(unsigned)(c))
 
         #define BOOST_MPL_MULTICHAR_POP_BACK(c) \
- ((c)>>8)
+ ((unsigned)(c)>>8)
 
         #define BOOST_MPL_MULTICHAR_POP_FRONT(c) \
- (((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(c))
+ (((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(unsigned)(c))
 
     #endif
 
     struct string_tag;
     struct string_iterator_tag;
 
- template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_STRING_MAX_PARAMS, unsigned C, 0)>
+ template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_STRING_MAX_PARAMS, int C, 0)>
     struct string;
 
- template<typename Sequence, unsigned I, unsigned J>
+ template<typename Sequence, int I, int J>
     struct string_iterator;
 
     template<typename Sequence>
@@ -117,7 +121,7 @@
         + BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C,n))
 
         #define M1(z, n, data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C)> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
           : mpl::size_t<(0 BOOST_PP_REPEAT_ ## z(n, M0, ~))> \
         {};
@@ -155,7 +159,7 @@
         struct apply;
 
         #define M0(z,n,data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C)> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
         { \
             typedef mpl::string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, n, 0> type; \
@@ -205,17 +209,17 @@
         };
 
         #define M0(z,n,data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C), typename Value> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C), typename Value> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, false> \
         { \
             typedef \
                 mpl::string< \
                     BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), C) \
                     BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
- (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
+ ((unsigned)BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
                     ?BOOST_PP_CAT(C,BOOST_PP_DEC(n)) \
                     :BOOST_MPL_MULTICHAR_PUSH_BACK(BOOST_PP_CAT(C,BOOST_PP_DEC(n)), Value::value) \
- , (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
+ , ((unsigned)BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
                     ?(char)Value::value \
                     :0 \
> \
@@ -225,7 +229,7 @@
         BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
         #undef M0
 
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), typename Value>
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C), typename Value>
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
         {
             typedef
@@ -247,7 +251,7 @@
         struct apply;
 
         #define M0(z,n,data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C)> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
         { \
             BOOST_MPL_ASSERT_MSG((C0 != 0), POP_BACK_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \
@@ -300,7 +304,7 @@
         #endif
 
         #define M0(z,n,data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C), typename Value> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C), typename Value> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, true> \
         { \
             typedef \
@@ -314,7 +318,7 @@
         BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
         #undef M0
 
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), typename Value>
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C), typename Value>
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
         {
             typedef
@@ -348,7 +352,7 @@
         struct apply;
 
         #define M0(z,n,data) \
- template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, int C)> \
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, true> \
         { \
             BOOST_MPL_ASSERT_MSG((C0 != 0), POP_FRONT_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \
@@ -360,7 +364,7 @@
         BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
         #undef M0
 
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)>
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C)>
         struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, false>
         {
             typedef
@@ -449,7 +453,7 @@
     };
 
     #define M0(z, n, data) \
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), unsigned J> \
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C), int J> \
     struct string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, n, J> \
     { \
         enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == J + 1) }; \
@@ -463,7 +467,7 @@
         prior; \
         typedef mpl::char_<BOOST_MPL_MULTICHAR_AT(BOOST_PP_CAT(C, n), J)> type; \
     }; \
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)> \
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C)> \
     struct string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, n, 0> \
     { \
         enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == 1) }; \
@@ -485,7 +489,7 @@
     BOOST_PP_REPEAT(BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
     #undef M0
 
- template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)>
+ template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, int C)>
     struct string
     {
         /// INTERNAL ONLY

Modified: branches/release/libs/mpl/test/string.cpp
==============================================================================
--- branches/release/libs/mpl/test/string.cpp (original)
+++ branches/release/libs/mpl/test/string.cpp 2009-07-27 14:39:32 EDT (Mon, 27 Jul 2009)
@@ -17,6 +17,7 @@
 
 #include <boost/mpl/string.hpp>
 
+#include <boost/mpl/at.hpp>
 #include <boost/mpl/back.hpp>
 #include <boost/mpl/empty.hpp>
 #include <boost/mpl/front.hpp>
@@ -471,5 +472,45 @@
         ));
     }
 
+ {
+ BOOST_TEST((
+ mpl::at_c<
+ mpl::string<'\x7f'>
+ , 0
+ >::type::value == (char)0x7f
+ ));
+
+ BOOST_TEST((
+ mpl::at_c<
+ mpl::string<'\x80'>
+ , 0
+ >::type::value == (char)0x80
+ ));
+
+ BOOST_TEST((
+ mpl::at_c<
+ mpl::string<
+ mpl::at_c<
+ mpl::string<'\x7f'>
+ , 0
+ >::type::value
+ >
+ , 0
+ >::type::value == (char)0x7f
+ ));
+
+ BOOST_TEST((
+ mpl::at_c<
+ mpl::string<
+ mpl::at_c<
+ mpl::string<'\x80'>
+ , 0
+ >::type::value
+ >
+ , 0
+ >::type::value == (char)0x80
+ ));
+ }
+
     return boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk