From 837a031a0e12f9185d9160c3ee8dda01626ec662 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 27 Jul 2009 18:39:32 +0000 Subject: [PATCH] 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 ........ [SVN r55206] --- include/boost/mpl/string.hpp | 58 +++++++++++++++++++----------------- test/string.cpp | 41 +++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/include/boost/mpl/string.hpp b/include/boost/mpl/string.hpp index ce7c782..22c71cb 100644 --- a/include/boost/mpl/string.hpp +++ b/include/boost/mpl/string.hpp @@ -44,6 +44,10 @@ #include #include #include +#include + +#include // for bidirectional_iterator_tag +#include namespace boost { namespace mpl { @@ -54,51 +58,51 @@ namespace boost { namespace mpl // 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)((c0xffffff)+(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 + template struct string; - template + template struct string_iterator; template @@ -117,7 +121,7 @@ namespace boost { namespace mpl + BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C,n)) #define M1(z, n, data) \ - template \ + template \ struct apply > \ : mpl::size_t<(0 BOOST_PP_REPEAT_ ## z(n, M0, ~))> \ {}; @@ -155,7 +159,7 @@ namespace boost { namespace mpl struct apply; #define M0(z,n,data) \ - template \ + template \ struct apply > \ { \ typedef mpl::string_iterator, n, 0> type; \ @@ -205,17 +209,17 @@ namespace boost { namespace mpl }; #define M0(z,n,data) \ - template \ + template \ struct apply, 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 @@ namespace boost { namespace mpl BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~) #undef M0 - template + template struct apply, Value, false> { typedef @@ -247,7 +251,7 @@ namespace boost { namespace mpl struct apply; #define M0(z,n,data) \ - template \ + template \ struct apply > \ { \ BOOST_MPL_ASSERT_MSG((C0 != 0), POP_BACK_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \ @@ -300,7 +304,7 @@ namespace boost { namespace mpl #endif #define M0(z,n,data) \ - template \ + template \ struct apply, Value, true> \ { \ typedef \ @@ -314,7 +318,7 @@ namespace boost { namespace mpl BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~) #undef M0 - template + template struct apply, Value, false> { typedef @@ -348,7 +352,7 @@ namespace boost { namespace mpl struct apply; #define M0(z,n,data) \ - template \ + template \ struct apply, true> \ { \ BOOST_MPL_ASSERT_MSG((C0 != 0), POP_FRONT_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \ @@ -360,7 +364,7 @@ namespace boost { namespace mpl BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~) #undef M0 - template + template struct apply, false> { typedef @@ -449,7 +453,7 @@ namespace boost { namespace mpl }; #define M0(z, n, data) \ - template \ + template \ struct string_iterator, n, J> \ { \ enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == J + 1) }; \ @@ -463,7 +467,7 @@ namespace boost { namespace mpl prior; \ typedef mpl::char_ type; \ }; \ - template \ + template \ struct string_iterator, n, 0> \ { \ enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == 1) }; \ @@ -485,7 +489,7 @@ namespace boost { namespace mpl BOOST_PP_REPEAT(BOOST_MPL_STRING_MAX_PARAMS, M0, ~) #undef M0 - template + template struct string { /// INTERNAL ONLY diff --git a/test/string.cpp b/test/string.cpp index f50073b..57b5979 100644 --- a/test/string.cpp +++ b/test/string.cpp @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -471,5 +472,45 @@ int main() )); } + { + 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(); }