From cdc03862c9e9062beae08886255d590c142a2f0b Mon Sep 17 00:00:00 2001 From: Arkadiy Vertleyb Date: Wed, 8 Jun 2005 02:57:29 +0000 Subject: [PATCH] _TPL-related fixes [SVN r2613] --- include/boost/typeof/lvalue_typeof.hpp | 25 ++++++++++++++++++++++ include/boost/typeof/typeof.hpp | 15 +++++++++++-- include/boost/typeof/typeof_impl.hpp | 29 +++++++++++++++----------- test/main.cpp | 26 +++++++++++++++++++++++ test/odr.hpp | 2 +- 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/include/boost/typeof/lvalue_typeof.hpp b/include/boost/typeof/lvalue_typeof.hpp index d99031b..fa3ec4e 100644 --- a/include/boost/typeof/lvalue_typeof.hpp +++ b/include/boost/typeof/lvalue_typeof.hpp @@ -76,11 +76,36 @@ namespace boost // Since this is always a type, // just add "typename" when using in templates +#ifndef BOOST_TYPEOF_COMPLIANT + #define BOOST_LVALUE_TYPEOF(expr) \ boost::type_of::decorate_type< \ BOOST_TYPEOF(expr), \ sizeof(*boost::type_of::classify_expression(expr)) \ >::type +#else //BOOST_TYPEOF_COMPLIANT + +#include + +namespace boost { namespace type_of { + + template + struct decorate_decode_begin + { + typedef typename decorate_type< + typename decode_begin::type, + n + >::type type; + }; +}} + +#define BOOST_LVALUE_TYPEOF(expr) \ + boost::type_of::decorate_decode_begin< \ + BOOST_TYPEOF_ENCODED_VECTOR(expr), \ + sizeof(*boost::type_of::classify_expression(expr)) \ + >::type + +#endif #endif//BOOST_TYPEOF_LVALUE_TYPEOF_HPP_INCLUDED diff --git a/include/boost/typeof/typeof.hpp b/include/boost/typeof/typeof.hpp index 8255f8a..4429a6c 100755 --- a/include/boost/typeof/typeof.hpp +++ b/include/boost/typeof/typeof.hpp @@ -30,10 +30,21 @@ # define BOOST_TYPEOF_TEXT "using native imlementation" # include -# if !defined BOOST_TYPEOF -# define BOOST_TYPEOF __typeof__ +# if !defined BOOST_TYPEOF_KEYWORD +# define BOOST_TYPEOF_KEYWORD __typeof__ # endif + /* Native __typeof__ can accept either type or value. + Something like "int()" can be viewed either way, but + __typeof__ consideres it a type. We force it otherwise + to ensure consistensy with emulation */ + + namespace boost { namespace type_of { + template T& ensure_obj(const T&); + }} + +# define BOOST_TYPEOF(expr) BOOST_TYPEOF_KEYWORD(boost::type_of::ensure_obj(expr)) + # define BOOST_TYPEOF_TPL BOOST_TYPEOF #endif diff --git a/include/boost/typeof/typeof_impl.hpp b/include/boost/typeof/typeof_impl.hpp index 87cca00..873d0ed 100644 --- a/include/boost/typeof/typeof_impl.hpp +++ b/include/boost/typeof/typeof_impl.hpp @@ -34,21 +34,26 @@ namespace boost { namespace type_of { #undef BOOST_TYPEOF_sizer_item +namespace boost { namespace type_of { + + template + struct decode_begin + { + typedef typename decode_type::type type; + }; +}} + #define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ boost::mpl::size_t -#define BOOST_TYPEOF(Expr) \ - boost::type_of::decode_type< \ - BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \ - BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ - >::begin \ - >::type +#define BOOST_TYPEOF_ENCODED_VECTOR(Expr) \ + BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \ + BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ + > -#define BOOST_TYPEOF_TPL(Expr) \ - typename boost::type_of::decode_type< \ - typename BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \ - BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ - >::begin \ - >::type +#define BOOST_TYPEOF(Expr)\ + boost::type_of::decode_begin::type + +#define BOOST_TYPEOF_TPL typename BOOST_TYPEOF #endif//BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED diff --git a/test/main.cpp b/test/main.cpp index b8432cc..1ef3388 100755 --- a/test/main.cpp +++ b/test/main.cpp @@ -205,6 +205,27 @@ void lvalue_typeof_test() //BOOST_STATIC_ASSERT((boost::is_same::value)); //msvc BOOST_STATIC_ASSERT((boost::is_same::value)); } +namespace ltype +{ + int& foo(double); + char foo(int); + + template + struct result_type + { + typedef typename BOOST_LVALUE_TYPEOF(foo(T())) type; + }; + + BOOST_STATIC_ASSERT((boost::is_same< + result_type::type, + char + >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + result_type::type, + int& + >::value)); +}; #define BOOST_TYPEOF_TEXT "Noncopyable..." #include @@ -331,6 +352,11 @@ void odr_test() odr_test2(); } +#define BOOST_TYPEOF_TEXT "native/emulation consistency..." +#include + +BOOST_STATIC_ASSERT((is_same::value)); + #define BOOST_TYPEOF_TEXT "main()..." #include diff --git a/test/odr.hpp b/test/odr.hpp index ec2969f..257f139 100644 --- a/test/odr.hpp +++ b/test/odr.hpp @@ -37,7 +37,7 @@ void odr_test2(); template typename sum_t::result_type sum_t::operator()() { - // BOOST_AUTO_TPL(result, m_sum); + //BOOST_AUTO_TPL(result, m_sum); return m_sum; }