From 37e60c8673b375d09372d5d011e5f52451a2d3f8 Mon Sep 17 00:00:00 2001 From: Arkadiy Vertleyb Date: Tue, 11 Jan 2005 02:19:36 +0000 Subject: [PATCH] int encoding/signed char/volatile support [SVN r2436] --- genreg/input.txt | 11 -- .../boost/typeof/compliant/int_encoding.hpp | 167 +++++++++------- include/boost/typeof/compliant/modifiers.hpp | 178 ++++++++---------- .../typeof/compliant/template_encoding.hpp | 4 + include/boost/typeof/std/fstream.hpp | 4 - include/boost/typeof/std/istream.hpp | 2 - include/boost/typeof/std/ostream.hpp | 1 - include/boost/typeof/std/sstream.hpp | 4 - test/main.cpp | 57 +++--- 9 files changed, 203 insertions(+), 225 deletions(-) diff --git a/genreg/input.txt b/genreg/input.txt index 9a8838a..db08138 100755 --- a/genreg/input.txt +++ b/genreg/input.txt @@ -143,9 +143,7 @@ TEMPLATE,std::basic_iostream,1,2 #ifdef BOOST_TYPEOF_COMPLIANT TYPE,std::istream -TYPE,std::wistream TYPE,std::iostream -TYPE,std::wiostream #endif//BOOST_TYPEOF_COMPLIANT ~ostream @@ -155,7 +153,6 @@ TEMPLATE,std::basic_ostream,1,2 #ifdef BOOST_TYPEOF_COMPLIANT TYPE,std::ostream -TYPE,std::wostream #endif//BOOST_TYPEOF_COMPLIANT ~sstream @@ -169,13 +166,9 @@ TEMPLATE,std::basic_stringstream,1,3 #ifdef BOOST_TYPEOF_COMPLIANT TYPE,std::stringbuf -TYPE,std::wstringbuf TYPE,std::istringstream -TYPE,std::wistringstream TYPE,std::ostringstream -TYPE,std::wostringstream TYPE,std::stringstream -TYPE,std::wstringstream #endif//BOOST_TYPEOF_COMPLIANT ~fstream @@ -188,13 +181,9 @@ TEMPLATE,std::basic_fstream,1,2 #ifdef BOOST_TYPEOF_COMPLIANT TYPE,std::filebuf -TYPE,std::wfilebuf TYPE,std::ifstream -TYPE,std::wifstream TYPE,std::ofstream -TYPE,std::wofstream TYPE,std::fstream -TYPE,std::wfstream #endif//BOOST_TYPEOF_COMPLIANT ~iterator diff --git a/include/boost/typeof/compliant/int_encoding.hpp b/include/boost/typeof/compliant/int_encoding.hpp index 264945d..bb6e4e5 100755 --- a/include/boost/typeof/compliant/int_encoding.hpp +++ b/include/boost/typeof/compliant/int_encoding.hpp @@ -9,81 +9,114 @@ #include #include -namespace boost -{ - namespace type_of +namespace boost{namespace type_of{ + + template struct get_unsigned { - template - struct split - { - static const size_t u = (size_t)n; - static const size_t value1 = (u >> 16) + 1; - static const size_t value2 = (u << 16 >> 16) + 1; - }; + typedef T type; + }; + template<> struct get_unsigned + { + typedef unsigned char type; + }; + template<> struct get_unsigned + { + typedef unsigned char type; + }; + template<> struct get_unsigned + { + typedef unsigned short type; + }; + template<> struct get_unsigned + { + typedef unsigned int type; + }; + template<> struct get_unsigned + { + typedef unsigned long type; + }; - template - struct join - { - static const T value = (T)(((u1 - 1) << 16) + (u2 - 1)); - }; + ////////////////////////// - template - struct encode_long_integral - { - typedef - typename BOOST_TYPEOF_PUSH_BACK< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t::value1> >::type - , mpl::size_t::value2> >::type - type; - }; + template + struct pack + { + static const size_t value = + (n + 1) * 2 + (Overflow ? 1 : 0); + }; - template - struct decode_long_integral - { - static const T value = join< - T, - mpl::deref::type::value, - mpl::deref::type>::type::value - >::value; + template + struct unpack + { + static const size_t value = + (m / 2) - 1; - typedef typename mpl::next::type>::type iter; - }; + static const bool overflow = + (m % 2 == 1); + }; - template - struct encode_short_integral - { - typedef - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t<(size_t)n + 1> >::type - type; - }; + //////////////////////////////// - template - struct decode_short_integral - { - static const T value = (T)(mpl::deref::type::value - 1); - typedef typename mpl::next::type iter; - }; + template= 0x3fffffff)> + struct encode_size_t : BOOST_TYPEOF_PUSH_BACK< + V, + boost::mpl::size_t::value> + > + {}; - template - struct encode_integral : mpl::if_c< - (sizeof(T) < 4), - encode_short_integral, - encode_long_integral - >::type - {}; + template + struct encode_size_t : BOOST_TYPEOF_PUSH_BACK::value> >::type, + boost::mpl::size_t + > + {}; - template - struct decode_integral : mpl::if_c< - (sizeof(T) < 4), - decode_short_integral, - decode_long_integral - >::type - {}; - } -}//namespace + template + struct encode_integral : encode_size_t< V, (typename get_unsigned::type)n > + {}; + + /////////////////////////// + + template + struct decode_size_t; + + template + struct decode_size_t + { + static const size_t value = n; + typedef Iter iter; + }; + + template + struct decode_size_t + { + static const size_t m = boost::mpl::deref::type::value; + + static const size_t value = m * 0x3ffffffe + n; + typedef typename boost::mpl::next::type iter; + }; + + template + struct decode_integral + { + static const size_t m = + boost::mpl::deref::type::value; + + static const size_t n = + unpack::value; + + static const bool overflow = + unpack::overflow; + + typedef typename boost::mpl::next::type nextpos; + + static const T value = + decode_size_t::value; + + typedef typename decode_size_t::iter iter; + }; + +}}//namespace #endif//BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/modifiers.hpp b/include/boost/typeof/compliant/modifiers.hpp index 23628fb..667bf15 100755 --- a/include/boost/typeof/compliant/modifiers.hpp +++ b/include/boost/typeof/compliant/modifiers.hpp @@ -10,109 +10,83 @@ #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() -namespace boost -{ - namespace type_of - { - namespace - { - enum - { - CONST_ID = BOOST_TYPEOF_UNIQUE_ID(), - PTR_ID, - REF_ID, - ARRAY_ID, - CONST_ARRAY_ID - }; +// modifiers - template struct encode_type_impl - { - typedef - typename encode_type< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t >::type - , T>::type - type; - }; - template struct decode_type_impl, Iter> - { - typedef decode_type d1; - typedef const typename d1::type type; - typedef typename d1::iter iter; - }; - template struct encode_type_impl - { - typedef - typename encode_type< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t >::type - , T>::type - type; - }; - template struct decode_type_impl, Iter> - { - typedef decode_type d1; - typedef typename d1::type* type; - typedef typename d1::iter iter; - }; - template struct encode_type_impl - { - typedef - typename encode_type< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t >::type - , T>::type - type; - }; - template struct decode_type_impl, Iter> - { - typedef decode_type d1; - typedef typename d1::type& type; - typedef typename d1::iter iter; - }; - template struct encode_type_impl - { - typedef - typename encode_type< - typename BOOST_TYPEOF_PUSH_BACK< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t >::type - , mpl::size_t >::type - , T>::type - type; - }; - template struct decode_type_impl, Iter> - { - enum{n = mpl::deref::type::value}; - typedef decode_type::type> d; - typedef typename d::type type[n]; - typedef typename d::iter iter; - }; - template struct encode_type_impl - { - typedef - typename encode_type< - typename BOOST_TYPEOF_PUSH_BACK< - typename BOOST_TYPEOF_PUSH_BACK< - V - , mpl::size_t >::type - , mpl::size_t >::type - , T>::type - type; - }; - template struct decode_type_impl, Iter> - { - enum{n = mpl::deref::type::value}; - typedef decode_type::type> d; - typedef typename d::type const type[n]; - typedef typename d::iter iter; - }; - } +#define BOOST_TYPEOF_modifier_support(ID, Fun)\ + template struct encode_type_impl\ + {\ + typedef\ + typename encode_type<\ + typename BOOST_TYPEOF_PUSH_BACK<\ + V\ + , mpl::size_t >::type\ + , T>::type\ + type;\ + };\ + template struct decode_type_impl, Iter>\ + {\ + typedef decode_type d1;\ + typedef Fun(typename d1::type) type;\ + typedef typename d1::iter iter;\ } -} + +#define BOOST_TYPEOF_const_fun(T) const T +#define BOOST_TYPEOF_volatile_fun(T) volatile T +#define BOOST_TYPEOF_volatile_const_fun(T) volatile const T +#define BOOST_TYPEOF_pointer_fun(T) T* +#define BOOST_TYPEOF_reference_fun(T) T& + +namespace boost{namespace type_of{namespace{ + + BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_const_fun); + BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_fun); + BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_const_fun); + BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_pointer_fun); + BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_reference_fun); + +}}} + +#undef BOOST_TYPEOF_modifier_support +#undef BOOST_TYPEOF_const_fun +#undef BOOST_TYPEOF_volatile_fun +#undef BOOST_TYPEOF_volatile_const_fun +#undef BOOST_TYPEOF_pointer_fun +#undef BOOST_TYPEOF_reference_fun + +// arrays + +#define BOOST_TYPEOF_array_support(ID, Qualifier)\ + template\ + struct encode_type_impl\ + {\ + typedef\ + typename encode_type<\ + typename BOOST_TYPEOF_PUSH_BACK<\ + typename BOOST_TYPEOF_PUSH_BACK<\ + V\ + , mpl::size_t >::type\ + , mpl::size_t >::type\ + , T>::type\ + type;\ + };\ + template\ + struct decode_type_impl, Iter>\ + {\ + enum{n = mpl::deref::type::value};\ + typedef decode_type::type> d;\ + typedef typename d::type Qualifier type[n];\ + typedef typename d::iter iter;\ + } + +namespace boost{namespace type_of{namespace{ + + BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_PP_EMPTY()); + BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), const); + BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), volatile); + BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), volatile const); + +}}} + +#undef BOOST_TYPEOF_array_support #endif//BOOST_TYPEOF_COMPLIANT_MODIFIERS_HPP_INCLUDED diff --git a/include/boost/typeof/compliant/template_encoding.hpp b/include/boost/typeof/compliant/template_encoding.hpp index 3149897..ba44817 100755 --- a/include/boost/typeof/compliant/template_encoding.hpp +++ b/include/boost/typeof/compliant/template_encoding.hpp @@ -36,11 +36,14 @@ #define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedint BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned int) #define BOOST_TYPEOF_REGISTER_TEMPLATE_unsignedlong BOOST_TYPEOF_REGISTER_TEMPLATE_integral(unsigned long) +#define BOOST_TYPEOF_REGISTER_TEMPLATE_signedchar BOOST_TYPEOF_REGISTER_TEMPLATE_integral(signed char) + ////////// #define BOOST_TYPEOF_TO_SEQ(tokens) BOOST_TYPEOF_ ## tokens ## _BOOST_TYPEOF #define BOOST_TYPEOF_unsigned (unsigned) +#define BOOST_TYPEOF_signed (signed) #define BOOST_TYPEOF_char_BOOST_TYPEOF (char)(_) #define BOOST_TYPEOF_short_BOOST_TYPEOF (short)(_) @@ -175,6 +178,7 @@ namespace boost (unsigned short) (unsigned int) (unsigned long) + (signed char) ) } } diff --git a/include/boost/typeof/std/fstream.hpp b/include/boost/typeof/std/fstream.hpp index 4271515..cfa056f 100755 --- a/include/boost/typeof/std/fstream.hpp +++ b/include/boost/typeof/std/fstream.hpp @@ -31,13 +31,9 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_fstream, 1) BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_fstream, 2) #ifdef BOOST_TYPEOF_COMPLIANT BOOST_TYPEOF_REGISTER_TYPE(std::filebuf) -BOOST_TYPEOF_REGISTER_TYPE(std::wfilebuf) BOOST_TYPEOF_REGISTER_TYPE(std::ifstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wifstream) BOOST_TYPEOF_REGISTER_TYPE(std::ofstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wofstream) BOOST_TYPEOF_REGISTER_TYPE(std::fstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wfstream) #endif//BOOST_TYPEOF_COMPLIANT #endif//BOOST_TYPEOF_STD_fstream_hpp_INCLUDED diff --git a/include/boost/typeof/std/istream.hpp b/include/boost/typeof/std/istream.hpp index 46c6d3a..431e058 100755 --- a/include/boost/typeof/std/istream.hpp +++ b/include/boost/typeof/std/istream.hpp @@ -23,9 +23,7 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_iostream, 1) BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_iostream, 2) #ifdef BOOST_TYPEOF_COMPLIANT BOOST_TYPEOF_REGISTER_TYPE(std::istream) -BOOST_TYPEOF_REGISTER_TYPE(std::wistream) BOOST_TYPEOF_REGISTER_TYPE(std::iostream) -BOOST_TYPEOF_REGISTER_TYPE(std::wiostream) #endif//BOOST_TYPEOF_COMPLIANT #endif//BOOST_TYPEOF_STD_istream_hpp_INCLUDED diff --git a/include/boost/typeof/std/ostream.hpp b/include/boost/typeof/std/ostream.hpp index 6d0b003..d8c20c7 100755 --- a/include/boost/typeof/std/ostream.hpp +++ b/include/boost/typeof/std/ostream.hpp @@ -19,7 +19,6 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_ostream, 1) BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_ostream, 2) #ifdef BOOST_TYPEOF_COMPLIANT BOOST_TYPEOF_REGISTER_TYPE(std::ostream) -BOOST_TYPEOF_REGISTER_TYPE(std::wostream) #endif//BOOST_TYPEOF_COMPLIANT #endif//BOOST_TYPEOF_STD_ostream_hpp_INCLUDED diff --git a/include/boost/typeof/std/sstream.hpp b/include/boost/typeof/std/sstream.hpp index 742edd0..4d63503 100755 --- a/include/boost/typeof/std/sstream.hpp +++ b/include/boost/typeof/std/sstream.hpp @@ -36,13 +36,9 @@ BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_stringstream, 2) BOOST_TYPEOF_REGISTER_TEMPLATE(std::basic_stringstream, 3) #ifdef BOOST_TYPEOF_COMPLIANT BOOST_TYPEOF_REGISTER_TYPE(std::stringbuf) -BOOST_TYPEOF_REGISTER_TYPE(std::wstringbuf) BOOST_TYPEOF_REGISTER_TYPE(std::istringstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wistringstream) BOOST_TYPEOF_REGISTER_TYPE(std::ostringstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wostringstream) BOOST_TYPEOF_REGISTER_TYPE(std::stringstream) -BOOST_TYPEOF_REGISTER_TYPE(std::wstringstream) #endif//BOOST_TYPEOF_COMPLIANT #endif//BOOST_TYPEOF_STD_sstream_hpp_INCLUDED diff --git a/test/main.cpp b/test/main.cpp index 4a5af36..7d1e178 100755 --- a/test/main.cpp +++ b/test/main.cpp @@ -41,40 +41,36 @@ using namespace std; using namespace boost; -#if BOOST_WORKAROUND(BOOST_MSVC,<=1300) - template -mpl::vector1 typeof_test_helper(type const&); - -template -struct typeof_test -{ - static type dummy; - enum {value = boost::is_same< - BOOST_TYPEOF_TPL(typeof_test_helper(dummy)), - mpl::vector1 - >::value - }; -}; - -template -type typeof_test::dummy; - -#else //!BOOST_WORKAROUND(BOOST_MSVC,<=1300) -template -mpl::vector1 typeof_test_helper(); +mpl::vector1 typeof_test_helper(mpl::vector1*); template struct typeof_test { enum {value = boost::is_same< - BOOST_TYPEOF_TPL(typeof_test_helper()), + BOOST_TYPEOF_TPL(typeof_test_helper(reinterpret_cast*>(0))), mpl::vector1 >::value }; }; -#endif //BOOST_WORKAROUND(BOOST_MSVC,<=1300) +#pragma message("modifiers...") + +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); +BOOST_STATIC_ASSERT(typeof_test::value); + +BOOST_STATIC_ASSERT((typeof_test*>::value)); +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +BOOST_STATIC_ASSERT((typeof_test&>::value)); +#endif +BOOST_STATIC_ASSERT((typeof_test >::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); #pragma message("started") @@ -84,7 +80,7 @@ struct x BOOST_TYPEOF_REGISTER_TYPE(x) template struct with_integrals + int i, unsigned long ul, bool b1, bool b2, signed char sc, unsigned u> struct with_integrals {}; BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals, @@ -95,12 +91,13 @@ BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals, (unsigned long) (bool) (bool) + (signed char) (unsigned) ) #pragma message("integral...") -BOOST_STATIC_ASSERT((typeof_test >::value)); -BOOST_STATIC_ASSERT((typeof_test >::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); +BOOST_STATIC_ASSERT((typeof_test >::value)); #pragma message("namespace-level function pointers...") BOOST_STATIC_ASSERT(typeof_test::value); @@ -133,14 +130,6 @@ BOOST_STATIC_ASSERT(typeof_test::value); #pragma message("data members...") BOOST_STATIC_ASSERT(typeof_test::value); -#pragma message("modifiers...") -BOOST_STATIC_ASSERT((typeof_test*>::value)); -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -BOOST_STATIC_ASSERT((typeof_test&>::value)); -#endif -BOOST_STATIC_ASSERT((typeof_test >::value)); -BOOST_STATIC_ASSERT((typeof_test >::value)); - #pragma message("Lvalue test...") void lvalue_typeof_test() {