diff --git a/include/boost/typeof/config.hpp b/include/boost/typeof/config.hpp index 12aab24..fa32545 100755 --- a/include/boost/typeof/config.hpp +++ b/include/boost/typeof/config.hpp @@ -7,21 +7,28 @@ #include -#if !defined(BOOST_TYPEOF_COMPLIANT) && !defined(BOOST_TYPEOF_VINTAGE) && !defined(BOOST_TYPEOF_NATIVE) +#if !defined(BOOST_TYPEOF_COMPLIANT) &&\ + !defined(BOOST_TYPEOF_VINTAGE) &&\ + !defined(BOOST_TYPEOF_NATIVE) &&\ + !defined(BOOST_TYPEOF_MSVC) -# if defined __GNUC__ -# define BOOST_TYPEOF_NATIVE +# if defined __GNUC__ +# define BOOST_TYPEOF_NATIVE -# elif defined __MWERKS__ -# define BOOST_TYPEOF_NATIVE +# elif defined __MWERKS__ +# define BOOST_TYPEOF_NATIVE -# elif defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -# define BOOST_TYPEOF_VINTAGE +# elif defined(BOOST_MSVC) && (BOOST_MSVC<1400) +//Doesn't require registration +# define BOOST_TYPEOF_NATIVE -# else -# define BOOST_TYPEOF_COMPLIANT +# elif defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# define BOOST_TYPEOF_VINTAGE -# endif +# else +# define BOOST_TYPEOF_COMPLIANT + +# endif #endif diff --git a/include/boost/typeof/msvc/typeof_impl.hpp b/include/boost/typeof/msvc/typeof_impl.hpp new file mode 100644 index 0000000..d92c90a --- /dev/null +++ b/include/boost/typeof/msvc/typeof_impl.hpp @@ -0,0 +1,142 @@ + +// Copyright (C) 2005 Igor Chesnokov +// Copyright (C) 2005 Peder Holt + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED +# define BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED + +# include +# include + +namespace boost +{ + namespace type_of + { + + //Compile time constant code +# if BOOST_WORKAROUND(BOOST_MSVC,>=1300) && defined(_MSC_EXTENSIONS) + template struct the_counter; + + template + struct encode_counter + { + __if_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter::count)); + } + __if_not_exists(the_counter) + { + __if_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter::count)); + } + __if_not_exists(the_counter) + { + __if_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter::count)); + } + __if_not_exists(the_counter) + { + __if_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter::count)); + } + __if_not_exists(the_counter) + { + __if_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter::count)); + } + __if_not_exists(the_counter) + { + BOOST_STATIC_CONSTANT(unsigned,count=N); + typedef the_counter type; + } + } + } + } + } + }; + +# define BOOST_TYPEOF_INDEX(T) (encode_counter::count) +# define BOOST_TYPEOF_NEXT_INDEX(next) +# else + template struct encode_counter : encode_counter {}; + template<> struct encode_counter<0> {}; + + //Need to default to a larger value than 4, as due to MSVC's ETI errors. (sizeof(int)==4) + char (*encode_index(...))[5]; + +# define BOOST_TYPEOF_INDEX(T) (sizeof(*boost::type_of::encode_index((boost::type_of::encode_counter<1005>*)0))) +# define BOOST_TYPEOF_NEXT_INDEX(next) friend char (*encode_index(encode_counter*))[next]; +# endif + + //Typeof code + +# if BOOST_WORKAROUND(BOOST_MSVC,==1300) + template + struct msvc_typeof_base + { + template + struct id2type_impl; + + typedef id2type_impl id2type; + }; + + template + struct msvc_typeof : public msvc_typeof_base + { + template<> + struct id2type_impl + { + typedef T type; + }; + }; +# else + template + class msvc_typeof_base + { + public: + class id2type; + }; + + template + class msvc_typeof : public msvc_typeof_base + { + public: + class msvc_typeof_base::id2type // This uses nice VC6-VC7 bugfeature + { + public: + typedef T type; + }; + }; +# endif + //Tie it all together + template + struct encode_type + { + //Get the next available compile time constants index + BOOST_STATIC_CONSTANT(unsigned,value=BOOST_TYPEOF_INDEX(T)); + //Instantiate the template + typedef typename msvc_typeof::id2type type; + //Set the next compile time constants index + BOOST_STATIC_CONSTANT(unsigned,next=value+1); + //Increment the compile time constant (only needed when extensions are not active + BOOST_TYPEOF_NEXT_INDEX(next); + }; + + template + char (*encode_start(T const&))[encode_type::value]; + } +} + +# define BOOST_TYPEOF(expr) \ + boost::type_of::msvc_typeof_base::id2type::type + +# define BOOST_TYPEOF_TPL(expr) typename BOOST_TYPEOF(expr) + +#endif//BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED diff --git a/include/boost/typeof/typeof.hpp b/include/boost/typeof/typeof.hpp index b00fe39..f068351 100755 --- a/include/boost/typeof/typeof.hpp +++ b/include/boost/typeof/typeof.hpp @@ -15,10 +15,15 @@ // BOOST_TYPEOF, BOOST_TYPEOF_TPL -#if defined(BOOST_TYPEOF_COMPLIANT) +#if defined(BOOST_TYPEOF_NATIVE) && defined(BOOST_MSVC) +# define BOOST_TYPEOF_TEXT "using msvc 'native' imlementation" +# include +# include + +#elif defined(BOOST_TYPEOF_COMPLIANT) # define BOOST_TYPEOF_TEXT "using compliant imlementation" # include -# include +# include #elif defined(BOOST_TYPEOF_VINTAGE) # define BOOST_TYPEOF_TEXT "using vintage imlementation" @@ -40,7 +45,7 @@ // lvalue typeof -#if defined(BOOST_TYPEOF_VINTAGE) +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) # include #else # include @@ -54,7 +59,7 @@ #elif defined(BOOST_TYPEOF_VINTAGE) # include # include -#else//BOOST_TYPEOF_NATIVE +#else//BOOST_TYPEOF_NATIVE and BOOST_TYPEOF_MSVC # define BOOST_TYPEOF_REGISTER_TYPE(x) # define BOOST_TYPEOF_REGISTER_TEMPLATE(x, params) #endif @@ -66,7 +71,6 @@ // register stuff - #include #if defined(BOOST_TYPEOF_COMPLIANT)