int encoding/signed char/volatile support

[SVN r2436]
This commit is contained in:
Arkadiy Vertleyb
2005-01-11 02:19:36 +00:00
parent e78ee98737
commit 37e60c8673
9 changed files with 203 additions and 225 deletions

View File

@ -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

View File

@ -9,81 +9,114 @@
#include <boost/mpl/vector.hpp>
#include <boost/mpl/size_t.hpp>
namespace boost
{
namespace type_of
namespace boost{namespace type_of{
template<class T> struct get_unsigned
{
template<class T, T n>
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<signed char>
{
typedef unsigned char type;
};
template<> struct get_unsigned<char>
{
typedef unsigned char type;
};
template<> struct get_unsigned<short>
{
typedef unsigned short type;
};
template<> struct get_unsigned<int>
{
typedef unsigned int type;
};
template<> struct get_unsigned<long>
{
typedef unsigned long type;
};
template<class T, size_t u1, size_t u2>
struct join
{
static const T value = (T)(((u1 - 1) << 16) + (u2 - 1));
};
//////////////////////////
template<class V, class T, T n>
struct encode_long_integral
{
typedef
typename BOOST_TYPEOF_PUSH_BACK<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<split<T, n>::value1> >::type
, mpl::size_t<split<T, n>::value2> >::type
type;
};
template<size_t n, bool Overflow>
struct pack
{
static const size_t value =
(n + 1) * 2 + (Overflow ? 1 : 0);
};
template<class T, class Iter>
struct decode_long_integral
{
static const T value = join<
T,
mpl::deref<Iter>::type::value,
mpl::deref<typename mpl::next<Iter>::type>::type::value
>::value;
template<size_t m>
struct unpack
{
static const size_t value =
(m / 2) - 1;
typedef typename mpl::next<typename mpl::next<Iter>::type>::type iter;
};
static const bool overflow =
(m % 2 == 1);
};
template<class V, class T, T n>
struct encode_short_integral
{
typedef
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<(size_t)n + 1> >::type
type;
};
////////////////////////////////
template<class T, class Iter>
struct decode_short_integral
{
static const T value = (T)(mpl::deref<Iter>::type::value - 1);
typedef typename mpl::next<Iter>::type iter;
};
template<class V, size_t n, bool overflow = (n >= 0x3fffffff)>
struct encode_size_t : BOOST_TYPEOF_PUSH_BACK<
V,
boost::mpl::size_t<pack<n, false>::value>
>
{};
template<class V, class T, T n>
struct encode_integral : mpl::if_c<
(sizeof(T) < 4),
encode_short_integral<V, T, n>,
encode_long_integral<V, T, n>
>::type
{};
template<class V, size_t n>
struct encode_size_t<V, n, true> : BOOST_TYPEOF_PUSH_BACK<typename BOOST_TYPEOF_PUSH_BACK<
V,
boost::mpl::size_t<pack<n % 0x3ffffffe, true>::value> >::type,
boost::mpl::size_t<n / 0x3ffffffe>
>
{};
template<class T, class Iter>
struct decode_integral : mpl::if_c<
(sizeof(T) < 4),
decode_short_integral<T, Iter>,
decode_long_integral<T, Iter>
>::type
{};
}
}//namespace
template<class V, class T, T n>
struct encode_integral : encode_size_t< V, (typename get_unsigned<T>::type)n >
{};
///////////////////////////
template<size_t n, class Iter, bool overflow>
struct decode_size_t;
template<size_t n, class Iter>
struct decode_size_t<n, Iter, false>
{
static const size_t value = n;
typedef Iter iter;
};
template<size_t n, class Iter>
struct decode_size_t<n, Iter, true>
{
static const size_t m = boost::mpl::deref<Iter>::type::value;
static const size_t value = m * 0x3ffffffe + n;
typedef typename boost::mpl::next<Iter>::type iter;
};
template<class T, class Iter>
struct decode_integral
{
static const size_t m =
boost::mpl::deref<Iter>::type::value;
static const size_t n =
unpack<m>::value;
static const bool overflow =
unpack<m>::overflow;
typedef typename boost::mpl::next<Iter>::type nextpos;
static const T value =
decode_size_t<n, nextpos, overflow>::value;
typedef typename decode_size_t<n, nextpos, overflow>::iter iter;
};
}}//namespace
#endif//BOOST_TYPEOF_INT_ENCODING_HPP_INCLUDED

View File

@ -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<class V, class T> struct encode_type_impl<V, const T>
{
typedef
typename encode_type<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<CONST_ID> >::type
, T>::type
type;
};
template<class Iter> struct decode_type_impl<mpl::size_t<CONST_ID>, Iter>
{
typedef decode_type<Iter> d1;
typedef const typename d1::type type;
typedef typename d1::iter iter;
};
template<class V, class T> struct encode_type_impl<V, T*>
{
typedef
typename encode_type<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<PTR_ID> >::type
, T>::type
type;
};
template<class Iter> struct decode_type_impl<mpl::size_t<PTR_ID>, Iter>
{
typedef decode_type<Iter> d1;
typedef typename d1::type* type;
typedef typename d1::iter iter;
};
template<class V, class T> struct encode_type_impl<V, T&>
{
typedef
typename encode_type<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<REF_ID> >::type
, T>::type
type;
};
template<class Iter> struct decode_type_impl<mpl::size_t<REF_ID>, Iter>
{
typedef decode_type<Iter> d1;
typedef typename d1::type& type;
typedef typename d1::iter iter;
};
template<class V, class T, int N> struct encode_type_impl<V, T[N]>
{
typedef
typename encode_type<
typename BOOST_TYPEOF_PUSH_BACK<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<ARRAY_ID> >::type
, mpl::size_t<N> >::type
, T>::type
type;
};
template<class Iter> struct decode_type_impl<mpl::size_t<ARRAY_ID>, Iter>
{
enum{n = mpl::deref<Iter>::type::value};
typedef decode_type<typename mpl::next<Iter>::type> d;
typedef typename d::type type[n];
typedef typename d::iter iter;
};
template<class V, class T, int N> struct encode_type_impl<V, const T[N]>
{
typedef
typename encode_type<
typename BOOST_TYPEOF_PUSH_BACK<
typename BOOST_TYPEOF_PUSH_BACK<
V
, mpl::size_t<CONST_ARRAY_ID> >::type
, mpl::size_t<N> >::type
, T>::type
type;
};
template<class Iter> struct decode_type_impl<mpl::size_t<CONST_ARRAY_ID>, Iter>
{
enum{n = mpl::deref<Iter>::type::value};
typedef decode_type<typename mpl::next<Iter>::type> d;
typedef typename d::type const type[n];
typedef typename d::iter iter;
};
}
#define BOOST_TYPEOF_modifier_support(ID, Fun)\
template<class V, class T> struct encode_type_impl<V, Fun(T)>\
{\
typedef\
typename encode_type<\
typename BOOST_TYPEOF_PUSH_BACK<\
V\
, mpl::size_t<ID> >::type\
, T>::type\
type;\
};\
template<class Iter> struct decode_type_impl<mpl::size_t<ID>, Iter>\
{\
typedef decode_type<Iter> 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<class V, class T, int N>\
struct encode_type_impl<V, Qualifier T[N]>\
{\
typedef\
typename encode_type<\
typename BOOST_TYPEOF_PUSH_BACK<\
typename BOOST_TYPEOF_PUSH_BACK<\
V\
, mpl::size_t<ID> >::type\
, mpl::size_t<N> >::type\
, T>::type\
type;\
};\
template<class Iter>\
struct decode_type_impl<mpl::size_t<ID>, Iter>\
{\
enum{n = mpl::deref<Iter>::type::value};\
typedef decode_type<typename mpl::next<Iter>::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

View File

@ -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)
)
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -41,40 +41,36 @@
using namespace std;
using namespace boost;
#if BOOST_WORKAROUND(BOOST_MSVC,<=1300)
template<class T>
mpl::vector1<T> typeof_test_helper(type<T> const&);
template<class T>
struct typeof_test
{
static type<T> dummy;
enum {value = boost::is_same<
BOOST_TYPEOF_TPL(typeof_test_helper(dummy)),
mpl::vector1<T>
>::value
};
};
template<class T>
type<T> typeof_test<T>::dummy;
#else //!BOOST_WORKAROUND(BOOST_MSVC,<=1300)
template<class T>
mpl::vector1<T> typeof_test_helper();
mpl::vector1<T> typeof_test_helper(mpl::vector1<T>*);
template<class T>
struct typeof_test
{
enum {value = boost::is_same<
BOOST_TYPEOF_TPL(typeof_test_helper<T>()),
BOOST_TYPEOF_TPL(typeof_test_helper(reinterpret_cast<mpl::vector1<T>*>(0))),
mpl::vector1<T>
>::value
};
};
#endif //BOOST_WORKAROUND(BOOST_MSVC,<=1300)
#pragma message("modifiers...")
BOOST_STATIC_ASSERT(typeof_test<int*>::value);
BOOST_STATIC_ASSERT(typeof_test<int&>::value);
BOOST_STATIC_ASSERT(typeof_test<int[20]>::value);
BOOST_STATIC_ASSERT(typeof_test<const int>::value);
BOOST_STATIC_ASSERT(typeof_test<volatile int>::value);
BOOST_STATIC_ASSERT(typeof_test<volatile const int>::value);
BOOST_STATIC_ASSERT(typeof_test<volatile int[20]>::value);
BOOST_STATIC_ASSERT(typeof_test<volatile const int[20]>::value);
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector3<const int* const, const int[20], const int&>*>::value));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector2<const int* const, const int&>&>::value));
#endif
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<int[5]> >::value));
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<const int[5]> >::value));
#pragma message("started")
@ -84,7 +80,7 @@ struct x
BOOST_TYPEOF_REGISTER_TYPE(x)
template<class T, char c, unsigned short us,
int i, unsigned long ul, bool b1, bool b2, unsigned u> 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<with_integrals<int, 5, 4, 3, 2, true, false, 5> >::value));
BOOST_STATIC_ASSERT((typeof_test<with_integrals<int, 1, 1, 0, ULONG_MAX, false, true, 0> >::value));
BOOST_STATIC_ASSERT((typeof_test<with_integrals<int, 5, 4, -3, 2, true, false, -1, 5> >::value));
BOOST_STATIC_ASSERT((typeof_test<with_integrals<int, 1, 1, 0, ULONG_MAX, false, true, -1, 0> >::value));
#pragma message("namespace-level function pointers...")
BOOST_STATIC_ASSERT(typeof_test<double(*)()>::value);
@ -133,14 +130,6 @@ BOOST_STATIC_ASSERT(typeof_test<double(x::*)()volatile const>::value);
#pragma message("data members...")
BOOST_STATIC_ASSERT(typeof_test<double x::*>::value);
#pragma message("modifiers...")
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector3<const int* const, const int[20], const int&>*>::value));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector2<const int* const, const int&>&>::value));
#endif
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<int[5]> >::value));
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<const int[5]> >::value));
#pragma message("Lvalue test...")
void lvalue_typeof_test()
{