diff --git a/include/boost/typeof/config.hpp b/include/boost/typeof/config.hpp index 1957751..9f3e57c 100755 --- a/include/boost/typeof/config.hpp +++ b/include/boost/typeof/config.hpp @@ -6,6 +6,7 @@ #define BOOST_TYPEOF_CONFIG_HPP_INCLUDED #include +#include #if !defined(BOOST_TYPEOF_COMPLIANT) &&\ !defined(BOOST_TYPEOF_NATIVE) @@ -27,4 +28,8 @@ #endif +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +# define BOOST_TYPEOF_NO_SIMPLE_TYPE_OPTIMIZATION +#endif + #endif//BOOST_TYPEOF_CONFIG_HPP_INCLUDED diff --git a/include/boost/typeof/typeof_impl.hpp b/include/boost/typeof/typeof_impl.hpp index 9f880e0..a4d9ac5 100644 --- a/include/boost/typeof/typeof_impl.hpp +++ b/include/boost/typeof/typeof_impl.hpp @@ -9,12 +9,13 @@ #include #include +#include +#include +#include +#include + #ifdef BOOST_TYPEOF_USE_MPL_VECTOR # include -# include -# include -# include -# include # include # define BOOST_TYPEOF_VECTOR(n) BOOST_PP_CAT(boost::mpl::vector, n) #else @@ -25,9 +26,21 @@ namespace boost{namespace type_of{ template - char(&at(const T&))[ - mpl::at, T>::type, mpl::int_ >::type::value + struct at_result + { + typedef typename encode_type, T>::type encoded_type; + typedef typename mpl::size::type size; + + typedef char(&type)[ + mpl::at< + encoded_type, + mpl::int_<(pos < size::value) ? pos : 0> + >::type::value ]; + }; + + template + typename at_result::type at(const T&); template char(&size(const T&))[ @@ -38,8 +51,13 @@ namespace boost{namespace type_of{ #define BOOST_TYPEOF_AT(n, expr) sizeof(boost::type_of::at(expr)) #define BOOST_TYPEOF_SIZE(expr) sizeof(boost::type_of::size(expr)) -#define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ +#ifndef BOOST_TYPEOF_NO_SIMPLE_TYPE_OPTIMIZATION +# define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ boost::mpl::size_t +#else +# define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ + boost::mpl::size_t +#endif #define BOOST_TYPEOF(Expr) \ boost::type_of::decode_type< \ diff --git a/test/compliant/test_compliant.cpp b/test/compliant/test_compliant.cpp index 5f6a65f..37776c2 100755 --- a/test/compliant/test_compliant.cpp +++ b/test/compliant/test_compliant.cpp @@ -96,4 +96,20 @@ namespace negate_test } } +#define BOOST_TYPEOF_TEXT "adder..." +#include + +namespace test_adder +{ + template T make(); + + template + struct adder + { + typedef BOOST_TYPEOF_TPL(make() + make()) type; + }; + + typedef adder::type type; +}; + #endif//!(BOOST_WORKAROUND(BOOST_MSVC, <= 1300))